| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Nicklas\Comment\Modules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * A database driven model. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class User extends ActiveRecordModelExtender | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * @var string $tableName name of the database table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected $tableName = "ramverk1_users"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * Columns in the table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @var integer $id primary key auto incremented. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public $email; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public $pass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public $authority = "user"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public $question; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Returns post with markdown and gravatar | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param string $sql | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @param array $param | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 1 |  |     public function getAllUsers($sql = null, $params = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |         if ($sql == null) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |             $users = $this->findAll(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |         if ($sql != null) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |             $users = $this->findAllWhere($sql, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |         $question   = new Question($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 1 |  |         $post       = new Post($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |         $comment    = new Comment($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |         return array_map(function ($user) use ($question, $post, $comment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |             $user->questions    = $question->getQuestions("user = ?", $user->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |             $user->posts        = $post->getAllPosts("user = ? AND type = ?", [$user->name, "answer"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |             $user->comments     = $comment->getComments("user = ?", $user->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |             $user->img          = $this->getGravatar($user->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |             return $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  |         }, $users); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * return question/answer, three attributes are set, comments connected to them is an array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return object | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  |     */ | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 1 |  |     public function getUser($name) | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 1 |  |         $user = $this->find("name", $name); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 1 |  |         $question   = new Question($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 1 |  |         $post       = new Post($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 | 1 |  |         $comment    = new Comment($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         // Get all the different posts user made. | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  |         $user->questions    = $question->getQuestions("user = ?", $user->name); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 1 |  |         $user->posts        = $post->getAllPosts("user = ? AND type = ?", [$user->name, "answer"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 | 1 |  |         $user->comments     = $comment->getComments("user = ?", $user->name); | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 1 |  |         $user->img          = $this->getGravatar($name); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 1 |  |         return $user; | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * Check if user exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @return boolean true if user exists in database else false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 1 |  |     public function userExists($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 1 |  |         $user = $this->find("name", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |         return !$user ? false : true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * Returns gravatar link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @param string $email | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return string as gravatar link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 5 |  |     public function setGravatar() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 5 |  |         $this->img = $this->gravatar($this->email); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * Returns gravatar link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @return string as gravatar link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 6 |  |     public function getGravatar($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 6 |  |         $this->find("name", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 6 |  |         return $this->gravatar($this->email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * Set the pass. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @param string $pass the pass to use. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 5 |  |     public function setPassword($pass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 5 |  |         $this->pass = password_hash($pass, PASSWORD_DEFAULT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * Verify the name and the pass, if successful the object contains | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * all details from the database row. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param string $name  name to check. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @param string $pass the pass to use. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @return boolean true if name and pass matches, else false. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 3 |  |     public function verifyPassword($name, $pass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 3 |  |         $this->find("name", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 3 |  |         return password_verify($pass, $this->pass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * Verify the name and the anaswer, if successful the object contains | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * all details from the database row. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @param string $name  name to check. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @param string $answer the answer. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return boolean true if name and pass matches, else false. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 1 |  |     public function verifyQuestion($name, $answer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 1 |  |         $this->find("name", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 1 |  |         return ($this->question == $answer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     * Check if a post belongs to user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 | 1 |  |     public function controlAuthority($loggedUser, $name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 1 |  |         $this->find("name", $loggedUser); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         // IF AUTHORITY == admin, then continue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 1 |  |         if ($this->authority != "admin") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 1 |  |             return ($this->name == $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 1 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 177 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 178 |  |  |  | 
            
                        
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.