1
|
|
|
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
2
|
|
|
|
3
|
|
|
class History_Model extends CI_Model { |
4
|
94 |
|
public function __construct() { |
5
|
94 |
|
parent::__construct(); |
|
|
|
|
6
|
|
|
|
7
|
94 |
|
$this->load->database(); |
8
|
94 |
|
} |
9
|
|
|
|
10
|
|
|
/*** TITLE HISTORY ***/ |
11
|
|
|
public function updateTitleHistory(int $titleID, $oldChapter, string $newChapter, string $newChapterTimestamp) { |
12
|
|
|
$success = TRUE; |
13
|
|
|
if($oldChapter !== $newChapter) { |
14
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
15
|
|
|
'title_id' => $titleID, |
16
|
|
|
|
17
|
|
|
'old_chapter' => $oldChapter, |
18
|
|
|
'new_chapter' => $newChapter, |
19
|
|
|
|
20
|
|
|
'updated_at' => $newChapterTimestamp |
21
|
|
|
]); |
22
|
|
|
} |
23
|
|
|
return (bool) $success; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/*** USER HISTORY ***/ |
27
|
|
View Code Duplication |
public function userAddTitle(int $chapterID, string $chapter, string $category) : bool { |
|
|
|
|
28
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
29
|
|
|
'chapter_id' => $chapterID, |
30
|
|
|
|
31
|
|
|
'type' => '1', |
32
|
|
|
'custom1' => $chapter, |
33
|
|
|
'custom2' => $category, |
34
|
|
|
|
35
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
return $success; |
39
|
|
|
} |
40
|
|
View Code Duplication |
public function userUpdateTitle(int $chapterID, string $old_chapter, string $new_chapter) : bool { |
|
|
|
|
41
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
42
|
|
|
'chapter_id' => $chapterID, |
43
|
|
|
|
44
|
|
|
'type' => '2', |
45
|
|
|
'custom1' => $old_chapter, |
46
|
|
|
'custom2' => $new_chapter, |
47
|
|
|
|
48
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
return $success; |
52
|
|
|
} |
53
|
|
|
public function userRemoveTitle(int $chapterID) : bool { |
54
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
55
|
|
|
'chapter_id' => $chapterID, |
56
|
|
|
|
57
|
|
|
'type' => '3', |
58
|
|
|
|
59
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
return $success; |
63
|
|
|
} |
64
|
|
View Code Duplication |
public function userUpdateTags(int $chapterID, string/*|null*/ $old_tags, string $new_tags) : bool { |
|
|
|
|
65
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
66
|
|
|
'chapter_id' => $chapterID, |
67
|
|
|
|
68
|
|
|
'type' => '4', |
69
|
|
|
'custom1' => $old_tags, |
70
|
|
|
'custom2' => $new_tags, |
71
|
|
|
|
72
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
return $success; |
76
|
|
|
} |
77
|
|
View Code Duplication |
public function userUpdateCategory(int $chapterID, string $old_category, string $new_category) : bool { |
|
|
|
|
78
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
79
|
|
|
'chapter_id' => $chapterID, |
80
|
|
|
|
81
|
|
|
'type' => '5', |
82
|
|
|
'custom1' => $old_category, |
83
|
|
|
'custom2' => $new_category, |
84
|
|
|
|
85
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
return $success; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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: