1 | <?php |
||
22 | final class FinalInterfaceSniff implements PHP_CodeSniffer_Sniff |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var PHP_CodeSniffer_File |
||
27 | */ |
||
28 | private $file; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | private $position; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 1 | public function register() |
|
43 | |||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 1 | public function process(PHP_CodeSniffer_File $file, $position) |
|
49 | { |
||
50 | 1 | $this->file = $file; |
|
51 | 1 | $this->position = $position; |
|
52 | |||
53 | 1 | if ($this->implementsInterface() === FALSE) { |
|
54 | return; |
||
55 | } |
||
56 | |||
57 | 1 | if ($this->isFinalOrAbstractClass()) { |
|
58 | 1 | return; |
|
59 | } |
||
60 | |||
61 | 1 | if ($this->isDoctrineEntity()) { |
|
62 | 1 | return; |
|
63 | } |
||
64 | |||
65 | 1 | $file->addError( |
|
66 | 1 | 'Non-abstract class that implements interface should be final.', |
|
67 | $position |
||
68 | ); |
||
69 | 1 | } |
|
70 | |||
71 | |||
72 | /** |
||
73 | * @return bool |
||
74 | */ |
||
75 | 1 | private function implementsInterface() |
|
79 | |||
80 | |||
81 | /** |
||
82 | * @return bool |
||
83 | */ |
||
84 | 1 | private function isFinalOrAbstractClass() |
|
89 | |||
90 | |||
91 | /** |
||
92 | * @return bool |
||
93 | */ |
||
94 | 1 | private function isDoctrineEntity() |
|
114 | |||
115 | } |
||
116 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.