| 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 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * --User history types-- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * 1: Title Added | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * 2: Title Updated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * 3: Title Removed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * 4: Tags updated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * 5: Category updated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * 6: Favourite added | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 * 7: Favourite removed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 38 |  | View Code Duplication | 	public function userAddTitle(int $chapterID, string $chapter, string $category) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			'type'        => '1', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			'custom1'     => $chapter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			'custom2'     => $category, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	} | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication | 	public function userUpdateTitle(int $chapterID, string $new_chapter) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			'type'        => '2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			'custom1'     => $new_chapter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	public function userRemoveTitle(int $chapterID) : bool { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			'type'        => '3', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 74 |  | View Code Duplication | 	public function userUpdateTags(int $chapterID, string $new_tags) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			'type'        => '4', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			'custom1'     => $new_tags, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	} | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 86 |  | View Code Duplication | 	public function userUpdateCategory(int $chapterID, string $new_category) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			'type'        => '5', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			'custom1'     => $new_category, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		return $success; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 97 |  |  | 	} | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 98 |  | View Code Duplication | 	public function userAddFavourite(int $chapterID, string $chapter) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 			'type'        => '6', | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 			'custom1'     => $chapter, | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 		]); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 		return $success; | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 110 |  | View Code Duplication | 	public function userRemoveFavourite(int $chapterID, string $chapter) : bool { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$success = $this->db->insert('tracker_user_history', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			'chapter_id'  => $chapterID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			'type'        => '7', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			'custom1'     => $chapter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			'updated_at'  => date('Y-m-d H:i:s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	public function userGetHistory(int $page) : array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		$rowsPerPage = 50; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$query = $this->db | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 			->select('SQL_CALC_FOUND_ROWS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			          tt.title, tt.title_url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			          ts.site, ts.site_class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			          tuh.type, tuh.custom1, tuh.custom2, tuh.custom3, tuh.updated_at', FALSE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			->from('tracker_user_history AS tuh') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			->join('tracker_chapters AS tc', 'tuh.chapter_id = tc.id', 'left') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			->join('tracker_titles AS tt', 'tc.title_id = tt.id', 'left') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 			->join('tracker_sites AS ts', 'tt.site_id = ts.id', 'left') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 			->where('tc.user_id', $this->User->id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 			->order_by('tuh.id DESC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 			->limit($rowsPerPage, ($rowsPerPage * ($page - 1))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 			->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		$arr = ['rows' => [], 'totalCount' => 0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		if($query->num_rows() > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			foreach($query->result() as $row) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 				$arrRow = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 				$arrRow['updated_at'] = $row->updated_at; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 				$arrRow['title']      = $row->title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 				$arrRow['title_url']  = $this->Tracker->sites->{$row->site_class}->getFullTitleURL($row->title_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 				$arrRow['site'] = $row->site; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 				$arrRow['site_sprite'] = str_replace('.', '-', $row->site); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 				switch($row->type) { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 152 |  | View Code Duplication | 					case 1: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 						$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 						$arrRow['status'] = "Series added at '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>' to category '{$row->custom2}'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 157 |  | View Code Duplication | 					case 2: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 						$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 						$arrRow['status'] = "Chapter updated to '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 					case 3: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 						$arrRow['status'] = "Series removed"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 					case 4: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 						$arrRow['status'] = "Tags set to '{$row->custom1}'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 					case 5: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 						$arrRow['status'] = "Category set to '{$row->custom1}'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 174 |  | View Code Duplication | 					case 6: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 						$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 						$arrRow['status'] = "Favourited '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 179 |  | View Code Duplication | 					case 7: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 						$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 						$arrRow['status'] = "Unfavourited '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 					default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 						$arrRow['status'] = "Something went wrong!"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 						break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 				$arr['rows'][] = $arrRow; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 			$arr['totalPages'] = ceil($this->db->query('SELECT FOUND_ROWS() count;')->row()->count / $rowsPerPage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 		return $arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 194 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 195 |  |  |  | 
            
                        
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: