diff --git a/README.md b/README.md index 16b215e22..369218eaf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Yii -

Yii ActiveRecord Library

+

Yii ActiveRecord


diff --git a/docs/create-model.md b/docs/create-model.md index 76f9ffd68..67889f320 100644 --- a/docs/create-model.md +++ b/docs/create-model.md @@ -7,7 +7,8 @@ class properties, the table name and relations. ### Dynamic properties -Easiest way to define properties is to use dynamic properties. This way you don't need to define properties explicitly. +The easiest way to define properties is to use dynamic properties. +This way you don't need to define properties explicitly. ```php use Yiisoft\ActiveRecord\ActiveRecord; @@ -20,7 +21,7 @@ use Yiisoft\ActiveRecord\ActiveRecord; * @property string $email * * The properties in PHPDoc are optional and used by static analysis and by IDEs for autocompletion, type hinting, - * code generation and inspection tools. This does not affect code execution. + * code generation, and inspection tools. This doesn't affect code execution. **/ #[\AllowDynamicProperties] final class User extends ActiveRecord @@ -45,8 +46,8 @@ $user->save(); Notes: - It needs to use the `#[\AllowDynamicProperties]` attribute to enable dynamic properties; -- ❌ It does not use strict typing and can be a reason of hard-to-detect errors; -- ❌ It is slower than explicitly defined properties, it is not optimized by PHP opcache and uses more memory; +- ❌ It doesn't use strict typing and can be a reason of hard-to-detect errors; +- ❌ It is slower than explicitly defined properties, it isn't optimized by PHP opcache and uses more memory; ### Public properties @@ -75,7 +76,7 @@ final class User extends ActiveRecord As with dynamic properties, you can use `$user->id`, `$user->username`, `$user->email` to access the properties. Notes: -- ✔️ It allows to use strict typing and define default values for properties; +- ✔️ It allows using strict typing and define default values for properties; - ✔️ It works faster than dynamic properties, optimized by PHP opcache and uses less memory; ### Protected properties (recommended) @@ -145,9 +146,9 @@ $user->save(); Notes: - To access properties, you need to define getter and setter methods. -- ✔️ It allows to use strict typing and define default values for properties; -- ✔️ It allows to access uninitialized properties, using **null coalescing operator** `return $this->id ?? null;` -- ✔️ It allows to reset relations when setting the property, using `ActiveRecordInterface::setAttribute()` method. +- ✔️ It allows using strict typing and define default values for properties; +- ✔️ It allows accessing uninitialized properties, using **null coalescing operator** `return $this->id ?? null;` +- ✔️ It allows resetting relations when setting the property, using `ActiveRecordInterface::setAttribute()` method. ### Private properties @@ -206,7 +207,7 @@ use Yiisoft\ActiveRecord\Trait\MagicPropertiesTrait; * @property string $email * * The properties in PHPDoc are optional and used by static analysis and by IDEs for autocompletion, type hinting, - * code generation and inspection tools. This does not affect code execution. + * code generation, and inspection tools. This doesn't affect code execution. **/ final class User extends ActiveRecord { @@ -223,11 +224,11 @@ You can use `$user->id`, `$user->username`, `$user->email` to access the propert Notes: - It needs to use the `MagicPropertiesTrait` to enable magic properties; -- Compared to dynamic properties, they are stored in the `private array $attributes` property; -- ✔️ It allows to access relations as properties; -- ❌ It does not use strict typing and can be a reason of hard-to-detect errors; +- Compared to dynamic properties, they're stored in the `private array $attributes` property; +- ✔️ It allows accessing relations as properties; +- ❌ It doesn't use strict typing and can be a reason of hard-to-detect errors; - ❌ It is slower than explicitly defined properties, it is not optimized by PHP opcache and uses more memory. - In some cases it can be 100 times slower than explicitly defined properties; + Sometimes it can be 100 times slower than explicitly defined properties; ## Relations diff --git a/docs/define-connection.md b/docs/define-connection.md index 60a8243d2..191bf08b7 100644 --- a/docs/define-connection.md +++ b/docs/define-connection.md @@ -1,10 +1,10 @@ -# Define the DB connection for Active Record +# Define the database connection for Active Record To use the Active Record, you need to define the DB connection in one of the following ways: ## Using the bootstrap configuration -Add the following code to the configuration file, for example in `config/common/bootstrap.php`: +Add the following code to the configuration file, for example, in `config/common/bootstrap.php`: ```php use Psr\Container\ContainerInterface; diff --git a/docs/define-relations.md b/docs/define-relations.md index 9c57f3031..76247947b 100644 --- a/docs/define-relations.md +++ b/docs/define-relations.md @@ -151,8 +151,8 @@ $this->hasOne(User::class, ['id' => 'user_id']); ### Many-to-many -The relationships are used when you need to link multiple records from one table to multiple records from another table. -This is common in scenarios where entities have a bidirectional relationship, such as users belonging to multiple groups +Use relationships when you need to link multiple records from one table to multiple records from another table. +This is common when entities have a bidirectional relationship, such as users belonging to multiple groups and groups having multiple users. ```mermaid @@ -348,8 +348,8 @@ Use this method when you don't need to store additional information in the junct ## Inverse Relations -An inverse relation is a relation that is defined in the related record to link back to the current record. It is used -to associate the related record(s) with the current record in a more efficient way by avoiding additional queries. +An inverse relation is a relation defined in the related record to link back to the current record. +It associates the related record(s) with the current record in a more efficient way by avoiding additional queries. To define an inverse relation, use the `ActiveQueryInterface::inverseOf()` method. @@ -393,8 +393,8 @@ final class Order extends ActiveRecord ## Eager Loading -**Relations are loaded lazily**, meaning that the related record(s) are not loaded until you access them. This allows -you to load only the data you need and avoid unnecessary queries. +**Relations are loaded lazily**, meaning that the related record(s) aren't loaded until you access them. +This allows you to load only the data you need and avoid unnecessary queries. However, there are cases when you need to load the related record(s) in advance to avoid the **N+1 query problem**. To do this, use the `ActiveQueryInterface::with()` method. diff --git a/docs/internals.md b/docs/internals.md index ef1f94b4a..a3621f962 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,6 +1,6 @@ # Internals -This package can be tested globally or individually for each DBMS. +You can test this package either globally or individually for each DBMS. - [MSSQL](https://github.com/yiisoft/db-mssql) - [MySQL/MariaDB](https://github.com/yiisoft/db-mysql) @@ -10,13 +10,14 @@ This package can be tested globally or individually for each DBMS. ## GitHub actions -All our packages have GitHub actions by default, so you can test your [contribution](https://github.com/yiisoft/db/blob/master/.github/CONTRIBUTING.md) in the cloud. +All packages have GitHub actions by default, so you can test your [contribution](https://github.com/yiisoft/db/blob/master/.github/CONTRIBUTING.md) in the cloud. > Note: We recommend pull requesting in draft mode until all tests pass. ## Docker images -For greater ease we recommend to use Docker container for each DBMS. For this you can use the [docker-compose.yml](https://docs.docker.com/compose/compose-file/) file that's in the root directory of each package. +For greater ease, we recommend to use Docker container for each DBMS. +For this, you can use the [docker-compose.yml](https://docs.docker.com/compose/compose-file/) file in the root directory of each package. - [MSSQL 2022](https://github.com/yiisoft/db-mssql/blob/master/docker-compose.yml) - [MySQL 8](https://github.com/yiisoft/db-mysql/blob/master/docker-compose.yml) @@ -24,7 +25,7 @@ For greater ease we recommend to use Docker container for each DBMS. For this yo - [Oracle 21](https://github.com/yiisoft/db-oracle/blob/master/docker-compose.yml) - [PostgreSQL 15](https://github.com/yiisoft/db-pgsql/blob/master/docker-compose.yml) -To run Docker containers you can use the following command: +To run Docker containers, you can use the following command: ```shell docker compose up -d @@ -32,37 +33,37 @@ docker compose up -d ### Global testing -The following steps are required to run tests. +To run tests, follow these steps. 1. Install all DBMS dependencies with composer. -```shell -composer require --dev yiisoft/db-mssql yiisoft/db-mysql yiisoft/db-oracle yiisoft/db-pgsql yiisoft/db-sqlite --ansi -``` + ```shell + composer require --dev yiisoft/db-mssql yiisoft/db-mysql yiisoft/db-oracle yiisoft/db-pgsql yiisoft/db-sqlite --ansi + ``` 2. Run all Docker containers for each DBMS. 3. Run the tests. -```shell -vendor/bin/phpunit -``` + ```shell + vendor/bin/phpunit + ``` ### Individual testing -The following steps are required to run tests. +To run tests, follow these steps. 1. Install DBMS dependencies with Composer. -```shell -composer require --dev yiisoft/db-pgsql --ansi -``` + ```shell + composer require --dev yiisoft/db-pgsql --ansi + ``` 2. Run the Docker container for the DBMS you want to test. 3. Run the tests. -```shell -vendor/bin/phpunit --testsuite=Pgsql -``` + ```shell + vendor/bin/phpunit --testsuite=Pgsql + ``` Suites available: diff --git a/docs/using-di.md b/docs/using-di.md index d5b257de2..710f60e58 100644 --- a/docs/using-di.md +++ b/docs/using-di.md @@ -1,6 +1,6 @@ # Using Dependency Injection With Active Record -Using [dependency injection](https://github.com/yiisoft/di) in the Active Record model allows to inject dependencies +Using [dependency injection](https://github.com/yiisoft/di) in the Active Record model allows injecting dependencies into the model and use them in the model methods. To create an Active Record model with dependency injection, you need to use @@ -62,7 +62,7 @@ final class User extends ActiveRecord } ``` -This will allow to create the `ActiveQuery` instance without calling `ActiveRecord::withFactory()` method. +This will allow creating the `ActiveQuery` instance without calling `ActiveRecord::withFactory()` method. ```php $userQuery = new ActiveQuery($factory->create(User::class)); diff --git a/src/AbstractActiveRecord.php b/src/AbstractActiveRecord.php index d6e1aabd5..8e8bc9202 100644 --- a/src/AbstractActiveRecord.php +++ b/src/AbstractActiveRecord.php @@ -68,7 +68,7 @@ abstract protected function getAttributesInternal(): array; * @throws InvalidConfigException * @throws Throwable * - * @return bool Whether the record is inserted successfully. + * @return bool Whether the record inserted successfully. */ abstract protected function insertInternal(array $attributes = null): bool; @@ -127,7 +127,7 @@ public function getIsNewRecord(): bool * * @param string $name The attribute name. * - * @return mixed the old attribute value. `null` if the attribute is not loaded before or does not exist. + * @return mixed The old attribute value. `null` if the attribute is not loaded before or doesn't exist. * * {@see hasAttribute()} */ @@ -137,11 +137,11 @@ public function getOldAttribute(string $name): mixed } /** - * Returns the attribute values that have been modified since they are loaded or saved most recently. + * Returns the attribute values that have been modified since they're loaded or saved most recently. * - * The comparison of new and old values is made for identical values using `===`. + * The comparison of new and old values uses `===`. * - * @param array|null $names The names of the attributes whose values may be returned if they are changed recently. + * @param array|null $names The names of the attributes whose values may be returned if they're changed recently. * If null, {@see attributes()} will be used. * * @return array The changed attribute values (name-value pairs). @@ -235,13 +235,13 @@ public function hasAttribute(string $name): bool /** * Declares a `has-many` relation. * - * The declaration is returned in terms of a relational {@see ActiveQuery} instance through which the related + * The declaration is returned in terms of a relational {@see ActiveQuery} instance through which the related * record can be queried and retrieved back. * * A `has-many` relation means that there are multiple related records matching the criteria set by this relation, * e.g., a customer has many orders. * - * For example, to declare the `orders` relation for `Customer` class, we can write the following code in the + * For example, to declare the `orders` relation for `Customer` class, you can write the following code in the * `Customer` class: * * ```php @@ -251,16 +251,16 @@ public function hasAttribute(string $name): bool * } * ``` * - * Note that in the above, the 'customer_id' key in the `$link` parameter refers to an attribute name in the related + * Note that the `customer_id` key in the `$link` parameter refers to an attribute name in the related * class `Order`, while the 'id' value refers to an attribute name in the current AR class. * * Call methods declared in {@see ActiveQuery} to further customize the relation. * - * @param ActiveRecordInterface|Closure|string $class The class name of the related record, or an instance of the - * related record, or a Closure to create an {@see ActiveRecordInterface} object. - * @param array $link The primary-foreign key constraint. The keys of the array refer to the attributes of the - * record associated with the `$class` model, while the values of the array refer to the corresponding attributes in - * **this** AR class. + * @param ActiveRecordInterface|Closure|string $class The class name of the related record, or an instance of + * the related record, or a Closure to create an {@see ActiveRecordInterface} object. + * @param array $link The primary-foreign key constraint. The keys of the array refer to the attributes of + * the record associated with the `$class` model, while the values of the array refer to the corresponding attributes + * in **this** AR class. * * @return ActiveQueryInterface The relational query object. * @@ -280,7 +280,7 @@ public function hasMany(string|ActiveRecordInterface|Closure $class, array $link * A `has-one` relation means that there is at most one related record matching the criteria set by this relation, * e.g., a customer has one country. * - * For example, to declare the `country` relation for `Customer` class, we can write the following code in the + * For example, to declare the `country` relation for `Customer` class, you can write the following code in the * `Customer` class: * * ```php @@ -290,15 +290,15 @@ public function hasMany(string|ActiveRecordInterface|Closure $class, array $link * } * ``` * - * Note that in the above, the 'id' key in the `$link` parameter refers to an attribute name in the related class - * `Country`, while the 'country_id' value refers to an attribute name in the current AR class. + * Note that the `id` key in the `$link` parameter refers to an attribute name in the related class + * `Country`, while the `country_id` value refers to an attribute name in the current AR class. * * Call methods declared in {@see ActiveQuery} to further customize the relation. * - * @param ActiveRecordInterface|Closure|string $class The class name of the related record, or an instance of the - * related record, or a Closure to create an {@see ActiveRecordInterface} object. - * @param array $link The primary-foreign key constraint. The keys of the array refer to the attributes of the - * record associated with the `$class` model, while the values of the array refer to the corresponding attributes in + * @param ActiveRecordInterface|Closure|string $class The class name of the related record, or an instance of + * the related record, or a Closure to create an {@see ActiveRecordInterface} object. + * @param array $link The primary-foreign key constraint. The keys of the array refer to the attributes of + * the record associated with the `$class` model, while the values of the array refer to the corresponding attributes in * **this** AR class. * * @return ActiveQueryInterface The relational query object. @@ -316,8 +316,8 @@ public function insert(array $attributes = null): bool } /** - * @param ActiveRecordInterface|Closure|string $arClass The class name of the related record, or an instance of the - * related record, or a Closure to create an {@see ActiveRecordInterface} object. + * @param ActiveRecordInterface|Closure|string $arClass The class name of the related record, or an instance of + * the related record, or a Closure to create an {@see ActiveRecordInterface} object. * * @psalm-param ARClass $arClass */ @@ -327,11 +327,11 @@ public function instantiateQuery(string|ActiveRecordInterface|Closure $arClass): } /** - * Returns a value indicating whether the named attribute has been changed. + * Returns whether the named attribute has been changed. * * @param string $name The name of the attribute. - * @param bool $identical Whether the comparison of new and old value is made for identical values using `===`, - * defaults to `true`. Otherwise `==` is used for comparison. + * @param bool $identical Whether the comparison of new and old value uses `===`, + * defaults to `true`. Otherwise, `==` is used for comparison. * * @return bool Whether the attribute has been changed. */ @@ -459,7 +459,7 @@ public function link(string $name, ActiveRecordInterface $arClass, array $extraC } } - // update lazily loaded related objects + // Update lazily loaded related objects. if (!$relation->getMultiple()) { $this->related[$name] = $arClass; } elseif (isset($this->related[$name])) { @@ -511,7 +511,7 @@ public function markAttributeDirty(string $name): void * 2. In the Web form that collects the user input, add a hidden field that stores the lock version of the recording * being updated. * 3. In the controller action that does the data updating, try to catch the {@see StaleObjectException} and - * implement necessary business logic (e.g. merging the changes, prompting stated data) to resolve the conflict. + * implement necessary business logic (e.g., merging the changes, prompting stated data) to resolve the conflict. * * @return string|null The column name that stores the lock version of a table row. If `null` is returned (default * implemented), optimistic locking will not be supported. @@ -621,7 +621,7 @@ protected function retrieveRelation(string $name): ActiveRecordInterface|array|n * @throws StaleObjectException * @throws Throwable * - * @return bool Whether the saving succeeded (i.e. no validation errors occurred). + * @return bool Whether the saving succeeded (i.e., no validation errors occurred). */ public function save(array $attributeNames = null): bool { @@ -666,7 +666,7 @@ public function setAttributes(array $values): void /** * Sets the value indicating whether the record is new. * - * @param bool $value whether the record is new and should be inserted when calling {@see save()}. + * @param bool $value Whether the record is new and should be inserted when calling {@see save()}. * * @see getIsNewRecord() */ @@ -680,7 +680,7 @@ public function setIsNewRecord(bool $value): void * * @param string $name The attribute name. * - * @throws InvalidArgumentException If the named attribute does not exist. + * @throws InvalidArgumentException If the named attribute doesn't exist. * * {@see hasAttribute()} */ @@ -698,8 +698,7 @@ public function setOldAttribute(string $name, mixed $value): void * * All existing old attribute values will be discarded. * - * @param array|null $values Old attribute values to be set. If set to `null` this record is considered to be - * {@see isNewRecord|new}. + * @param array|null $values Old attribute values to be set. If set to `null` this record is {@see isNewRecord|new}. */ public function setOldAttributes(array $values = null): void { @@ -747,9 +746,9 @@ public function updateAttributes(array $attributes): int } /** - * Updates the whole table using the provided counter changes and conditions. + * Updates the whole table using the provided counters and condition. * - * For example, to increment all customers' age by 1, + * For example, to increment all customers' age by 1: * * ```php * $customer = new Customer($db); @@ -760,8 +759,8 @@ public function updateAttributes(array $attributes): int * * @param array $counters The counters to be updated (attribute name => increment value). * Use negative values if you want to decrement the counters. - * @param array|string $condition The conditions that will be put in the WHERE part of the UPDATE SQL. Please refer - * to {@see Query::where()} on how to specify this parameter. + * @param array|string $condition The conditions that will be put in the `WHERE` part of the `UPDATE` SQL. + * Please refer to {@see Query::where()} on how to specify this parameter. * @param array $params The parameters (name => value) to be bound to the query. * * Do not name the parameters as `:bp0`, `:bp1`, etc., because they are used internally by this method. @@ -789,7 +788,7 @@ public function updateAllCounters(array $counters, array|string $condition = '', } /** - * Updates one or several counter columns for the current AR object. + * Updates one or several counters for the current AR object. * * Note that this method differs from {@see updateAllCounters()} in that it only saves counters for the current AR * object. @@ -929,14 +928,14 @@ public function unlink(string $name, ActiveRecordInterface $arClass, bool $delet } /** - * Destroys the relationship in current model. + * Destroys the relationship in the current model. * * The active record with the foreign key of the relationship will be deleted if `$delete` is `true`. Otherwise, the * foreign key will be set `null` and the model will be saved without validation. * - * Note that to destroy the relationship without removing records make sure your keys can be set to null. + * To destroy the relationship without removing records, make sure your keys can be set to `null`. * - * @param string $name The case sensitive name of the relationship, e.g. `orders` for a relation defined via + * @param string $name The case-sensitive name of the relationship, e.g., `orders` for a relation defined via * `getOrders()` method. * @param bool $delete Whether to delete the model that contains the foreign key. * @@ -1038,9 +1037,9 @@ public function unlinkAll(string $name, bool $delete = false): void /** * Sets relation dependencies for a property. * - * @param string $name property name. - * @param ActiveQueryInterface $relation relation instance. - * @param string|null $viaRelationName intermediate relation. + * @param string $name Property name. + * @param ActiveQueryInterface $relation Relation instance. + * @param string|null $viaRelationName Intermediate relation. */ protected function setRelationDependencies( string $name, @@ -1099,7 +1098,7 @@ protected function createRelationQuery(string|ActiveRecordInterface|Closure $arC protected function deleteInternal(): int { /** - * We do not check the return value of deleteAll() because it's possible the record is already deleted in + * We don't check the return value of deleteAll() because it is possible the record is already deleted in * the database and thus the method will return 0 */ $condition = $this->getOldPrimaryKey(true); @@ -1209,7 +1208,7 @@ private function bindModels( } /** - * relation via array valued attribute + * Relation via array valued attribute. */ if (is_array($fkValue = $foreignModel->getAttribute($fk))) { /** @psalm-var mixed */ diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 453a857f2..692ad3b66 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -86,7 +86,7 @@ * Relational query * ---------------- * - * In relational context ActiveQuery represents a relation between two Active Record classes. + * In relational context, ActiveQuery represents a relation between two Active Record classes. * * Relational ActiveQuery instances are usually created by calling {@see ActiveRecord::hasOne()} and * {@see ActiveRecord::hasMany()}. An Active Record class declares a relation by defining a getter method which calls @@ -97,8 +97,8 @@ * * If a relation involves a junction table, it may be specified by {@see via()} or {@see viaTable()} method. * - * These methods may only be called in a relational context. Same is true for {@see inverseOf()}, which marks a relation - * as inverse of another relation and {@see onCondition()} which adds a condition that's to be added to relational + * These methods may only be called in a relational context. The same is true for {@see inverseOf()}, which marks a relation + * as inverse of another relation and {@see onCondition()} which adds a condition that is to be added to relational * query join condition. * * @psalm-import-type ARClass from ActiveQueryInterface @@ -156,7 +156,7 @@ public function prepare(QueryBuilderInterface $builder): QueryInterface { /** * NOTE: Because the same ActiveQuery may be used to build different SQL statements, one for count query, the - * other for row data query, it's important to make sure the same ActiveQuery can be used to build SQL + * other for row data query, it is important to make sure the same ActiveQuery can be used to build SQL * statements many times. */ if (!empty($this->joinWith)) { diff --git a/src/ActiveQueryInterface.php b/src/ActiveQueryInterface.php index 55ba0cff2..c880e27ad 100644 --- a/src/ActiveQueryInterface.php +++ b/src/ActiveQueryInterface.php @@ -16,7 +16,7 @@ use Yiisoft\Definitions\Exception\NotInstantiableException; /** - * Defines the common interface to be implemented by active record query classes. + * A common interface to be implemented by active record query classes. * * That are methods for all normal queries that return active records but also relational queries in which the query * represents a relation between two active record classes and will return related records only. @@ -107,7 +107,7 @@ public function via(string $relationName, callable $callable = null): self; * @return array|string|null the join condition to be used when this query is used in a relational context. * * The condition will be used in the ON part when {@see joinWith()} is called. Otherwise, the condition will be used - * in the WHERE part of a query. + * in the `WHERE` part of a query. * * Please refer to {@see Query::where()} on how to specify this parameter. * @@ -125,16 +125,16 @@ public function buildJoinWith(): void; /** * Joins with the specified relations. * - * This method allows you to reuse existing relation definitions to perform JOIN queries. Based on the definition of - * the specified relation(s), the method will append one or many JOIN statements to the current query. + * This method allows you to reuse existing relation definitions to perform `JOIN` queries. Based on the definition of + * the specified relation(s), the method will append one or many `JOIN` statements to the current query. * * If the `$eagerLoading` parameter is true, the method will also perform eager loading for the specified relations, * which is equal to calling {@see with()} using the specified relations. * - * Note: That because a JOIN query will be performed, you're responsible for disambiguated column names. + * Note: That because a `JOIN` query will be performed, you're responsible for disambiguated column names. * - * This method differs from {@see with()} in that it will build up and execute a JOIN SQL statement for the primary - * table. And when `$eagerLoading` is true, it will call {@see with()} in addition with the specified relations. + * This method differs from {@see with()} in that it will build up and execute a `JOIN` SQL statement for the primary + * table. And when `$eagerLoading` is true, it will call {@see with()} also with the specified relations. * * @param array|string $with The relations to be joined. This can either be a string, representing a relation name * or an array with the following semantics: @@ -144,18 +144,18 @@ public function buildJoinWith(): void; * relation queries on-the-fly as the array value. * - If a relation query doesn't need modification, you may use the relation name as the array value. * - * The relation name may optionally contain an alias for the relation table (e.g. `books b`). + * The relation name may optionally contain an alias for the relation table (for example, `books b`). * * Sub-relations can also be specified, see {@see with()} for the syntax. * - * In the following you find some examples: + * In the following, you find some examples: * * ```php * // Find all orders that contain books, and eager loading "books". * $orderQuery = new ActiveQuery(Order::class); * $orderQuery->joinWith('books', true, 'INNER JOIN')->all(); * - * // find all orders, eager loading "books", and sort the orders and books by the book names. + * // Find all orders, eagerly load "books", and sort the orders and books by the book names. * $orderQuery = new ActiveQuery(Order::class, $db); * $orderQuery->joinWith([ * 'books' => function (ActiveQuery $query) { @@ -170,7 +170,7 @@ public function buildJoinWith(): void; * @param array|bool $eagerLoading Whether to eager load the relations specified in `$with`. When this is boolean. * It applies to all relations specified in `$with`. Use an array to explicitly list which relations in `$with` a * need to be eagerly loaded. - * Note: That this doesn't mean that the relations are populated from the query result. An + * Note: This doesn't mean that the relations are populated from the query result. An * extra query will still be performed to bring in the related data. Defaults to `true`. * @param array|string $joinType The join type of the relations specified in `$with`. When this is a string, it * applies to all relations specified in `$with`. Use an array in the format of `relationName => joinType` to @@ -205,7 +205,7 @@ public function innerJoinWith(array|string $with, array|bool $eagerLoading = tru * * The condition will be used in the ON part when {@see joinWith()} is called. * - * Otherwise, the condition will be used in the WHERE part of a query. + * Otherwise, the condition will be used in the `WHERE` part of a query. * * Use this method to specify more conditions when declaring a relation in the {@see ActiveRecord} class: * @@ -229,9 +229,9 @@ public function onCondition(array|string $condition, array $params = []): self; /** * Adds ON condition to the existing one. * - * The new condition and the existing one will be joined using the 'AND' operator. + * The new condition and the existing one will be joined using the `AND` operator. * - * @param array|string $condition The new ON condition. + * @param array|string $condition The new `ON` condition. * Please refer to {@see where()} on how to specify this parameter. * @param array $params the parameters (name => value) to be bound to the query. * @@ -243,9 +243,9 @@ public function andOnCondition(array|string $condition, array $params = []): sel /** * Adds ON condition to the existing one. * - * The new condition and the existing one will be joined using the 'OR' operator. + * The new condition and the existing one will be joined using the `OR` operator. * - * @param array|string $condition The new ON condition. + * @param array|string $condition The new `ON` condition. * Please refer to {@see where()} on how to specify this parameter. * @param array $params The parameters (name => value) to be bound to the query. * @@ -295,7 +295,7 @@ public function alias(string $alias): self; /** * Returns table names used in {@see from} indexed by aliases. * - * Both aliases and names are enclosed into {{ and }}. + * Both aliases and names are enclosed into `{{` and `}}`. * * @throws CircularReferenceException * @throws InvalidArgumentException @@ -439,7 +439,7 @@ public function relatedRecords(): ActiveRecordInterface|array|null; * $query = $aqClass->findOne(['id' => $id); * ``` * - * Do NOT use the following code!, it's possible to inject an array condition to filter by arbitrary column values!: + * Do NOT use the following code!, it is possible to inject an array condition to filter by arbitrary column values!: * * ```php * $aqClass = new ActiveQuery(Post::class, $db); @@ -460,7 +460,7 @@ public function findOne(mixed $condition): array|ActiveRecordInterface|null; * - A scalar value (integer or string): query by a single primary key value and return an array containing the * corresponding record (or an empty array if not found). * - A non-associative array: query by a list of primary key values and return the corresponding records (or an - * empty array if none was found). + * empty array if none found). * Note that an empty condition will result in an empty result as it will be interpreted as a search for * primary keys and not an empty `WHERE` condition. * - An associative array of name-value pairs: query by a set of attribute values and return an array of records @@ -579,7 +579,7 @@ public function getVia(): array|self|null; * The array keys must be columns of the table for this relation, and the array values must be the corresponding * columns from the primary table. * - * Do not prefix or quote the column names as this will be done automatically by Yii. This property is only used in + * Don't prefix or quote the column names. Yii does that automatically. This property is only used in * relational context. * * @psalm-return string[] diff --git a/src/ActiveQueryTrait.php b/src/ActiveQueryTrait.php index 5fcc76f89..2112b1858 100644 --- a/src/ActiveQueryTrait.php +++ b/src/ActiveQueryTrait.php @@ -24,9 +24,9 @@ trait ActiveQueryTrait /** * Sets the {@see asArray} property. * - * @param bool $value whether to return the query results in terms of arrays instead of Active Records. + * @param bool $value Whether to return the query results in terms of arrays instead of Active Records. * - * @return static the query object itself. + * @return static The query object itself. */ public function asArray(bool|null $value = true): static { @@ -73,9 +73,9 @@ public function asArray(bool|null $value = true): static * CustomerQuery->with('orders')->with('country')->all(); * ``` * - * @param array|string ...$with a list of relation names or relation definitions. + * @param array|string ...$with A list of relation names or relation definitions. * - * @return static the query object itself. + * @return static The query object itself. */ public function with(array|string ...$with): static { @@ -153,7 +153,7 @@ public function findWith(array $with, array &$models): void foreach ($relations as $name => $relation) { if ($relation->asArray === null) { - /** inherit asArray from primary query */ + /** inherit asArray from a primary query */ $relation->asArray($this->asArray); } diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index ec271a67e..e6f40bc05 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -41,7 +41,7 @@ * In this example, Active Record is providing an object-oriented interface for accessing data stored in the database. * But Active Record provides much more functionality than this. * - * To declare an ActiveRecord class you need to extend {@see ActiveRecord} and implement the `getTableName` method: + * To declare an ActiveRecord class, you need to extend {@see ActiveRecord} and implement the `getTableName` method: * * ```php * class Customer extends ActiveRecord @@ -65,7 +65,7 @@ * ```php * $user = new User($db); * $user->name = 'Qiang'; - * $user->save(); // a new row is inserted into user table + * $user->save(); // a new row is inserted into user table * * // the following will retrieve the user 'CeBe' from the database * $userQuery = new ActiveQuery(User::class); @@ -121,7 +121,7 @@ public function filterValidAliases(ActiveQuery $query): array * Returns the schema information of the DB table associated with this AR class. * * @throws Exception - * @throws InvalidConfigException If the table for the AR class does not exist. + * @throws InvalidConfigException If the table for the AR class doesn't exist. * * @return TableSchemaInterface The schema information of the DB table associated with this AR class. */ diff --git a/src/ActiveRecordInterface.php b/src/ActiveRecordInterface.php index 8b5a810ae..dcf087f78 100644 --- a/src/ActiveRecordInterface.php +++ b/src/ActiveRecordInterface.php @@ -72,7 +72,7 @@ public function delete(): int; * * For a large set of models you might consider using {@see ActiveQuery::each()} to keep memory usage within limits. * - * @param array $condition The conditions that will be put in the WHERE part of the DELETE SQL. Please refer to + * @param array $condition The conditions that will be put in the `WHERE` part of the `DELETE` SQL. Please refer to * {@see Query::where()} on how to specify this parameter. * * @throws Exception @@ -112,7 +112,7 @@ public function equals(self $record): bool; public function filterCondition(array $condition, array $aliases = []): array; /** - * Returns table aliases which aren't the same as the name of the tables. + * Returns table aliases which are different from the name of the tables. * * @throws InvalidArgumentException * @throws InvalidConfigException @@ -157,8 +157,8 @@ public function getIsNewRecord(): bool; /** * Returns the old primary key value(s). * - * This refers to the primary key value that's populated into the record after executing a find method (for example - * findOne()). + * This refers to the primary key value that's populated into the record after executing a find method (for example, + * `findOne()`). * * The value remains unchanged even if the primary key attribute is manually assigned with a different value. * @@ -261,7 +261,7 @@ public function isPrimaryKey(array $keys): bool; /** * Check whether the named relation has been populated with records. * - * @param string $name The relation name, for example `orders` for a relation defined via `getOrders()` method + * @param string $name The relation name, for example, `orders` for a relation defined via `getOrders()` method * (case-sensitive). * * @return bool Whether relation has been populated with records. @@ -283,7 +283,7 @@ public function isRelationPopulated(string $name): bool; * * This method requires that the primary key value isn't `null`. * - * @param string $name The case-sensitive name of the relationship, for example `orders` for a relation defined via + * @param string $name The case-sensitive name of the relationship, for example, `orders` for a relation defined via * `getOrders()` method. * @param self $arClass The record to be linked with the current one. * @param array $extraColumns More column values to be saved into the junction table. This parameter is only @@ -297,7 +297,7 @@ public function link(string $name, self $arClass, array $extraColumns = []): voi * * Note that this method doesn't check if the relation exists or not. * - * @param string $name The relation name, for example `orders` for a relation defined via `getOrders()` method + * @param string $name The relation name, for example, `orders` for a relation defined via `getOrders()` method * (case-sensitive). * @param array|self|null $records The related records to be populated into the relation. */ @@ -324,7 +324,7 @@ public function primaryKey(): array; /** * Returns the relation object with the specified name. * - * @param string $name The relation name, for example `orders` (case-sensitive). + * @param string $name The relation name, for example, `orders` (case-sensitive). * * @return ActiveRecordInterface|array|null The relation object. */ @@ -349,7 +349,7 @@ public function relation(string $name): self|array|null; * } * ``` * - * @param string $name The relation name, for example `orders` (case-sensitive). + * @param string $name The relation name, for example, `orders` (case-sensitive). * * @throws InvalidArgumentException * @@ -360,7 +360,7 @@ public function relationQuery(string $name): ActiveQueryInterface; /** * Resets relation data for the specified name. * - * @param string $name The relation name, for example `orders` (case-sensitive). + * @param string $name The relation name, for example, `orders` (case-sensitive). */ public function resetRelation(string $name): void; @@ -456,7 +456,7 @@ public function update(array $attributeNames = null): int; * For a large set of models you might consider using {@see ActiveQuery::each()} to keep memory usage within limits. * * @param array $attributes Attribute values (name-value pairs) to be saved into the table. - * @param array|string $condition The conditions that will be put in the WHERE part of the UPDATE SQL. + * @param array|string $condition The conditions that will be put in the `WHERE` part of the `UPDATE` SQL. * Please refer to {@see Query::where()} on how to specify this parameter. * @param array $params The parameters (name => value) to be bound to the query. * @@ -471,7 +471,7 @@ public function updateAll(array $attributes, array|string $condition = [], array /** * Updates the specified attributes. * - * This method is a shortcut to {@see update()} when data validation isn't needed and only a small set attributes + * This method is a shortcut to {@see update()} when data validation isn't necessary and only a small set attributes * need to be updated. * * You may specify the attributes to be updated as name list or name-value pairs. @@ -497,7 +497,7 @@ public function updateAttributes(array $attributes): int; * * Otherwise, the foreign key will be set `null` and the record will be saved without validation. * - * @param string $name The case-sensitive name of the relationship, for example `orders` for a relation defined via + * @param string $name The case-sensitive name of the relationship, for example, `orders` for a relation defined via * `getOrders()` method. * @param self $arClass The active record to be unlinked from the current one. * @param bool $delete Whether to delete the active record that contains the foreign key. diff --git a/src/ActiveRelationTrait.php b/src/ActiveRelationTrait.php index c46fdd054..12bf4bf83 100644 --- a/src/ActiveRelationTrait.php +++ b/src/ActiveRelationTrait.php @@ -52,7 +52,7 @@ trait ActiveRelationTrait * referenced through the specified relation. * * For example, `$customer->orders[0]->customer` and `$customer` will be the same object, and accessing the customer - * of an order will not trigger new DB query. + * of an order will not trigger a new DB query. * * This property is only used in relational context. * @@ -67,7 +67,7 @@ trait ActiveRelationTrait */ public function __clone() { - /** make a clone of "via" object so that the same query object can be reused multiple times */ + /** Make a clone of "via" object so that the same query object can be reused multiple times. */ if (is_object($this->via)) { $this->via = clone $this->via; } elseif (is_array($this->via)) { @@ -122,7 +122,7 @@ public function via(string $relationName, callable $callable = null): static * For example, `$customer->orders[0]->customer` and `$customer` will be the same object, and accessing the customer * of an order will not trigger a new DB query. * - * Use this method when declaring a relation in the {@see ActiveRecord} class, e.g. in Customer model: + * Use this method when declaring a relation in the {@see ActiveRecord} class, e.g., in the Customer model: * * ```php * public function getOrders() @@ -131,7 +131,7 @@ public function via(string $relationName, callable $callable = null): static * } * ``` * - * This also may be used for Order model, but with caution: + * This also may be used for the Order model, but with caution: * * ```php * public function getCustomer() @@ -171,7 +171,7 @@ public function inverseOf(string $relationName): static } /** - * Returns query records depends on {@see $multiple} . + * Returns query records depending on {@see $multiple} . * * This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion. * @@ -179,9 +179,9 @@ public function inverseOf(string $relationName): static * @throws InvalidArgumentException * @throws InvalidConfigException * @throws ReflectionException - * @throws Throwable if the relation is invalid. + * @throws Throwable If the relation is invalid. * - * @return ActiveRecordInterface|array|null the related record(s). + * @return ActiveRecordInterface|array|null The related record(s). */ public function relatedRecords(): ActiveRecordInterface|array|null { @@ -223,14 +223,14 @@ private function addInverseRelations(array &$result): void /** * Finds the related records and populates them into the primary models. * - * @param string $name the relation name - * @param array $primaryModels primary models + * @param string $name The relation name. + * @param array $primaryModels Primary models. * - * @throws InvalidArgumentException|InvalidConfigException|NotSupportedException|Throwable if {@see link()} is + * @throws InvalidArgumentException|InvalidConfigException|NotSupportedException|Throwable If {@see link()} is * invalid. * @throws Exception * - * @return array the related models + * @return array The related models. */ public function populateRelation(string $name, array &$primaryModels): array { @@ -242,7 +242,7 @@ public function populateRelation(string $name, array &$primaryModels): array [$viaName, $viaQuery] = $this->via; if ($viaQuery->asArray === null) { - /** inherit asArray from primary query */ + /** inherit asArray from a primary query */ $viaQuery->asArray($this->asArray); } @@ -271,7 +271,7 @@ public function populateRelation(string $name, array &$primaryModels): array /** * {@see https://github.com/yiisoft/yii2/issues/3197} * - * delay indexing related models after buckets are built. + * Delay indexing related models after buckets are built. */ $indexBy = $this->getIndexBy(); $this->indexBy(null); @@ -642,7 +642,7 @@ private function findJunctionRows(array $primaryModels): array $primaryModel = reset($primaryModels); if (!$primaryModel instanceof ActiveRecordInterface) { - /** when primaryModels are array of arrays (asArray case) */ + /** when primaryModels are an array of arrays (asArray case) */ $primaryModel = $this->arClass; } diff --git a/src/Trait/ArrayAccessTrait.php b/src/Trait/ArrayAccessTrait.php index 5f5a72060..0bf495960 100644 --- a/src/Trait/ArrayAccessTrait.php +++ b/src/Trait/ArrayAccessTrait.php @@ -44,9 +44,9 @@ trait ArrayAccessTrait * * It is implicitly called when you use something like `isset($model[$offset])`. * - * @param string $offset the offset to check on. + * @param string $offset The offset to check on. * - * @return bool whether or not an offset exists. + * @return bool Whether an offset exists. */ public function offsetExists(mixed $offset): bool { @@ -66,7 +66,7 @@ public function offsetExists(mixed $offset): bool } /** - * @param string $offset the offset to retrieve element. + * @param string $offset The offset to retrieve element. */ public function offsetGet(mixed $offset): mixed { @@ -88,7 +88,7 @@ public function offsetGet(mixed $offset): mixed * * It is implicitly called when you use something like `$model[$offset] = $item;`. * - * @param string $offset the offset to set element. + * @param string $offset The offset to set element. */ public function offsetSet(mixed $offset, mixed $value): void { @@ -117,7 +117,7 @@ public function offsetSet(mixed $offset, mixed $value): void * * It is implicitly called when you use something like `unset($model[$offset])`. * - * @param string $offset the offset to unset element + * @param string $offset The offset to unset element. */ public function offsetUnset(mixed $offset): void { diff --git a/src/Trait/MagicPropertiesTrait.php b/src/Trait/MagicPropertiesTrait.php index 85825aed0..62e7b26e8 100644 --- a/src/Trait/MagicPropertiesTrait.php +++ b/src/Trait/MagicPropertiesTrait.php @@ -58,13 +58,13 @@ trait MagicPropertiesTrait * * This method is overridden so that attributes and related objects can be accessed like properties. * - * @param string $name property name. + * @param string $name Property name. * * @throws InvalidArgumentException|InvalidCallException|InvalidConfigException|ReflectionException|Throwable * @throws UnknownPropertyException * * @throws Exception - * @return mixed property value. + * @return mixed Property value. * * {@see getAttribute()} */ @@ -79,12 +79,12 @@ public function __get(string $name) } if (method_exists($this, $getter = 'get' . ucfirst($name))) { - /** read getter, e.g. getName() */ + /** Read getter, e.g., getName() */ return $this->$getter(); } if (method_exists($this, 'get' . ucfirst($name) . 'Query')) { - /** read relation query getter, e.g. getUserQuery() */ + /** Read relation query getter, e.g., getUserQuery() */ return $this->retrieveRelation($name); } @@ -100,9 +100,9 @@ public function __get(string $name) * * This method overrides the parent implementation by checking if the named attribute is `null` or not. * - * @param string $name the property name or the event name. + * @param string $name The property name or the event name. * - * @return bool whether the property value is null. + * @return bool Whether the property value is null. */ public function __isset(string $name): bool { @@ -118,7 +118,7 @@ public function __isset(string $name): bool * * This method overrides the parent implementation by clearing the specified attribute value. * - * @param string $name the property name or the event name. + * @param string $name The property name or the event name. */ public function __unset(string $name): void { @@ -142,7 +142,7 @@ public function __unset(string $name): void * * This method is overridden so that AR attributes can be accessed like properties. * - * @param string $name property name. + * @param string $name Property name. * * @throws InvalidCallException|UnknownPropertyException */ @@ -191,10 +191,10 @@ public function setAttribute(string $name, mixed $value): void * case-insensitive). * - the class has a member variable with the specified name (when `$checkVars` is true). * - * @param string $name the property name. - * @param bool $checkVars whether to treat member variables as properties. + * @param string $name The property name. + * @param bool $checkVars Whether to treat member variables as properties. * - * @return bool whether the property is defined. + * @return bool Whether the property is defined. * * {@see canGetProperty()} * {@see canSetProperty()} diff --git a/src/Trait/MagicRelationsTrait.php b/src/Trait/MagicRelationsTrait.php index abc92f58b..8689b0695 100644 --- a/src/Trait/MagicRelationsTrait.php +++ b/src/Trait/MagicRelationsTrait.php @@ -41,7 +41,7 @@ trait MagicRelationsTrait * } * ``` * - * @throws InvalidArgumentException if the named relation does not exist. + * @throws InvalidArgumentException If the named relation doesn't exist. * @throws ReflectionException */ public function relationQuery(string $name): ActiveQueryInterface @@ -67,7 +67,7 @@ public function relationQuery(string $name): ActiveQueryInterface ); } - /** relation name is case sensitive, trying to validate it when the relation is defined within this class */ + /** Relation name is case-sensitive, trying to validate it when the relation is defined within this class. */ $realName = lcfirst(substr($method->getName(), 3, -5)); if ($realName !== $name) { diff --git a/src/TransactionalInterface.php b/src/TransactionalInterface.php index b5b7bf214..c779e988e 100644 --- a/src/TransactionalInterface.php +++ b/src/TransactionalInterface.php @@ -70,7 +70,7 @@ public function isTransactional(int $operation): bool; * The above declaration specifies that in the "admin" scenario, the insert operation ({@see insert()}) should be * done in a transaction; and in the "api" scenario, all the operations should be done in a transaction. * - * @return array The declarations of transactional operations. The array keys are scenarios names, and the array + * @return array The declarations of transactional operations. The array keys are scenario names, and the array * values are the corresponding transaction operations. */ public function transactions(): array; diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 72d3d402d..08fe0dedd 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -43,11 +43,11 @@ public function testOptions(): void $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->on(['a' => 'b'])->joinWith('profile'); - $this->assertEquals($query->getARClass(), Customer::class); - $this->assertEquals($query->getOn(), ['a' => 'b']); - $this->assertEquals($query->getJoinWith(), [[['profile'], true, 'LEFT JOIN']]); + $this->assertEquals(Customer::class, $query->getARClass()); + $this->assertEquals(['a' => 'b'], $query->getOn()); + $this->assertEquals([[['profile'], true, 'LEFT JOIN']], $query->getJoinWith()); $customerQuery->resetJoinWith(); - $this->assertEquals($query->getJoinWith(), []); + $this->assertEquals([], $query->getJoinWith()); } public function testPrepare(): void @@ -945,7 +945,7 @@ public function testJoinWithAlias(string $aliasMethod): void $relationName = 'books' . ucfirst($aliasMethod) . 'A'; $orderQuery = new ActiveQuery(Order::class); - $orders = $orderQuery->joinWith([(string)$relationName])->orderBy('order.id')->all(); + $orders = $orderQuery->joinWith([$relationName])->orderBy('order.id')->all(); $this->assertCount(3, $orders); $this->assertCount(2, $orders[0]->relation($relationName)); @@ -1795,7 +1795,7 @@ public static function filterTableNamesFromAliasesProvider(): array /** * @dataProvider filterTableNamesFromAliasesProvider * - * @param $expectedAliases + * @param array $expectedAliases * * @throws ReflectionException */ @@ -2054,11 +2054,11 @@ public function testBit(): void $bitValueQuery = new ActiveQuery(BitValues::class); $falseBit = $bitValueQuery->findOne(1); - $this->assertEquals(false, $falseBit->val); + $this->assertFalse($falseBit->val); $bitValueQuery = new ActiveQuery(BitValues::class); $trueBit = $bitValueQuery->findOne(2); - $this->assertEquals(true, $trueBit->val); + $this->assertTrue($trueBit->val); } public function testUpdateAttributes(): void diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 539e54b5d..c411abd04 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -165,7 +165,7 @@ public function testDefaultValues(): void $this->assertEquals('something', $arClass->char_col2); $this->assertEquals(1.23, $arClass->float_col2); $this->assertEquals(33.22, $arClass->numeric_col); - $this->assertEquals(true, $arClass->bool_col2); + $this->assertTrue($arClass->bool_col2); $this->assertEquals('2002-01-01 00:00:00', $arClass->time); $arClass = new Type(); @@ -675,7 +675,7 @@ public function testEquals(): void $this->assertFalse($customerA->equals($customerB)); } - public static function providerForUnlinkDelete() + public static function providerForUnlinkDelete(): array { return [ 'with delete' => [true, 0], @@ -688,7 +688,7 @@ public static function providerForUnlinkDelete() * * @see https://github.com/yiisoft/yii2/issues/17174 */ - public function testUnlinkWithViaOnCondition($delete, $count) + public function testUnlinkWithViaOnCondition($delete, $count): void { $this->checkFixture($this->db(), 'order', true); $this->checkFixture($this->db(), 'order_item_with_null_fk', true); @@ -714,7 +714,7 @@ public function testUnlinkWithViaOnCondition($delete, $count) ])); } - public function testVirtualRelation() + public function testVirtualRelation(): void { $this->checkFixture($this->db(), 'order', true); @@ -731,7 +731,7 @@ public function testVirtualRelation() * * @see https://github.com/yiisoft/yii2/issues/19507 */ - public function testJoinWithEager() + public function testJoinWithEager(): void { $this->checkFixture($this->db(), 'customer', true); @@ -1015,7 +1015,7 @@ public function testSerialization(): void ); } - public function testRelationViaJson() + public function testRelationViaJson(): void { if (in_array($this->db()->getDriverName(), ['oci', 'sqlsrv'], true)) { $this->markTestSkipped('Oracle and MSSQL drivers do not support JSON columns.'); @@ -1048,7 +1048,7 @@ public function testRelationViaJson() $this->assertSame([2, 3], ArArrayHelper::getColumn($promotions[2]->getItemsViaJson()[1]->getPromotionsViaJson(), 'id')); } - public function testLazzyRelationViaJson() + public function testLazzyRelationViaJson(): void { if (in_array($this->db()->getDriverName(), ['oci', 'sqlsrv'], true)) { $this->markTestSkipped('Oracle and MSSQL drivers do not support JSON columns.'); diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index fa49261f5..ca6d3a89e 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -20,7 +20,6 @@ public function testQuery(): void $result = $query->batch(2); - $this->assertInstanceOf(BatchQueryResultInterface::class, $result); $this->assertEquals(2, $result->getBatchSize()); $this->assertSame($result->getQuery(), $query); diff --git a/tests/Driver/Oracle/ActiveQueryTest.php b/tests/Driver/Oracle/ActiveQueryTest.php index fbfc7afdb..c3c3aa26c 100644 --- a/tests/Driver/Oracle/ActiveQueryTest.php +++ b/tests/Driver/Oracle/ActiveQueryTest.php @@ -190,7 +190,7 @@ public function testJoinWithAlias(string $aliasMethod): void $relationName = 'books' . ucfirst($aliasMethod) . 'A'; $orderQuery = new ActiveQuery(Order::class); - $orders = $orderQuery->joinWith([(string)$relationName])->orderBy('order.id')->all(); + $orders = $orderQuery->joinWith([$relationName])->orderBy('order.id')->all(); $this->assertCount(3, $orders); $this->assertCount(2, $orders[0]->relation($relationName)); diff --git a/tests/Driver/Pgsql/ActiveRecordTest.php b/tests/Driver/Pgsql/ActiveRecordTest.php index c67bc730d..101994460 100644 --- a/tests/Driver/Pgsql/ActiveRecordTest.php +++ b/tests/Driver/Pgsql/ActiveRecordTest.php @@ -49,7 +49,7 @@ public function testDefaultValues(): void $this->assertEquals('something', $arClass->char_col2); $this->assertEquals(1.23, $arClass->float_col2); $this->assertEquals(33.22, $arClass->numeric_col); - $this->assertEquals(true, $arClass->bool_col2); + $this->assertTrue($arClass->bool_col2); $this->assertEquals('2002-01-01 00:00:00', $arClass->time); $arClass = new Type(); @@ -397,7 +397,7 @@ public function testArrayValues($attributes): void $this->assertSame(1, $type->update(), 'The record got updated'); } - public function testRelationViaArray() + public function testRelationViaArray(): void { $this->checkFixture($this->db(), 'promotion'); @@ -426,7 +426,7 @@ public function testRelationViaArray() $this->assertSame([2, 3], ArArrayHelper::getColumn($promotions[2]->getItemsViaArray()[1]->getPromotionsViaArray(), 'id')); } - public function testLazzyRelationViaArray() + public function testLazzyRelationViaArray(): void { $this->checkFixture($this->db(), 'item'); diff --git a/tests/MagicActiveRecordTest.php b/tests/MagicActiveRecordTest.php index 924a04ada..d7fb24ac8 100644 --- a/tests/MagicActiveRecordTest.php +++ b/tests/MagicActiveRecordTest.php @@ -157,7 +157,7 @@ public function testDefaultValues(): void $this->assertEquals('something', $arClass->char_col2); $this->assertEquals(1.23, $arClass->float_col2); $this->assertEquals(33.22, $arClass->numeric_col); - $this->assertEquals(true, $arClass->bool_col2); + $this->assertTrue($arClass->bool_col2); $this->assertEquals('2002-01-01 00:00:00', $arClass->time); $arClass = new Type(); @@ -657,7 +657,7 @@ public function testEquals(): void $this->assertFalse($customerA->equals($customerB)); } - public static function providerForUnlinkDelete() + public static function providerForUnlinkDelete(): array { return [ 'with delete' => [true, 0], @@ -670,7 +670,7 @@ public static function providerForUnlinkDelete() * * @see https://github.com/yiisoft/yii2/issues/17174 */ - public function testUnlinkWithViaOnCondition($delete, $count) + public function testUnlinkWithViaOnCondition($delete, $count): void { $this->checkFixture($this->db(), 'order', true); $this->checkFixture($this->db(), 'order_item_with_null_fk', true); @@ -696,7 +696,7 @@ public function testUnlinkWithViaOnCondition($delete, $count) ])); } - public function testVirtualRelation() + public function testVirtualRelation(): void { $this->checkFixture($this->db(), 'order', true); @@ -713,7 +713,7 @@ public function testVirtualRelation() * * @see https://github.com/yiisoft/yii2/issues/19507 */ - public function testJoinWithEager() + public function testJoinWithEager(): void { $this->checkFixture($this->db(), 'customer', true); diff --git a/tests/Stubs/ActiveRecord/UnqueryableQueryMock.php b/tests/Stubs/ActiveRecord/UnqueryableQueryMock.php index 378e0289f..0f67cb8ab 100644 --- a/tests/Stubs/ActiveRecord/UnqueryableQueryMock.php +++ b/tests/Stubs/ActiveRecord/UnqueryableQueryMock.php @@ -9,7 +9,7 @@ final class UnqueryableQueryMock extends Query { - public function one(): mixed + public function one(): array|object|null { throw new InvalidCallException('Invalid call'); } diff --git a/tests/Stubs/MagicActiveRecord/UnqueryableQueryMock.php b/tests/Stubs/MagicActiveRecord/UnqueryableQueryMock.php index ec5bbe2fc..ba0ec1cf7 100644 --- a/tests/Stubs/MagicActiveRecord/UnqueryableQueryMock.php +++ b/tests/Stubs/MagicActiveRecord/UnqueryableQueryMock.php @@ -9,7 +9,7 @@ final class UnqueryableQueryMock extends Query { - public function one(): mixed + public function one(): array|object|null { throw new InvalidCallException('Invalid call'); }