Conditions | 1 |
Paths | 1 |
Total Lines | 8 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
35 | public function getCurrentChapter(int $titleID) : string { |
||
36 | $query = $this->db->select('latest_chapter') |
||
37 | ->from('tracker_titles') |
||
38 | ->where('id', $titleID) |
||
39 | ->get(); |
||
40 | |||
41 | return $query->row()->latest_chapter; |
||
42 | } |
||
43 | } |
||
44 |
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 sub-classes 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 parent class: