| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Class EntityModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @property int|float $dbId Buddy record DB ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class EntityModel implements \Common\IEntityModel { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |    * Link to DB which used by this EntityModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |    * @var \db_mysql $dbStatic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |    * deprecated - replace with container ID like 'db' or 'dbAuth' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |   protected static $dbStatic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |    * Service to work with rows | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |    * @var \DbRowDirectOperator $rowOperator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |   protected static $rowOperator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |    * Name of table for this entity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |    * @var string $tableName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |   protected $tableName = '_table'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |    * Name of key field field in this table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |    * @var string $idField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |   protected $idField = 'id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | //  /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | //   * Property list and description | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | //   * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | //   * propertyName => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | //   *    P_DB_FIELD => 'dbFieldName', - directly converts property to field and vice versa | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | //   * ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | //   * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | //   * @var array[] $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | //   */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | //  protected $properties = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |    * Name of exception class that would be thrown | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |    * Uses for calling when you don't know which exact exception should be called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |    * On EntityModel's children should be used exception class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |    * @var string $exceptionClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |   protected static $exceptionClass = 'EntityException'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |   protected static $entityContainerClass = '\EntityContainer'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |    * EntityModel constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |    * @param \Common\GlobalContainer $gc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |   public function __construct($gc) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     static::$dbStatic = $gc->db; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     static::$rowOperator = $gc->dbRowOperator; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |    * @return \db_mysql | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |   public function getDbStatic() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     return static::$dbStatic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |    * @return \DbRowDirectOperator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |   public function getRowOperator() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     return static::$rowOperator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |   public function setTableName($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     $this->tableName = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |   public function getTableName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     return $this->tableName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |   public function setIdFieldName($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     $this->idField = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |   public function getIdFieldName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     return $this->idField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |   public function fromArray($array) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @var EntityContainer $cEntity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     $cEntity = new static::$entityContainerClass(classSupernova::$gc); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     $cEntity->importRow($array); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     return $cEntity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |   public function exportRow($cEntity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     return $cEntity->exportRow(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |   public function exportRowNoId($cEntity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     $row = $this->exportRow($cEntity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     unset($row[$this->getIdFieldName()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     return $row; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |   public function loadTry($dbId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     $row = static::$rowOperator->getById($this, $dbId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     if (empty($row)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |       return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |       $cEntity = $this->fromArray($row); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     return $cEntity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 149 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 150 |  |  |  | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.