1 | <?php |
||
21 | class PhpCodeSnifferReviewNoBlade extends AbstractFileReview |
||
22 | { |
||
23 | protected $options = []; |
||
24 | |||
25 | /** |
||
26 | * Gets the value of an option. |
||
27 | * |
||
28 | * @param string $option |
||
29 | * @return string |
||
30 | */ |
||
31 | public function getOption($option) |
||
35 | |||
36 | /** |
||
37 | * Gets a string of the set options to pass to the command line. |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getOptionsForConsole() |
||
57 | |||
58 | /** |
||
59 | * Adds an option to be included when running PHP_CodeSniffer. Overwrites the values of options with the same name. |
||
60 | * |
||
61 | * @param string $option |
||
62 | * @param string $value |
||
63 | * @return PhpCodeSnifferReview |
||
64 | */ |
||
65 | public function setOption($option, $value) |
||
75 | |||
76 | /** |
||
77 | * Determins if a given file should be reviewed. |
||
78 | * |
||
79 | * @param FileInterface $file |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function canReviewFile(FileInterface $file) |
||
86 | |||
87 | /** |
||
88 | * Checks PHP files using PHP_CodeSniffer. |
||
89 | */ |
||
90 | public function review(ReporterInterface $reporter, ReviewableInterface $file) |
||
120 | } |
||
121 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: