-
Notifications
You must be signed in to change notification settings - Fork 554
Differenciate signaturePrototype and inheritancePrototype #4945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,13 @@ | |
| return []; | ||
| } | ||
|
|
||
| [$prototype, $prototypeDeclaringClass, $checkVisibility] = $prototypeData; | ||
| [ | ||
| $prototype, | ||
| $prototypeDeclaringClass, | ||
| $checkVisibility, | ||
| $inheritancePrototype, | ||
| $inheritancePrototypeDeclaringClass, | ||
| ] = $prototypeData; | ||
|
|
||
| $messages = []; | ||
| if ( | ||
|
|
@@ -119,8 +125,8 @@ | |
| 'Method %s::%s() overrides method %s::%s() but is missing the #[\Override] attribute.', | ||
| $method->getDeclaringClass()->getDisplayName(), | ||
| $method->getName(), | ||
| $prototypeDeclaringClass->getDisplayName(true), | ||
| $prototype->getName(), | ||
| $inheritancePrototypeDeclaringClass->getDisplayName(true), | ||
| $inheritancePrototype->getName(), | ||
| )) | ||
| ->identifier('method.missingOverride') | ||
| ->fixNode($node->getOriginalNode(), static function (Node\Stmt\ClassMethod $method) { | ||
|
|
@@ -132,24 +138,24 @@ | |
| }) | ||
| ->build(); | ||
| } | ||
| if ($prototype->isFinalByKeyword()->yes()) { | ||
| if ($inheritancePrototype->isFinalByKeyword()->yes()) { | ||
|
Check warning on line 141 in src/Rules/Methods/OverridingMethodRule.php
|
||
| $messages[] = RuleErrorBuilder::message(sprintf( | ||
| 'Method %s::%s() overrides final method %s::%s().', | ||
| $method->getDeclaringClass()->getDisplayName(), | ||
| $method->getName(), | ||
| $prototypeDeclaringClass->getDisplayName(true), | ||
| $prototype->getName(), | ||
| $inheritancePrototypeDeclaringClass->getDisplayName(true), | ||
| $inheritancePrototype->getName(), | ||
| )) | ||
| ->nonIgnorable() | ||
| ->identifier('method.parentMethodFinal') | ||
| ->build(); | ||
| } elseif ($prototype->isFinal()->yes()) { | ||
| } elseif ($inheritancePrototype->isFinal()->yes()) { | ||
|
Check warning on line 152 in src/Rules/Methods/OverridingMethodRule.php
|
||
| $messages[] = RuleErrorBuilder::message(sprintf( | ||
| 'Method %s::%s() overrides @final method %s::%s().', | ||
| $method->getDeclaringClass()->getDisplayName(), | ||
| $method->getName(), | ||
| $prototypeDeclaringClass->getDisplayName(true), | ||
| $prototype->getName(), | ||
| $inheritancePrototypeDeclaringClass->getDisplayName(true), | ||
| $inheritancePrototype->getName(), | ||
| ))->identifier('method.parentMethodFinalByPhpDoc') | ||
| ->build(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug11067; | ||
|
|
||
| interface BuilderInterface | ||
| { | ||
| public function __construct(string $field); | ||
| } | ||
|
|
||
| class BaseBuilder implements BuilderInterface | ||
| { | ||
| public function __construct( | ||
| protected string $field, | ||
| bool $checkType = true, | ||
| ) { | ||
| var_dump($field, $checkType); | ||
| } | ||
| } | ||
|
|
||
| class BooleanBuilder extends BaseBuilder | ||
| { | ||
| public function __construct(string $field) | ||
| { | ||
| parent::__construct($field, false); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| class BaseBuilder2 implements BuilderInterface | ||
| { | ||
| final public function __construct( | ||
| protected string $field, | ||
| bool $checkType = true, | ||
| ) { | ||
| var_dump($field, $checkType); | ||
| } | ||
| } | ||
|
|
||
| class BooleanBuilder2 extends BaseBuilder2 | ||
| { | ||
| public function __construct(string $field) | ||
| { | ||
| parent::__construct($field, false); | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace Bug12272; | ||
|
|
||
| interface ExceptionContract | ||
| { | ||
| public function __construct(string $message); | ||
| } | ||
|
|
||
| class BaseException extends Exception implements ExceptionContract | ||
| { | ||
| public function __construct(string $message, ?Throwable $previous = null) | ||
| { | ||
| parent::__construct($message, 0, $previous); | ||
| } | ||
| } | ||
|
|
||
| class SomeException extends BaseException | ||
| { | ||
| } | ||
|
|
||
| class SpecificException extends SomeException | ||
| { | ||
| public function __construct(string $message, int $code = 0) | ||
| { | ||
| if ($code) { | ||
| echo 1; | ||
| } | ||
|
|
||
| parent::__construct($message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace Bug12830; | ||
|
|
||
| interface I | ||
| { | ||
| public function __construct(string $mustBeString); | ||
| } | ||
|
|
||
| class A implements I | ||
| { | ||
| public string $MustBeString; | ||
| public int $CanBeInt; | ||
|
|
||
| public function __construct(string $mustBeString, int $canBeInt = -1) | ||
| { | ||
| $this->MustBeString = $mustBeString; | ||
| $this->CanBeInt = $canBeInt; | ||
| } | ||
| } | ||
|
|
||
| class B extends A | ||
| { | ||
| public bool $CanBeBool; | ||
|
|
||
| public function __construct(string $mustBeString, bool $canBeBool = false) | ||
| { | ||
| $this->MustBeString = $mustBeString; | ||
| $this->CanBeBool = $canBeBool; | ||
| } | ||
| } | ||
|
|
||
| var_dump([ | ||
| new A('A', 1), | ||
| new B('B', true), | ||
| ]); |
Uh oh!
There was an error while loading. Please reload this page.