| Conditions | 6 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 6.1666 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | 42 | public static function mightHaveAnnotations($entity) |
|
| 32 | { |
||
| 33 | 42 | if (is_object($entity)) |
|
| 34 | { |
||
| 35 | 42 | if ($entity instanceof Reflector) |
|
| 36 | { |
||
| 37 | 42 | if ($entity instanceof ReflectionClass) |
|
| 38 | { |
||
| 39 | 33 | $file = $entity->getFileName(); |
|
| 40 | } |
||
| 41 | else |
||
| 42 | { |
||
| 43 | 42 | $file = $entity->getDeclaringClass()->getFileName(); |
|
|
1 ignored issue
–
show
|
|||
| 44 | } |
||
| 45 | } |
||
| 46 | else |
||
| 47 | { |
||
| 48 | 42 | $file = (new ReflectionObject($entity))->getFileName(); |
|
| 49 | } |
||
| 50 | } |
||
| 51 | else |
||
| 52 | { |
||
| 53 | $file = $entity; |
||
| 54 | } |
||
| 55 | 42 | if (empty($file) || !is_string($file)) |
|
| 56 | { |
||
| 57 | return false; |
||
| 58 | // throw new \UnexpectedValueException(sprintf('Should provide file name, got: %s', gettype($file))); |
||
| 59 | } |
||
| 60 | 42 | $content = file_get_contents($file); |
|
| 61 | 42 | return preg_match('~@[A-Z]~', $content); |
|
| 62 | } |
||
| 63 | |||
| 65 |
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: