Conditions | 4 |
Paths | 5 |
Total Lines | 36 |
Code Lines | 24 |
Lines | 8 |
Ratio | 22.22 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
29 | public function update(\SplSubject $response) |
||
30 | { |
||
31 | if (false === $this->options['enable']) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | $request = $response->getRequest(); |
||
|
|||
36 | $route = $response->getRoute(); |
||
37 | $http_code = $response->getHttpCode(); |
||
38 | |||
39 | $data = array( |
||
40 | 'resource' => sprintf( |
||
41 | '%s %s', |
||
42 | $route->getMethod(), |
||
43 | $route->getName() |
||
44 | ), |
||
45 | 'status' => sprintf( |
||
46 | '%d %s - %s', |
||
47 | $http_code, |
||
48 | Response::getStatusPrases($http_code), |
||
49 | Response::getStatusAdjective($http_code) |
||
50 | ), |
||
51 | 'client_ip' => $request->getIp(true) |
||
52 | ); |
||
53 | |||
54 | View Code Duplication | if (null !== $this->options['extras']) { |
|
55 | $data['extras'] = $this->options['extras']; |
||
56 | } |
||
57 | |||
58 | $name = $this->options['name']; |
||
59 | View Code Duplication | if (true === $this->options['prepend']) { |
|
60 | $response->results = array($name=>$data)+$response->results; |
||
61 | } else { |
||
62 | $response->results[$name] = $data; |
||
63 | } |
||
64 | } |
||
65 | |||
67 |
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: