Conditions | 5 |
Paths | 7 |
Total Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
32 | public function run() |
||
33 | { |
||
34 | if (!$this->model->validate() || (!in_array($this->model->scenario, ['create', 'update'], false))) { |
||
35 | return false; |
||
36 | } |
||
37 | |||
38 | $rule = $this->make($this->model->className, [], ['name' => $this->model->name]); |
||
39 | |||
40 | try { |
||
41 | if ($this->model->scenario === 'create') { |
||
42 | $this->getAuthManager()->add($rule); |
||
43 | } else { |
||
44 | $this->getAuthManager()->update($this->model->previousName, $rule); |
||
45 | } |
||
46 | $this->getAuthManager()->invalidateCache(); |
||
|
|||
47 | } catch (Exception $e) { |
||
48 | return false; |
||
49 | } |
||
50 | |||
51 | return true; |
||
52 | } |
||
53 | } |
||
54 |
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: