| Conditions | 3 |
| Paths | 4 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 10 | public function updateTitleHistory(int $titleID, string $newChapter, string $newChapterTimestamp, bool $isNewTitle = FALSE) { |
||
| 11 | $oldChapter = NULL; |
||
| 12 | if(!$isNewTitle) { |
||
| 13 | $query = $this->db->select('latest_chapter') |
||
| 14 | ->from('tracker_titles') |
||
| 15 | ->where('id', $titleID) |
||
| 16 | ->get(); |
||
| 17 | |||
| 18 | $oldChapter = $query->row()->latest_chapter; |
||
| 19 | } |
||
| 20 | |||
| 21 | $success = TRUE; |
||
| 22 | if($oldChapter !== $newChapter) { |
||
| 23 | $success = $this->db->insert('tracker_titles_history', [ |
||
| 24 | 'title_id' => $titleID, |
||
| 25 | |||
| 26 | 'old_chapter' => $oldChapter, |
||
| 27 | 'new_chapter' => $newChapter, |
||
| 28 | |||
| 29 | 'updated_at' => $newChapterTimestamp |
||
| 30 | ]); |
||
| 31 | } |
||
| 32 | return (bool) $success; |
||
| 33 | } |
||
| 34 | |||
| 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: