| @@ -1,10 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\Lib; |
| 4 | 4 | |
| 5 | +use ArrayAccess; | |
| 6 | +use Exception; | |
| 7 | +use InvalidArgumentException; | |
| 8 | +use ReturnTypeWillChange; | |
| 5 | 9 | use wpdb; |
| 6 | -use ReturnTypeWillChange; | |
| 7 | 10 | use Yoast\WP\SEO\Config\Migration_Status; |
| 8 | 11 | |
| 9 | 12 | /** |
| 10 | 13 | * Yoast ORM class. |
| @@ -47,17 +50,17 @@ | ||
| 47 | 50 | * This documentation exposes these methods to doc generators and IDEs. |
| 48 | 51 | * |
| 49 | 52 | * @see http://www.php-fig.org/psr/psr-1/ |
| 50 | 53 | */ |
| 51 | -class ORM implements \ArrayAccess { | |
| 54 | +class ORM implements ArrayAccess { | |
| 52 | 55 | |
| 53 | 56 | /* |
| 54 | 57 | * --- CLASS CONSTANTS --- |
| 55 | 58 | */ |
| 56 | 59 | |
| 57 | - const CONDITION_FRAGMENT = 0; | |
| 60 | + public const CONDITION_FRAGMENT = 0; | |
| 58 | 61 | |
| 59 | - const CONDITION_VALUES = 1; | |
| 62 | + public const CONDITION_VALUES = 1; | |
| 60 | 63 | |
| 61 | 64 | /* |
| 62 | 65 | * --- INSTANCE PROPERTIES --- |
| 63 | 66 | */ |
| @@ -78,9 +81,9 @@ | ||
| 78 | 81 | |
| 79 | 82 | /** |
| 80 | 83 | * Holds the alias for the table to be used in SELECT queries. |
| 81 | 84 | * |
| 82 | - * @var string | |
| 85 | + * @var string|null | |
| 83 | 86 | */ |
| 84 | 87 | protected $table_alias = null; |
| 85 | 88 | |
| 86 | 89 | /** |
| @@ -148,9 +151,9 @@ | ||
| 148 | 151 | |
| 149 | 152 | /** |
| 150 | 153 | * LIMIT. |
| 151 | 154 | * |
| 152 | - * @var int | |
| 155 | + * @var int|null | |
| 153 | 156 | */ |
| 154 | 157 | protected $limit = null; |
| 155 | 158 | |
| 156 | 159 | /** |
| @@ -155,9 +158,9 @@ | ||
| 155 | 158 | |
| 156 | 159 | /** |
| 157 | 160 | * OFFSET. |
| 158 | 161 | * |
| 159 | - * @var int | |
| 162 | + * @var int|null | |
| 160 | 163 | */ |
| 161 | 164 | protected $offset = null; |
| 162 | 165 | |
| 163 | 166 | /** |
| @@ -212,9 +215,9 @@ | ||
| 212 | 215 | /** |
| 213 | 216 | * Name of the column to use as the primary key for |
| 214 | 217 | * this instance only. Overrides the config settings. |
| 215 | 218 | * |
| 216 | - * @var string | |
| 219 | + * @var string|null | |
| 217 | 220 | */ |
| 218 | 221 | protected $instance_id_column = null; |
| 219 | 222 | |
| 220 | 223 | /* |
| @@ -263,23 +266,23 @@ | ||
| 263 | 266 | protected static function execute( $query, $parameters = [] ) { |
| 264 | 267 | /** |
| 265 | 268 | * The global WordPress database variable. |
| 266 | 269 | * |
| 267 | - * @var wpdb | |
| 270 | + * @var wpdb $wpdb | |
| 268 | 271 | */ |
| 269 | 272 | global $wpdb; |
| 270 | 273 | |
| 271 | 274 | $show_errors = $wpdb->show_errors; |
| 272 | 275 | |
| 273 | - if ( YoastSEO()->classes->get( Migration_Status::class )->get_error( 'free' ) ) { | |
| 276 | + if ( \YoastSEO()->classes->get( Migration_Status::class )->get_error( 'free' ) ) { | |
| 274 | 277 | $wpdb->show_errors = false; |
| 275 | 278 | } |
| 276 | 279 | |
| 277 | 280 | $parameters = \array_filter( |
| 278 | 281 | $parameters, |
| 279 | - static function( $parameter ) { | |
| 282 | + static function ( $parameter ) { | |
| 280 | 283 | return $parameter !== null; |
| 281 | - } | |
| 284 | + }, | |
| 282 | 285 | ); |
| 283 | 286 | if ( ! empty( $parameters ) ) { |
| 284 | 287 | $query = $wpdb->prepare( $query, $parameters ); |
| 285 | 288 | } |
| @@ -328,9 +331,9 @@ | ||
| 328 | 331 | * @return bool|Model|ORM |
| 329 | 332 | */ |
| 330 | 333 | public function create( $data = null ) { |
| 331 | 334 | $this->is_new = true; |
| 332 | - if ( ! \is_null( $data ) ) { | |
| 335 | + if ( $data !== null ) { | |
| 333 | 336 | $this->hydrate( $data )->force_all_dirty(); |
| 334 | 337 | } |
| 335 | 338 | |
| 336 | 339 | return $this->create_model_instance( $this ); |
| @@ -377,9 +380,9 @@ | ||
| 377 | 380 | * |
| 378 | 381 | * @return bool|Model |
| 379 | 382 | */ |
| 380 | 383 | public function find_one( $id = null ) { |
| 381 | - if ( ! \is_null( $id ) ) { | |
| 384 | + if ( $id !== null ) { | |
| 382 | 385 | $this->where_id_is( $id ); |
| 383 | 386 | } |
| 384 | 387 | $this->limit( 1 ); |
| 385 | 388 | $rows = $this->run(); |
| @@ -536,9 +539,9 @@ | ||
| 536 | 539 | if ( $result !== false && isset( $result->{$alias} ) ) { |
| 537 | 540 | if ( ! \is_numeric( $result->{$alias} ) ) { |
| 538 | 541 | $return_value = $result->{$alias}; |
| 539 | 542 | } |
| 540 | - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Reason: This loose comparison seems intended. | |
| 543 | + // phpcs:ignore Universal.Operators.StrictComparisons -- Reason: This loose comparison seems intentional. | |
| 541 | 544 | elseif ( (int) $result->{$alias} == (float) $result->{$alias} ) { |
| 542 | 545 | $return_value = (int) $result->{$alias}; |
| 543 | 546 | } |
| 544 | 547 | else { |
| @@ -614,9 +617,9 @@ | ||
| 614 | 617 | * |
| 615 | 618 | * @return ORM |
| 616 | 619 | */ |
| 617 | 620 | protected function add_result_column( $expr, $alias = null ) { |
| 618 | - if ( ! \is_null( $alias ) ) { | |
| 621 | + if ( $alias !== null ) { | |
| 619 | 622 | $expr .= ' AS ' . $this->quote_identifier( $alias ); |
| 620 | 623 | } |
| 621 | 624 | if ( $this->using_default_result_columns ) { |
| 622 | 625 | $this->result_columns = [ $expr ]; |
| @@ -633,10 +636,10 @@ | ||
| 633 | 636 | * Counts the number of columns that belong to the primary key and their value is null. |
| 634 | 637 | * |
| 635 | 638 | * @return int The amount of null columns. |
| 636 | 639 | * |
| 637 | - * @throws \Exception Primary key ID contains null value(s). | |
| 638 | - * @throws \Exception Primary key ID missing from row or is null. | |
| 640 | + * @throws Exception Primary key ID contains null value(s). | |
| 641 | + * @throws Exception Primary key ID missing from row or is null. | |
| 639 | 642 | */ |
| 640 | 643 | public function count_null_id_columns() { |
| 641 | 644 | if ( \is_array( $this->get_id_column_name() ) ) { |
| 642 | 645 | return \count( \array_filter( $this->id(), 'is_null' ) ); |
| @@ -641,9 +644,9 @@ | ||
| 641 | 644 | if ( \is_array( $this->get_id_column_name() ) ) { |
| 642 | 645 | return \count( \array_filter( $this->id(), 'is_null' ) ); |
| 643 | 646 | } |
| 644 | 647 | else { |
| 645 | - return \is_null( $this->id() ) ? 1 : 0; | |
| 648 | + return ( $this->id() === null ) ? 1 : 0; | |
| 646 | 649 | } |
| 647 | 650 | } |
| 648 | 651 | |
| 649 | 652 | /** |
| @@ -805,9 +808,9 @@ | ||
| 805 | 808 | protected function add_join_source( $join_operator, $table, $constraint, $table_alias = null ) { |
| 806 | 809 | $join_operator = \trim( "{$join_operator} JOIN" ); |
| 807 | 810 | $table = $this->quote_identifier( $table ); |
| 808 | 811 | // Add table alias if present. |
| 809 | - if ( ! \is_null( $table_alias ) ) { | |
| 812 | + if ( $table_alias !== null ) { | |
| 810 | 813 | $table_alias = $this->quote_identifier( $table_alias ); |
| 811 | 814 | $table .= " {$table_alias}"; |
| 812 | 815 | } |
| 813 | 816 | // Build the constraint. |
| @@ -834,9 +837,9 @@ | ||
| 834 | 837 | * @return ORM |
| 835 | 838 | */ |
| 836 | 839 | public function raw_join( $table, $constraint, $table_alias, $parameters = [] ) { |
| 837 | 840 | // Add table alias if present. |
| 838 | - if ( ! \is_null( $table_alias ) ) { | |
| 841 | + if ( $table_alias !== null ) { | |
| 839 | 842 | $table_alias = $this->quote_identifier( $table_alias ); |
| 840 | 843 | $table .= " {$table_alias}"; |
| 841 | 844 | } |
| 842 | 845 | $this->values = \array_merge( $this->values, $parameters ); |
| @@ -1076,9 +1079,9 @@ | ||
| 1076 | 1079 | $this->{$conditions_class_property_name}, |
| 1077 | 1080 | [ |
| 1078 | 1081 | self::CONDITION_FRAGMENT => $fragment, |
| 1079 | 1082 | self::CONDITION_VALUES => $values, |
| 1080 | - ] | |
| 1083 | + ], | |
| 1081 | 1084 | ); |
| 1082 | 1085 | |
| 1083 | 1086 | return $this; |
| 1084 | 1087 | } |
| @@ -1103,9 +1106,9 @@ | ||
| 1103 | 1106 | foreach ( $multiple as $key => $val ) { |
| 1104 | 1107 | // Add the table name in case of ambiguous columns. |
| 1105 | 1108 | if ( \count( $result->join_sources ) > 0 && \strpos( $key, '.' ) === false ) { |
| 1106 | 1109 | $table = $result->table_name; |
| 1107 | - if ( ! \is_null( $result->table_alias ) ) { | |
| 1110 | + if ( $result->table_alias !== null ) { | |
| 1108 | 1111 | $table = $result->table_alias; |
| 1109 | 1112 | } |
| 1110 | 1113 | $key = "{$table}.{$key}"; |
| 1111 | 1114 | } |
| @@ -1154,9 +1157,9 @@ | ||
| 1154 | 1157 | */ |
| 1155 | 1158 | protected function get_compound_id_column_values( $value ) { |
| 1156 | 1159 | $filtered = []; |
| 1157 | 1160 | foreach ( $this->get_id_column_name() as $key ) { |
| 1158 | - $filtered[ $key ] = isset( $value[ $key ] ) ? $value[ $key ] : null; | |
| 1161 | + $filtered[ $key ] = ( $value[ $key ] ?? null ); | |
| 1159 | 1162 | } |
| 1160 | 1163 | |
| 1161 | 1164 | return $filtered; |
| 1162 | 1165 | } |
| @@ -1256,9 +1259,9 @@ | ||
| 1256 | 1259 | $query[] = ') OR ('; |
| 1257 | 1260 | } |
| 1258 | 1261 | $firstsub = true; |
| 1259 | 1262 | foreach ( $value as $key => $item ) { |
| 1260 | - $op = \is_string( $operator ) ? $operator : ( isset( $operator[ $key ] ) ? $operator[ $key ] : '=' ); | |
| 1263 | + $op = \is_string( $operator ) ? $operator : ( $operator[ $key ] ?? '=' ); | |
| 1261 | 1264 | if ( $op === '=' && $item === null ) { |
| 1262 | 1265 | $op = 'IS'; |
| 1263 | 1266 | } |
| 1264 | 1267 | if ( $firstsub ) { |
| @@ -1586,9 +1589,9 @@ | ||
| 1586 | 1589 | /** |
| 1587 | 1590 | * Adds a HAVING ... LIKE clause to your query. |
| 1588 | 1591 | * |
| 1589 | 1592 | * @param string|array $column_name The table column. |
| 1590 | - * @param null $value The value. | |
| 1593 | + * @param string|null $value The value. | |
| 1591 | 1594 | * |
| 1592 | 1595 | * @return ORM |
| 1593 | 1596 | */ |
| 1594 | 1597 | public function having_like( $column_name, $value = null ) { |
| @@ -1598,9 +1601,9 @@ | ||
| 1598 | 1601 | /** |
| 1599 | 1602 | * Adds where HAVING ... NOT LIKE clause to your query. |
| 1600 | 1603 | * |
| 1601 | 1604 | * @param string|array $column_name The table column. |
| 1602 | - * @param null $value The value. | |
| 1605 | + * @param string|null $value The value. | |
| 1603 | 1606 | * |
| 1604 | 1607 | * @return ORM |
| 1605 | 1608 | */ |
| 1606 | 1609 | public function having_not_like( $column_name, $value = null ) { |
| @@ -1610,9 +1613,9 @@ | ||
| 1610 | 1613 | /** |
| 1611 | 1614 | * Adds a HAVING ... > clause to your query. |
| 1612 | 1615 | * |
| 1613 | 1616 | * @param string|array $column_name The table column. |
| 1614 | - * @param null $value The value. | |
| 1617 | + * @param mixed $value The value. | |
| 1615 | 1618 | * |
| 1616 | 1619 | * @return ORM |
| 1617 | 1620 | */ |
| 1618 | 1621 | public function having_gt( $column_name, $value = null ) { |
| @@ -1622,9 +1625,9 @@ | ||
| 1622 | 1625 | /** |
| 1623 | 1626 | * Adds a HAVING ... < clause to your query. |
| 1624 | 1627 | * |
| 1625 | 1628 | * @param string|array $column_name The table column. |
| 1626 | - * @param null $value The value. | |
| 1629 | + * @param mixed $value The value. | |
| 1627 | 1630 | * |
| 1628 | 1631 | * @return ORM |
| 1629 | 1632 | */ |
| 1630 | 1633 | public function having_lt( $column_name, $value = null ) { |
| @@ -1634,9 +1637,9 @@ | ||
| 1634 | 1637 | /** |
| 1635 | 1638 | * Adds a HAVING ... >= clause to your query. |
| 1636 | 1639 | * |
| 1637 | 1640 | * @param string|array $column_name The table column. |
| 1638 | - * @param null $value The value. Defaults to null. | |
| 1641 | + * @param mixed $value The value. Defaults to null. | |
| 1639 | 1642 | * |
| 1640 | 1643 | * @return ORM |
| 1641 | 1644 | */ |
| 1642 | 1645 | public function having_gte( $column_name, $value = null ) { |
| @@ -1646,9 +1649,9 @@ | ||
| 1646 | 1649 | /** |
| 1647 | 1650 | * Adds a HAVING ... <= clause to your query. |
| 1648 | 1651 | * |
| 1649 | 1652 | * @param string|array $column_name The table column. |
| 1650 | - * @param null $value The value. | |
| 1653 | + * @param mixed $value The value. | |
| 1651 | 1654 | * |
| 1652 | 1655 | * @return ORM |
| 1653 | 1656 | */ |
| 1654 | 1657 | public function having_lte( $column_name, $value = null ) { |
| @@ -1658,9 +1661,9 @@ | ||
| 1658 | 1661 | /** |
| 1659 | 1662 | * Adds a HAVING ... IN clause to your query. |
| 1660 | 1663 | * |
| 1661 | 1664 | * @param string|array $column_name The table column. |
| 1662 | - * @param null $values The values. Defaults to null. | |
| 1665 | + * @param array|null $values The values. Defaults to null. | |
| 1663 | 1666 | * |
| 1664 | 1667 | * @return ORM |
| 1665 | 1668 | */ |
| 1666 | 1669 | public function having_in( $column_name, $values = null ) { |
| @@ -1670,9 +1673,9 @@ | ||
| 1670 | 1673 | /** |
| 1671 | 1674 | * Adds a HAVING ... NOT IN clause to your query. |
| 1672 | 1675 | * |
| 1673 | 1676 | * @param string|array $column_name The table column. |
| 1674 | - * @param null $values The values. Defaults to null. | |
| 1677 | + * @param array|null $values The values. Defaults to null. | |
| 1675 | 1678 | * |
| 1676 | 1679 | * @return ORM |
| 1677 | 1680 | */ |
| 1678 | 1681 | public function having_not_in( $column_name, $values = null ) { |
| @@ -1738,9 +1741,9 @@ | ||
| 1738 | 1741 | $this->build_having(), |
| 1739 | 1742 | $this->build_order_by(), |
| 1740 | 1743 | $this->build_limit(), |
| 1741 | 1744 | $this->build_offset(), |
| 1742 | - ] | |
| 1745 | + ], | |
| 1743 | 1746 | ); |
| 1744 | 1747 | } |
| 1745 | 1748 | |
| 1746 | 1749 | /** |
| @@ -1754,9 +1757,9 @@ | ||
| 1754 | 1757 | if ( $this->distinct ) { |
| 1755 | 1758 | $result_columns = 'DISTINCT ' . $result_columns; |
| 1756 | 1759 | } |
| 1757 | 1760 | $fragment .= "{$result_columns} FROM " . $this->quote_identifier( $this->table_name ); |
| 1758 | - if ( ! \is_null( $this->table_alias ) ) { | |
| 1761 | + if ( $this->table_alias !== null ) { | |
| 1759 | 1762 | $fragment .= ' ' . $this->quote_identifier( $this->table_alias ); |
| 1760 | 1763 | } |
| 1761 | 1764 | |
| 1762 | 1765 | return $fragment; |
| @@ -1846,9 +1849,9 @@ | ||
| 1846 | 1849 | * |
| 1847 | 1850 | * @return string |
| 1848 | 1851 | */ |
| 1849 | 1852 | protected function build_limit() { |
| 1850 | - if ( ! \is_null( $this->limit ) ) { | |
| 1853 | + if ( $this->limit !== null ) { | |
| 1851 | 1854 | return "LIMIT {$this->limit}"; |
| 1852 | 1855 | } |
| 1853 | 1856 | |
| 1854 | 1857 | return ''; |
| @@ -1859,9 +1862,9 @@ | ||
| 1859 | 1862 | * |
| 1860 | 1863 | * @return string |
| 1861 | 1864 | */ |
| 1862 | 1865 | protected function build_offset() { |
| 1863 | - if ( ! \is_null( $this->offset ) ) { | |
| 1866 | + if ( $this->offset !== null ) { | |
| 1864 | 1867 | return 'OFFSET ' . $this->offset; |
| 1865 | 1868 | } |
| 1866 | 1869 | |
| 1867 | 1870 | return ''; |
| @@ -1975,8 +1978,10 @@ | ||
| 1975 | 1978 | } |
| 1976 | 1979 | |
| 1977 | 1980 | /** |
| 1978 | 1981 | * Resets the Idiorm instance state. |
| 1982 | + * | |
| 1983 | + * @return void | |
| 1979 | 1984 | */ |
| 1980 | 1985 | private function reset_idiorm_state() { |
| 1981 | 1986 | $this->values = []; |
| 1982 | 1987 | $this->result_columns = [ '*' ]; |
| @@ -2011,15 +2016,15 @@ | ||
| 2011 | 2016 | public function get( $key ) { |
| 2012 | 2017 | if ( \is_array( $key ) ) { |
| 2013 | 2018 | $result = []; |
| 2014 | 2019 | foreach ( $key as $column ) { |
| 2015 | - $result[ $column ] = isset( $this->data[ $column ] ) ? $this->data[ $column ] : null; | |
| 2020 | + $result[ $column ] = ( $this->data[ $column ] ?? null ); | |
| 2016 | 2021 | } |
| 2017 | 2022 | |
| 2018 | 2023 | return $result; |
| 2019 | 2024 | } |
| 2020 | 2025 | else { |
| 2021 | - return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; | |
| 2026 | + return ( $this->data[ $key ] ?? null ); | |
| 2022 | 2027 | } |
| 2023 | 2028 | } |
| 2024 | 2029 | |
| 2025 | 2030 | /** |
| @@ -2027,9 +2032,9 @@ | ||
| 2027 | 2032 | * |
| 2028 | 2033 | * @return string The primary key ID of the row. |
| 2029 | 2034 | */ |
| 2030 | 2035 | protected function get_id_column_name() { |
| 2031 | - if ( ! \is_null( $this->instance_id_column ) ) { | |
| 2036 | + if ( $this->instance_id_column !== null ) { | |
| 2032 | 2037 | return $this->instance_id_column; |
| 2033 | 2038 | } |
| 2034 | 2039 | |
| 2035 | 2040 | return 'id'; |
| @@ -2041,10 +2046,10 @@ | ||
| 2041 | 2046 | * @param bool $disallow_null Whether to allow null IDs. |
| 2042 | 2047 | * |
| 2043 | 2048 | * @return array|mixed|null |
| 2044 | 2049 | * |
| 2045 | - * @throws \Exception Primary key ID contains null value(s). | |
| 2046 | - * @throws \Exception Primary key ID missing from row or is null. | |
| 2050 | + * @throws Exception Primary key ID contains null value(s). | |
| 2051 | + * @throws Exception Primary key ID missing from row or is null. | |
| 2047 | 2052 | */ |
| 2048 | 2053 | public function id( $disallow_null = false ) { |
| 2049 | 2054 | $id = $this->get( $this->get_id_column_name() ); |
| 2050 | 2055 | if ( $disallow_null ) { |
| @@ -2050,16 +2055,14 @@ | ||
| 2050 | 2055 | if ( $disallow_null ) { |
| 2051 | 2056 | if ( \is_array( $id ) ) { |
| 2052 | 2057 | foreach ( $id as $id_part ) { |
| 2053 | 2058 | if ( $id_part === null ) { |
| 2054 | - throw new \Exception( 'Primary key ID contains null value(s)' ); | |
| 2059 | + throw new Exception( 'Primary key ID contains null value(s)' ); | |
| 2055 | 2060 | } |
| 2056 | 2061 | } |
| 2057 | 2062 | } |
| 2058 | - else { | |
| 2059 | - if ( $id === null ) { | |
| 2060 | - throw new \Exception( 'Primary key ID missing from row or is null' ); | |
| 2061 | - } | |
| 2063 | + elseif ( $id === null ) { | |
| 2064 | + throw new Exception( 'Primary key ID missing from row or is null' ); | |
| 2062 | 2065 | } |
| 2063 | 2066 | } |
| 2064 | 2067 | |
| 2065 | 2068 | return $id; |
| @@ -2113,12 +2116,10 @@ | ||
| 2113 | 2116 | $this->dirty_fields[ $field ] = $value; |
| 2114 | 2117 | if ( $expr === false && isset( $this->expr_fields[ $field ] ) ) { |
| 2115 | 2118 | unset( $this->expr_fields[ $field ] ); |
| 2116 | 2119 | } |
| 2117 | - else { | |
| 2118 | - if ( $expr === true ) { | |
| 2119 | - $this->expr_fields[ $field ] = true; | |
| 2120 | - } | |
| 2120 | + elseif ( $expr === true ) { | |
| 2121 | + $this->expr_fields[ $field ] = true; | |
| 2121 | 2122 | } |
| 2122 | 2123 | } |
| 2123 | 2124 | |
| 2124 | 2125 | return $this; |
| @@ -2148,10 +2149,10 @@ | ||
| 2148 | 2149 | * Saves any fields which have been modified on this object to the database. |
| 2149 | 2150 | * |
| 2150 | 2151 | * @return bool True on success. |
| 2151 | 2152 | * |
| 2152 | - * @throws \Exception Primary key ID contains null value(s). | |
| 2153 | - * @throws \Exception Primary key ID missing from row or is null. | |
| 2153 | + * @throws Exception Primary key ID contains null value(s). | |
| 2154 | + * @throws Exception Primary key ID missing from row or is null. | |
| 2154 | 2155 | */ |
| 2155 | 2156 | public function save() { |
| 2156 | 2157 | global $wpdb; |
| 2157 | 2158 | |
| @@ -2203,9 +2204,9 @@ | ||
| 2203 | 2204 | * @param array $models Array of model instances to be inserted. |
| 2204 | 2205 | * |
| 2205 | 2206 | * @return array The distinct set of columns that are dirty in at least one of the models. |
| 2206 | 2207 | * |
| 2207 | - * @throws \InvalidArgumentException Instance to be inserted is not a new one. | |
| 2208 | + * @throws InvalidArgumentException Instance to be inserted is not a new one. | |
| 2208 | 2209 | */ |
| 2209 | 2210 | public function get_dirty_column_names( $models ) { |
| 2210 | 2211 | $dirty_column_names = []; |
| 2211 | 2212 | |
| @@ -2210,9 +2211,9 @@ | ||
| 2210 | 2211 | $dirty_column_names = []; |
| 2211 | 2212 | |
| 2212 | 2213 | foreach ( $models as $model ) { |
| 2213 | 2214 | if ( ! $model->orm->is_new() ) { |
| 2214 | - throw new \InvalidArgumentException( 'Instance to be inserted is not a new one' ); | |
| 2215 | + throw new InvalidArgumentException( 'Instance to be inserted is not a new one' ); | |
| 2215 | 2216 | } |
| 2216 | 2217 | |
| 2217 | 2218 | // Remove any expression fields as they are already baked into the query. |
| 2218 | 2219 | $dirty_fields = \array_diff_key( $model->orm->dirty_fields, $model->orm->expr_fields ); |
| @@ -2232,15 +2233,15 @@ | ||
| 2232 | 2233 | * @param array $models Array of model instances to be inserted. |
| 2233 | 2234 | * |
| 2234 | 2235 | * @return bool True for successful insert, false for failed. |
| 2235 | 2236 | * |
| 2236 | - * @throws \InvalidArgumentException Invalid instances to be inserted. | |
| 2237 | - * @throws \InvalidArgumentException Instance to be inserted is not a new one. | |
| 2237 | + * @throws InvalidArgumentException Invalid instances to be inserted. | |
| 2238 | + * @throws InvalidArgumentException Instance to be inserted is not a new one. | |
| 2238 | 2239 | */ |
| 2239 | 2240 | public function insert_many( $models ) { |
| 2240 | 2241 | // Validate the input first. |
| 2241 | 2242 | if ( ! \is_array( $models ) ) { |
| 2242 | - throw new \InvalidArgumentException( 'Invalid instances to be inserted' ); | |
| 2243 | + throw new InvalidArgumentException( 'Invalid instances to be inserted' ); | |
| 2243 | 2244 | } |
| 2244 | 2245 | |
| 2245 | 2246 | if ( empty( $models ) ) { |
| 2246 | 2247 | return true; |
| @@ -2250,9 +2251,9 @@ | ||
| 2250 | 2251 | |
| 2251 | 2252 | /** |
| 2252 | 2253 | * Filter: 'wpseo_chunk_bulked_insert_queries' - Allow filtering the chunk size of each bulked INSERT query. |
| 2253 | 2254 | * |
| 2254 | - * @api int The chunk size of the bulked INSERT queries. | |
| 2255 | + * @param int $chunk_size The chunk size of the bulked INSERT queries. | |
| 2255 | 2256 | */ |
| 2256 | 2257 | $chunk = \apply_filters( 'wpseo_chunk_bulk_insert_queries', 100 ); |
| 2257 | 2258 | $chunk = ! \is_int( $chunk ) ? 100 : $chunk; |
| 2258 | 2259 | $chunk = ( $chunk <= 0 ) ? 100 : $chunk; |
| @@ -2275,9 +2276,9 @@ | ||
| 2275 | 2276 | $model->orm->dirty_fields[ $dirty_column ] = null; |
| 2276 | 2277 | } |
| 2277 | 2278 | |
| 2278 | 2279 | // Only register the value if it is not null. |
| 2279 | - if ( ! is_null( $model->orm->dirty_fields[ $dirty_column ] ) ) { | |
| 2280 | + if ( $model->orm->dirty_fields[ $dirty_column ] !== null ) { | |
| 2280 | 2281 | $model_values[] = $model->orm->dirty_fields[ $dirty_column ]; |
| 2281 | 2282 | } |
| 2282 | 2283 | } |
| 2283 | 2284 | $values = \array_merge( $values, $model_values ); |
| @@ -2414,10 +2415,10 @@ | ||
| 2414 | 2415 | * Deletes this record from the database. |
| 2415 | 2416 | * |
| 2416 | 2417 | * @return string The delete query. |
| 2417 | 2418 | * |
| 2418 | - * @throws \Exception Primary key ID contains null value(s). | |
| 2419 | - * @throws \Exception Primary key ID missing from row or is null. | |
| 2419 | + * @throws Exception Primary key ID contains null value(s). | |
| 2420 | + * @throws Exception Primary key ID missing from row or is null. | |
| 2420 | 2421 | */ |
| 2421 | 2422 | public function delete() { |
| 2422 | 2423 | $query = [ 'DELETE FROM', $this->quote_identifier( $this->table_name ), $this->add_id_column_conditions() ]; |
| 2423 | 2424 | |
| @@ -2437,9 +2438,9 @@ | ||
| 2437 | 2438 | [ |
| 2438 | 2439 | 'DELETE FROM', |
| 2439 | 2440 | $this->quote_identifier( $this->table_name ), |
| 2440 | 2441 | $this->build_where(), |
| 2441 | - ] | |
| 2442 | + ], | |
| 2442 | 2443 | ); |
| 2443 | 2444 | |
| 2444 | 2445 | return self::execute( $query, $this->values ); |
| 2445 | 2446 | } |
| @@ -2450,52 +2451,56 @@ | ||
| 2450 | 2451 | |
| 2451 | 2452 | /** |
| 2452 | 2453 | * Checks whether the data has the key. |
| 2453 | 2454 | * |
| 2454 | - * @param mixed $key Key. | |
| 2455 | + * @param mixed $offset Key. | |
| 2455 | 2456 | * |
| 2456 | 2457 | * @return bool Whether the data has the key. |
| 2457 | 2458 | */ |
| 2458 | 2459 | #[ReturnTypeWillChange] |
| 2459 | - public function offsetExists( $key ) { | |
| 2460 | - return \array_key_exists( $key, $this->data ); | |
| 2460 | + public function offsetExists( $offset ) { | |
| 2461 | + return \array_key_exists( $offset, $this->data ); | |
| 2461 | 2462 | } |
| 2462 | 2463 | |
| 2463 | 2464 | /** |
| 2464 | 2465 | * Retrieves the value of the key. |
| 2465 | 2466 | * |
| 2466 | - * @param mixed $key Key. | |
| 2467 | + * @param mixed $offset Key. | |
| 2467 | 2468 | * |
| 2468 | 2469 | * @return array|mixed|null The value. |
| 2469 | 2470 | */ |
| 2470 | 2471 | #[ReturnTypeWillChange] |
| 2471 | - public function offsetGet( $key ) { | |
| 2472 | - return $this->get( $key ); | |
| 2472 | + public function offsetGet( $offset ) { | |
| 2473 | + return $this->get( $offset ); | |
| 2473 | 2474 | } |
| 2474 | 2475 | |
| 2475 | 2476 | /** |
| 2476 | 2477 | * Sets the value of the key. |
| 2477 | 2478 | * |
| 2478 | - * @param string|int $key Key. | |
| 2479 | - * @param mixed $value Value. | |
| 2479 | + * @param string|int $offset Key. | |
| 2480 | + * @param mixed $value Value. | |
| 2481 | + * | |
| 2482 | + * @return void | |
| 2480 | 2483 | */ |
| 2481 | 2484 | #[ReturnTypeWillChange] |
| 2482 | - public function offsetSet( $key, $value ) { | |
| 2483 | - if ( \is_null( $key ) ) { | |
| 2485 | + public function offsetSet( $offset, $value ) { | |
| 2486 | + if ( $offset === null ) { | |
| 2484 | 2487 | return; |
| 2485 | 2488 | } |
| 2486 | - $this->set( $key, $value ); | |
| 2489 | + $this->set( $offset, $value ); | |
| 2487 | 2490 | } |
| 2488 | 2491 | |
| 2489 | 2492 | /** |
| 2490 | 2493 | * Removes the given key from the data. |
| 2491 | 2494 | * |
| 2492 | - * @param mixed $key Key. | |
| 2495 | + * @param mixed $offset Key. | |
| 2496 | + * | |
| 2497 | + * @return void | |
| 2493 | 2498 | */ |
| 2494 | 2499 | #[ReturnTypeWillChange] |
| 2495 | - public function offsetUnset( $key ) { | |
| 2496 | - unset( $this->data[ $key ] ); | |
| 2497 | - unset( $this->dirty_fields[ $key ] ); | |
| 2500 | + public function offsetUnset( $offset ) { | |
| 2501 | + unset( $this->data[ $offset ] ); | |
| 2502 | + unset( $this->dirty_fields[ $offset ] ); | |
| 2498 | 2503 | } |
| 2499 | 2504 | |
| 2500 | 2505 | /* |
| 2501 | 2506 | * --- MAGIC METHODS --- |
| @@ -2516,8 +2521,10 @@ | ||
| 2516 | 2521 | * Handles magic set via offset. |
| 2517 | 2522 | * |
| 2518 | 2523 | * @param string|int $key Key. |
| 2519 | 2524 | * @param mixed $value Value. |
| 2525 | + * | |
| 2526 | + * @return void | |
| 2520 | 2527 | */ |
| 2521 | 2528 | public function __set( $key, $value ) { |
| 2522 | 2529 | $this->offsetSet( $key, $value ); |
| 2523 | 2530 | } |
| @@ -2525,8 +2532,10 @@ | ||
| 2525 | 2532 | /** |
| 2526 | 2533 | * Handles magic unset via offset. |
| 2527 | 2534 | * |
| 2528 | 2535 | * @param mixed $key Key. |
| 2536 | + * | |
| 2537 | + * @return void | |
| 2529 | 2538 | */ |
| 2530 | 2539 | public function __unset( $key ) { |
| 2531 | 2540 | $this->offsetUnset( $key ); |
| 2532 | 2541 | } |