Complex classes like ActiveRecord often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ActiveRecord, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | abstract class ActiveRecord extends Arrayy |
||
| 43 | { |
||
| 44 | const BELONGS_TO = 'belongs_to'; |
||
| 45 | const HAS_MANY = 'has_many'; |
||
| 46 | const HAS_ONE = 'has_one'; |
||
| 47 | |||
| 48 | const PREFIX = ':active_record'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Check "@property" types from class-phpdoc. |
||
| 52 | * |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $checkPropertyTypes = true; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Check properties mismatch in the constructor. |
||
| 59 | * |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * @var array <p>Mapping the function name and the operator, to build Expressions in WHERE condition.</p> |
||
| 67 | * |
||
| 68 | * call the function like this: |
||
| 69 | * <pre> |
||
| 70 | * $user->isNotNull()->eq('id', 1); |
||
| 71 | * </pre> |
||
| 72 | * |
||
| 73 | * the result in SQL: |
||
| 74 | * <pre> |
||
| 75 | * WHERE user.id IS NOT NULL AND user.id = :ph1 |
||
| 76 | * </pre> |
||
| 77 | */ |
||
| 78 | protected static $operators = [ |
||
| 79 | 'equal' => '=', |
||
| 80 | 'eq' => '=', |
||
| 81 | 'notequal' => '<>', |
||
| 82 | 'ne' => '<>', |
||
| 83 | 'greaterthan' => '>', |
||
| 84 | 'gt' => '>', |
||
| 85 | 'lessthan' => '<', |
||
| 86 | 'lt' => '<', |
||
| 87 | 'greaterthanorequal' => '>=', |
||
| 88 | 'ge' => '>=', |
||
| 89 | 'gte' => '>=', |
||
| 90 | 'lessthanorequal' => '<=', |
||
| 91 | 'le' => '<=', |
||
| 92 | 'lte' => '<=', |
||
| 93 | 'between' => 'BETWEEN', |
||
| 94 | 'like' => 'LIKE', |
||
| 95 | 'in' => 'IN', |
||
| 96 | 'notin' => 'NOT IN', |
||
| 97 | 'isnull' => 'IS NULL', |
||
| 98 | 'isnotnull' => 'IS NOT NULL', |
||
| 99 | 'notnull' => 'IS NOT NULL', |
||
| 100 | ]; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var int <p>The count of bind params, using this count and const "PREFIX" (:ph) to generate place holder in |
||
| 104 | * SQL.</p> |
||
| 105 | */ |
||
| 106 | private static $count = 0; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var DB |
||
| 110 | */ |
||
| 111 | protected $db; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var array <p>Part of the SQL, mapping the function name and the operator to build SQL Part.</p> |
||
| 115 | * |
||
| 116 | * <br /> |
||
| 117 | * |
||
| 118 | * call the function like this: |
||
| 119 | * <pre> |
||
| 120 | * $user->orderBy('id DESC', 'name ASC')->limit(2, 1); |
||
| 121 | * </pre> |
||
| 122 | * |
||
| 123 | * the result in SQL: |
||
| 124 | * <pre> |
||
| 125 | * ORDER BY id DESC, name ASC LIMIT 2,1 |
||
| 126 | * </pre> |
||
| 127 | */ |
||
| 128 | protected $sqlParts = [ |
||
| 129 | 'select' => 'SELECT', |
||
| 130 | 'from' => 'FROM', |
||
| 131 | 'set' => 'SET', |
||
| 132 | 'where' => 'WHERE', |
||
| 133 | 'group' => 'GROUP BY', |
||
| 134 | 'having' => 'HAVING', |
||
| 135 | 'order' => 'ORDER BY', |
||
| 136 | 'limit' => 'LIMIT', |
||
| 137 | 'top' => 'TOP', |
||
| 138 | ]; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var array <p>The default sql expressions values.</p> |
||
| 142 | */ |
||
| 143 | protected $defaultSqlExpressions = [ |
||
| 144 | 'expressions' => [], |
||
| 145 | 'wrap' => false, |
||
| 146 | 'select' => null, |
||
| 147 | 'insert' => null, |
||
| 148 | 'update' => null, |
||
| 149 | 'set' => null, |
||
| 150 | 'delete' => 'DELETE ', |
||
| 151 | 'join' => null, |
||
| 152 | 'from' => null, |
||
| 153 | 'values' => null, |
||
| 154 | 'where' => null, |
||
| 155 | 'having' => null, |
||
| 156 | 'limit' => null, |
||
| 157 | 'order' => null, |
||
| 158 | 'orderBy' => null, |
||
| 159 | 'group' => null, |
||
| 160 | ]; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var array <p>Stored the Expressions of the SQL.</p> |
||
| 164 | */ |
||
| 165 | protected $sqlExpressions = []; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var string <p>The table name in database.</p> |
||
| 169 | */ |
||
| 170 | protected $table; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @var string <p>The primary key of this ActiveRecord, just support single primary key.</p> |
||
| 174 | */ |
||
| 175 | protected $primaryKeyName = 'id'; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var array <p>Stored the dirty data of this object, when call "insert" or "update" function, will write this data |
||
| 179 | * into database.</p> |
||
| 180 | */ |
||
| 181 | protected $dirty = []; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var bool |
||
| 185 | */ |
||
| 186 | protected $new_data_are_dirty = true; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var array <p>Stored the params will bind to SQL when call DB->query().</p> |
||
| 190 | */ |
||
| 191 | protected $params = []; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @var ActiveRecordExpressions[] <p>Stored the configure of the relation, or target of the relation.</p> |
||
| 195 | */ |
||
| 196 | protected $relations = []; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Magic function to make calls witch in function mapping stored in $operators and $sqlPart. |
||
| 200 | * also can call function of DB object. |
||
| 201 | * |
||
| 202 | * @param string $name <p>The name of the function.</p> |
||
| 203 | * @param array $args <p>The arguments of the function.</p> |
||
| 204 | * |
||
| 205 | * @return $this|mixed <p>Return the result of callback or the current object to make chain method calls.</p> |
||
| 206 | * |
||
| 207 | * @throws ActiveRecordException |
||
| 208 | */ |
||
| 209 | 16 | public function __call(string $name, array $args = []) |
|
| 210 | { |
||
| 211 | 16 | if (!$this->db instanceof DB) { |
|
| 212 | 14 | $this->db = DB::getInstance(); |
|
|
|
|||
| 213 | } |
||
| 214 | |||
| 215 | 16 | $nameTmp = \strtolower($name); |
|
| 216 | |||
| 217 | 16 | if (\array_key_exists($nameTmp, self::$operators)) { |
|
| 218 | |||
| 219 | 14 | $this->addCondition( |
|
| 220 | 14 | $args[0], |
|
| 221 | 14 | self::$operators[$nameTmp], |
|
| 222 | 14 | $args[1] ?? null, |
|
| 223 | 14 | (\is_string(\end($args)) && 'or' === \strtolower(\end($args))) ? 'OR' : 'AND' |
|
| 224 | ); |
||
| 225 | |||
| 226 | 11 | } elseif (\array_key_exists($nameTmp = \str_replace('by', '', $nameTmp), $this->sqlParts)) { |
|
| 227 | |||
| 228 | 11 | $this->{$name} = new ActiveRecordExpressions( |
|
| 229 | [ |
||
| 230 | 11 | 'operator' => $this->sqlParts[$nameTmp], |
|
| 231 | 11 | 'target' => \implode(', ', $args), |
|
| 232 | ] |
||
| 233 | ); |
||
| 234 | |||
| 235 | } elseif (\is_callable($callback = [$this->db, $name])) { |
||
| 236 | |||
| 237 | return \call_user_func_array($callback, $args); |
||
| 238 | |||
| 239 | } else { |
||
| 240 | |||
| 241 | throw new ActiveRecordException("Method $name not exist."); |
||
| 242 | |||
| 243 | } |
||
| 244 | |||
| 245 | 16 | return $this; |
|
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Magic function to GET the values of current object. |
||
| 250 | * |
||
| 251 | * @param mixed $var |
||
| 252 | * |
||
| 253 | * @return mixed |
||
| 254 | */ |
||
| 255 | 23 | public function &__get($var) |
|
| 256 | { |
||
| 257 | 23 | if (\array_key_exists($var, $this->sqlExpressions)) { |
|
| 258 | 20 | return $this->sqlExpressions[$var]; |
|
| 259 | } |
||
| 260 | |||
| 261 | 23 | if (\array_key_exists($var, $this->relations)) { |
|
| 262 | 3 | return $this->getRelation($var); |
|
| 263 | } |
||
| 264 | |||
| 265 | 23 | if (isset($this->dirty[$var])) { |
|
| 266 | 10 | return $this->dirty[$var]; |
|
| 267 | } |
||
| 268 | |||
| 269 | 23 | return parent::__get($var); |
|
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Magic function to SET values of the current object. |
||
| 274 | * |
||
| 275 | * @param string $var |
||
| 276 | * @param mixed $val |
||
| 277 | */ |
||
| 278 | 24 | public function __set($var, $val) |
|
| 279 | { |
||
| 280 | if ( |
||
| 281 | 24 | \array_key_exists($var, $this->sqlExpressions) |
|
| 282 | || |
||
| 283 | 24 | \array_key_exists($var, $this->defaultSqlExpressions) |
|
| 284 | ) { |
||
| 285 | |||
| 286 | 20 | $this->sqlExpressions[$var] = $val; |
|
| 287 | |||
| 288 | } elseif ( |
||
| 289 | 21 | \array_key_exists($var, $this->relations) |
|
| 290 | && |
||
| 291 | 21 | $val instanceof self |
|
| 292 | ) { |
||
| 293 | |||
| 294 | 1 | $this->relations[$var] = $val; |
|
| 295 | |||
| 296 | } else { |
||
| 297 | |||
| 298 | 21 | $this->set($var, $val); |
|
| 299 | |||
| 300 | 21 | if ($this->new_data_are_dirty === true) { |
|
| 301 | 15 | $this->dirty[$var] = $val; |
|
| 302 | } |
||
| 303 | |||
| 304 | } |
||
| 305 | 24 | } |
|
| 306 | |||
| 307 | /** |
||
| 308 | * Magic function to UNSET values of the current object. |
||
| 309 | * |
||
| 310 | * @param mixed $var |
||
| 311 | */ |
||
| 312 | 1 | public function __unset($var) |
|
| 313 | { |
||
| 314 | 1 | if (\array_key_exists($var, $this->sqlExpressions)) { |
|
| 315 | unset($this->sqlExpressions[$var]); |
||
| 316 | } |
||
| 317 | |||
| 318 | 1 | if (isset($this->array[$var])) { |
|
| 319 | 1 | unset($this->array[$var]); |
|
| 320 | } |
||
| 321 | |||
| 322 | 1 | if (isset($this->dirty[$var])) { |
|
| 323 | 1 | unset($this->dirty[$var]); |
|
| 324 | } |
||
| 325 | 1 | } |
|
| 326 | |||
| 327 | /** |
||
| 328 | * Get a value from an array (optional using dot-notation). |
||
| 329 | * |
||
| 330 | * @param string $key <p>The key to look for.</p> |
||
| 331 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 332 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 333 | * class.</p> |
||
| 334 | * |
||
| 335 | * @return mixed |
||
| 336 | */ |
||
| 337 | 23 | public function get($key, $fallback = null, array $array = null) |
|
| 341 | |||
| 342 | /** |
||
| 343 | * helper function to add condition into WHERE. |
||
| 344 | * |
||
| 345 | * @param ActiveRecordExpressions $expression <p>The expression will be concat into WHERE or SET statement.</p> |
||
| 346 | * @param string $operator <p>The operator to concat this Expressions into WHERE or SET |
||
| 347 | * statement.</p> |
||
| 348 | * @param string $name <p>The Expression will contact to.</p> |
||
| 349 | */ |
||
| 350 | 14 | protected function _addCondition(ActiveRecordExpressions $expression, string $operator, string $name = 'where') |
|
| 351 | { |
||
| 352 | 14 | if (!$this->{$name}) { |
|
| 353 | |||
| 354 | 14 | $this->{$name} = new ActiveRecordExpressions( |
|
| 355 | [ |
||
| 356 | 14 | 'operator' => \strtoupper($name), |
|
| 357 | 14 | 'target' => $expression, |
|
| 358 | ] |
||
| 359 | ); |
||
| 360 | |||
| 361 | } else { |
||
| 362 | |||
| 363 | 4 | $this->{$name}->target = new ActiveRecordExpressions( |
|
| 364 | [ |
||
| 365 | 4 | 'source' => $this->{$name}->target, |
|
| 366 | 4 | 'operator' => $operator, |
|
| 367 | 4 | 'target' => $expression, |
|
| 368 | ] |
||
| 369 | ); |
||
| 370 | |||
| 371 | } |
||
| 372 | 14 | } |
|
| 373 | |||
| 374 | /** |
||
| 375 | * helper function to make wrapper. Stored the expression in to array. |
||
| 376 | * |
||
| 377 | * @param ActiveRecordExpressions $exp <p>The expression will be stored.</p> |
||
| 378 | * @param string $operator <p>The operator to concat this Expressions into WHERE statement.</p> |
||
| 379 | */ |
||
| 380 | 1 | protected function _addExpression(ActiveRecordExpressions $exp, string $operator) |
|
| 381 | { |
||
| 382 | if ( |
||
| 383 | 1 | !\is_array($this->expressions) |
|
| 384 | || |
||
| 385 | 1 | \count($this->expressions) === 0 |
|
| 386 | ) { |
||
| 387 | 1 | $this->expressions = [$exp]; |
|
| 388 | } else { |
||
| 389 | 1 | $this->expressions[] = new ActiveRecordExpressions( |
|
| 390 | [ |
||
| 391 | 1 | 'operator' => $operator, |
|
| 392 | 1 | 'target' => $exp, |
|
| 393 | ] |
||
| 394 | ); |
||
| 395 | } |
||
| 396 | 1 | } |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Helper function to build SQL with sql parts. |
||
| 400 | * |
||
| 401 | * @param string[] $sql_array <p>The SQL part will be build.</p> |
||
| 402 | * |
||
| 403 | * @return string |
||
| 404 | */ |
||
| 405 | 21 | protected function _buildSql(array $sql_array = []): string |
|
| 414 | |||
| 415 | /** |
||
| 416 | * Helper function to build SQL with sql parts. |
||
| 417 | * |
||
| 418 | * @param string $sql_string_part <p>The SQL part will be build.</p> |
||
| 419 | * @param int $index <p>The index of $n in $sql array.</p> |
||
| 420 | * @param self $active_record <p>The reference to $this.</p> |
||
| 421 | */ |
||
| 422 | 21 | private function _buildSqlCallback(string &$sql_string_part, int $index, self $active_record) |
|
| 454 | |||
| 455 | /** |
||
| 456 | * Helper function to build place holder when make SQL expressions. |
||
| 457 | * |
||
| 458 | * @param mixed $value <p>The value will be bind to SQL, just store it in $this->params.</p> |
||
| 459 | * |
||
| 460 | * @return mixed $value |
||
| 461 | */ |
||
| 462 | 18 | protected function _filterParam($value) |
|
| 475 | |||
| 476 | /** |
||
| 477 | * Helper function to add condition into WHERE. |
||
| 478 | * |
||
| 479 | * @param string $field <p>The field name, the source of Expressions</p> |
||
| 480 | * @param string $operator <p>The operator for this condition.</p> |
||
| 481 | * @param mixed $value <p>The target of the Expressions.</p> |
||
| 482 | * @param string $operator_concat <p>The operator to concat this Expressions into WHERE or SET statement.</p> |
||
| 483 | * @param string $name <p>The Expression will contact to.</p> |
||
| 484 | */ |
||
| 485 | 14 | public function addCondition(string $field, string $operator, $value, string $operator_concat = 'AND', string $name = 'where') |
|
| 509 | |||
| 510 | /** |
||
| 511 | * Helper function to copy an existing active record (and insert it into the database). |
||
| 512 | * |
||
| 513 | * @param bool $insert |
||
| 514 | * |
||
| 515 | * @return $this |
||
| 516 | */ |
||
| 517 | 1 | public function copy(bool $insert = true): self |
|
| 529 | |||
| 530 | /** |
||
| 531 | * Function to delete current record in database. |
||
| 532 | * |
||
| 533 | * @return bool |
||
| 534 | */ |
||
| 535 | 1 | public function delete(): bool |
|
| 550 | |||
| 551 | /** |
||
| 552 | * Helper function to exec sql. |
||
| 553 | * |
||
| 554 | * @param string $sql <p>The SQL need to be execute.</p> |
||
| 555 | * @param array $param <p>The param will be bind to the sql statement.</p> |
||
| 556 | * |
||
| 557 | * @return bool|int|Result <p> |
||
| 558 | * "Result" by "<b>SELECT</b>"-queries<br /> |
||
| 559 | * "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> |
||
| 560 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 561 | * "true" by e.g. "DROP"-queries<br /> |
||
| 562 | * "false" on error |
||
| 563 | * </p> |
||
| 564 | */ |
||
| 565 | 23 | public function execute(string $sql, array $param = []) |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Function to find one record and assign in to current object. |
||
| 576 | * |
||
| 577 | * @param mixed $id <p> |
||
| 578 | * If call this function using this param, we will find the record by using this id. |
||
| 579 | * If not set, just find the first record in database. |
||
| 580 | * </p> |
||
| 581 | * |
||
| 582 | * @return false|$this <p> |
||
| 583 | * If we could find the record, assign in to current object and return it, |
||
| 584 | * otherwise return "false". |
||
| 585 | * </p> |
||
| 586 | */ |
||
| 587 | 11 | public function fetch($id = null) |
|
| 615 | |||
| 616 | /** |
||
| 617 | * Function to find all records in database. |
||
| 618 | * |
||
| 619 | * @param array|null $ids <p> |
||
| 620 | * If call this function using this param, we will find the record by using this id's. |
||
| 621 | * If not set, just find all records in database. |
||
| 622 | * </p> |
||
| 623 | * |
||
| 624 | * @return $this[] |
||
| 625 | */ |
||
| 626 | 6 | public function fetchAll(array $ids = null): array |
|
| 649 | |||
| 650 | /** |
||
| 651 | * @param mixed $id |
||
| 652 | * |
||
| 653 | * @return $this |
||
| 654 | * |
||
| 655 | * @throws FetchingException <p>Will be thrown, if we can not find the id.</p> |
||
| 656 | */ |
||
| 657 | 2 | public function fetchById($id): self |
|
| 666 | |||
| 667 | /** |
||
| 668 | * @param mixed $id |
||
| 669 | * |
||
| 670 | * @return $this|null |
||
| 671 | */ |
||
| 672 | 4 | public function fetchByIdIfExists($id) |
|
| 682 | |||
| 683 | /** |
||
| 684 | * @param array $ids |
||
| 685 | * |
||
| 686 | * @return $this[] |
||
| 687 | */ |
||
| 688 | 2 | public function fetchByIds(array $ids): array |
|
| 701 | |||
| 702 | /** |
||
| 703 | * @param array $ids |
||
| 704 | * |
||
| 705 | * @return $this[] |
||
| 706 | */ |
||
| 707 | 1 | public function fetchByIdsPrimaryKeyAsArrayIndex(array $ids): array |
|
| 718 | |||
| 719 | /** |
||
| 720 | * @param string $query |
||
| 721 | * |
||
| 722 | * @return $this[]|$this |
||
| 723 | */ |
||
| 724 | 2 | public function fetchByQuery(string $query) |
|
| 744 | |||
| 745 | /** |
||
| 746 | * @return $this |
||
| 747 | */ |
||
| 748 | 2 | public static function fetchEmpty(): self |
|
| 754 | |||
| 755 | /** |
||
| 756 | * @param string $query |
||
| 757 | * |
||
| 758 | * @return $this[] |
||
| 759 | */ |
||
| 760 | 1 | public function fetchManyByQuery(string $query): array |
|
| 770 | |||
| 771 | /** |
||
| 772 | * @param string $query |
||
| 773 | * |
||
| 774 | * @return $this|null |
||
| 775 | */ |
||
| 776 | 1 | public function fetchOneByQuery(string $query) |
|
| 792 | |||
| 793 | /** |
||
| 794 | * @return array |
||
| 795 | */ |
||
| 796 | 1 | public function getDirty(): array |
|
| 800 | |||
| 801 | /** |
||
| 802 | * @return array |
||
| 803 | */ |
||
| 804 | public function getParams(): array |
||
| 808 | |||
| 809 | /** |
||
| 810 | * @return mixed|null |
||
| 811 | */ |
||
| 812 | 13 | public function getPrimaryKey() |
|
| 821 | |||
| 822 | /** |
||
| 823 | * @return string |
||
| 824 | */ |
||
| 825 | public function getPrimaryKeyName(): string |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Helper function to get relation of this object. |
||
| 832 | * There was three types of relations: {BELONGS_TO, HAS_ONE, HAS_MANY} |
||
| 833 | * |
||
| 834 | * @param string $name <p>The name of the relation (the array key from the definition).</p> |
||
| 835 | * |
||
| 836 | * @return mixed |
||
| 837 | * |
||
| 838 | * @throws ActiveRecordException <p>If the relation can't be found .</p> |
||
| 839 | */ |
||
| 840 | 3 | protected function &getRelation(string $name) |
|
| 910 | |||
| 911 | /** |
||
| 912 | * @return string |
||
| 913 | */ |
||
| 914 | public function getTable(): string |
||
| 918 | |||
| 919 | /** |
||
| 920 | * Helper function for "GROUP BY". |
||
| 921 | * |
||
| 922 | * @param mixed $args |
||
| 923 | * |
||
| 924 | * @return $this |
||
| 925 | */ |
||
| 926 | public function groupBy($args): self |
||
| 932 | |||
| 933 | /** |
||
| 934 | * Function to build insert SQL, and insert current record into database. |
||
| 935 | * |
||
| 936 | * @return bool|int <p> |
||
| 937 | * If insert was successful, it will return the new id, |
||
| 938 | * otherwise it will return false or true (if there are no dirty data). |
||
| 939 | * </p> |
||
| 940 | */ |
||
| 941 | 4 | public function insert() |
|
| 977 | |||
| 978 | /** |
||
| 979 | * @return bool |
||
| 980 | */ |
||
| 981 | public function isNewDataAreDirty(): bool |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Helper function to add condition into JOIN. |
||
| 988 | * |
||
| 989 | * @param string $table <p>The join table name.</p> |
||
| 990 | * @param string $on <p>The condition of ON.</p> |
||
| 991 | * @param string $type <p>The join type, like "LEFT", "INNER", "OUTER".</p> |
||
| 992 | * |
||
| 993 | * @return $this |
||
| 994 | */ |
||
| 995 | 1 | public function join(string $table, string $on, string $type = 'LEFT'): self |
|
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Helper function for "ORDER BY". |
||
| 1016 | * |
||
| 1017 | * @param mixed $args |
||
| 1018 | * |
||
| 1019 | * @return $this |
||
| 1020 | */ |
||
| 1021 | 2 | public function orderBy($args): self |
|
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Helper function to query one record by sql and params. |
||
| 1030 | * |
||
| 1031 | * @param string $sql <p> |
||
| 1032 | * The SQL query to find the record. |
||
| 1033 | * </p> |
||
| 1034 | * @param array $param <p> |
||
| 1035 | * The param will be bind to the $sql query. |
||
| 1036 | * </p> |
||
| 1037 | * @param null|self $obj <p> |
||
| 1038 | * The object, if find record in database, we will assign the attributes into |
||
| 1039 | * this object. |
||
| 1040 | * </p> |
||
| 1041 | * @param bool $single <p> |
||
| 1042 | * If set to true, we will find record and fetch in current object, otherwise |
||
| 1043 | * will find all records. |
||
| 1044 | * </p> |
||
| 1045 | * |
||
| 1046 | * @return bool|$this|$this[] |
||
| 1047 | */ |
||
| 1048 | 17 | public function query(string $sql, array $param = [], self $obj = null, bool $single = false) |
|
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Function to reset the $params and $sqlExpressions. |
||
| 1078 | * |
||
| 1079 | * @return $this |
||
| 1080 | */ |
||
| 1081 | 23 | public function reset(): self |
|
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Reset the dirty data. |
||
| 1091 | * |
||
| 1092 | * @return $this |
||
| 1093 | */ |
||
| 1094 | 6 | public function resetDirty(): self |
|
| 1100 | |||
| 1101 | /** |
||
| 1102 | * set the DB connection. |
||
| 1103 | * |
||
| 1104 | * @param DB $db |
||
| 1105 | */ |
||
| 1106 | public function setDb(DB $db) |
||
| 1110 | |||
| 1111 | /** |
||
| 1112 | * @param bool $bool |
||
| 1113 | */ |
||
| 1114 | 17 | public function setNewDataAreDirty(bool $bool) |
|
| 1118 | |||
| 1119 | /** |
||
| 1120 | * @param mixed $primaryKey |
||
| 1121 | * @param bool $dirty |
||
| 1122 | * |
||
| 1123 | * @return $this |
||
| 1124 | */ |
||
| 1125 | 1 | public function setPrimaryKey($primaryKey, bool $dirty = true): self |
|
| 1139 | |||
| 1140 | /** |
||
| 1141 | * @param string $primaryKeyName |
||
| 1142 | * |
||
| 1143 | * @return $this |
||
| 1144 | */ |
||
| 1145 | public function setPrimaryKeyName(string $primaryKeyName): self |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * @param string $table |
||
| 1154 | */ |
||
| 1155 | public function setTable(string $table) |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Function to build update SQL, and update current record in database, just write the dirty data into database. |
||
| 1162 | * |
||
| 1163 | * @return bool|int <p> |
||
| 1164 | * If update was successful, it will return the affected rows as int, |
||
| 1165 | * otherwise it will return false or true (if there are no dirty data). |
||
| 1166 | * </p> |
||
| 1167 | */ |
||
| 1168 | 2 | public function update() |
|
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Make wrap when build the SQL expressions of WHERE. |
||
| 1200 | * |
||
| 1201 | * @param string $op <p>If given, this param will build one "ActiveRecordExpressionsWrap" and include the stored |
||
| 1202 | * expressions add into WHERE, otherwise it will stored the expressions into an array.</p> |
||
| 1203 | * |
||
| 1204 | * @return $this |
||
| 1205 | */ |
||
| 1206 | 1 | public function wrap($op = null): self |
|
| 1228 | } |
||
| 1229 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..