| 1 | <?php |
||
| 11 | class FinalStaticUsage implements AnalyzerPassInterface |
||
| 12 | { |
||
| 13 | use DefaultMetadataPassTrait { |
||
| 14 | DefaultMetadataPassTrait::getMetadata as defaultMetadata; |
||
| 15 | } |
||
| 16 | |||
| 17 | const DESCRIPTION = 'Checks for use of `static::` inside a final class.'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param Expr\StaticCall $expr |
||
| 21 | * @param Context $context |
||
| 22 | * @return bool |
||
| 23 | */ |
||
| 24 | 3 | public function pass(Expr\StaticCall $expr, Context $context) |
|
| 25 | { |
||
| 26 | 3 | if (!$context->scope) { |
|
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | 3 | $scopePointer = $context->scope->getPointer(); |
|
| 31 | 3 | if (!$scopePointer) { |
|
| 32 | return false; |
||
| 33 | } |
||
| 34 | |||
| 35 | 3 | $classObject = $scopePointer->getObject(); |
|
| 36 | 3 | if (!$classObject instanceof ClassDefinition || !$classObject->isFinal()) { |
|
| 37 | 2 | return false; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | if ($expr->class->getFirst() !== 'static') { |
|
|
|
|||
| 41 | return false; |
||
| 42 | } |
||
| 43 | |||
| 44 | 1 | $context->notice( |
|
| 45 | 1 | 'error.final-static-usage', |
|
| 46 | 1 | 'Don\'t use static:: in final class', |
|
| 47 | $expr |
||
| 48 | 1 | ); |
|
| 49 | |||
| 50 | 1 | return true; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | 2 | public function getRegister() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 53 | public static function getMetadata() |
|
| 73 | } |
||
| 74 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: