| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Kifekenny\Comment\HTMLForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use \Anax\HTMLForm\FormModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use \Anax\DI\DIInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use \Kifekenny\Comment\Comment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Form to create an item. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class Com2Create extends FormModel | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * Constructor injects with DI container. | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @param Anax\DI\DIInterface $di a service container | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 2 |  |     public function __construct(DIInterface $dis) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 2 |  |         parent::__construct($dis); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 2 |  |         $session = $this->di->get("session"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 2 |  |         $this->form->create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 2 |  |                 "id" => __CLASS__, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 2 |  |                 "legend" => "Add Comment", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 2 |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 1 |  |                 "userId" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 2 |  |                     "type" => "hidden", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 2 |  |                     "validation" => ["not_empty"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 2 |  |                     "value" => $session->get("user_id"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 2 |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 "Mail" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 2 |  |                     "type" => "text", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 2 |  |                     "readonly" => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 2 |  |                     "value" => $session->get("user_mail"), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 2 |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 "Title" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 2 |  |                     "type" => "text", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 2 |  |                     "validation" => ["not_empty"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 2 |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 "Content" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |                     "type" => "textarea", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |                     "validation" => ["not_empty"], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 2 |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 "submit" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 2 |  |                     "type" => "submit", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  |                     "value" => "Submit Comment", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 2 |  |                     "callback" => [$this, "callbackSubmit"] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 | 2 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * Callback for submit-button which should return true if it could | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * carry out its work and false if something failed. | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @return boolean true if okey, false if something went wrong. | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function callbackSubmit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $comment = new Comment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $comment->setDb($this->di->get("db")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $comment->title      = $this->form->value("Title"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $comment->content    = $this->form->value("Content"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $comment->userMail  = $this->form->value("Mail"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $comment->userId    = $this->form->value("userId"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         // $comment->user_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $comment->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->di->get("response")->redirect(""); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  | 
            
                        
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.