| Conditions | 2 |
| Paths | 2 |
| Total Lines | 14 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 10 | public function updateTitleHistory(int $titleID, $oldChapter, string $newChapter, string $newChapterTimestamp) { |
||
| 11 | $success = TRUE; |
||
| 12 | if($oldChapter !== $newChapter) { |
||
| 13 | $success = $this->db->insert('tracker_titles_history', [ |
||
| 14 | 'title_id' => $titleID, |
||
| 15 | |||
| 16 | 'old_chapter' => $oldChapter, |
||
| 17 | 'new_chapter' => $newChapter, |
||
| 18 | |||
| 19 | 'updated_at' => $newChapterTimestamp |
||
| 20 | ]); |
||
| 21 | } |
||
| 22 | return (bool) $success; |
||
| 23 | } |
||
| 24 | |||
| 34 |
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: