Conditions | 5 |
Paths | 9 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
29 | public function run() |
||
30 | { |
||
31 | if (!$this->model->validate()) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | if (!is_array($this->model->items)) { |
||
36 | $this->model->items = []; |
||
37 | } |
||
38 | |||
39 | $assignedItems = $this->getAuthManager()->getItemsByUser($this->model->user_id); |
||
|
|||
40 | $assignedItemsNames = array_keys($assignedItems); |
||
41 | |||
42 | foreach (array_diff($assignedItemsNames, $this->model->items) as $item) { |
||
43 | $this->model->getAuthManager()->revoke($assignedItems[$item], $this->model->user_id); |
||
44 | } |
||
45 | |||
46 | foreach (array_diff($this->model->items, $assignedItemsNames) as $item) { |
||
47 | $this->getAuthManager()->assign($this->getAuthManager()->getItem($item), $this->model->user_id); |
||
48 | } |
||
49 | |||
50 | return $this->model->updated = true; |
||
51 | } |
||
52 | } |
||
53 |
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: