Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/CallBack.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CallBack
/**
* List of available callbacks.
*
* @var array<string>
* @var list<string>
*/
protected static array $VALID_CALLBACKS = [
'after_construct',
Expand Down Expand Up @@ -95,7 +95,7 @@ class CallBack
private \ReflectionClass $klass;

/**
* @var array<string>
* @var list<string>
*/
private array $publicMethods;

Expand Down Expand Up @@ -141,7 +141,7 @@ public function __construct(string $model_class_name)
*
* @param $name string Name of a callback (see {@link VALID_CALLBACKS $VALID_CALLBACKS})
*
* @return array<\Closure|string> array of callbacks or empty array if invalid callback name
* @return list<\Closure|string> array of callbacks or empty array if invalid callback name
*/
public function get_callbacks(string $name): array
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Config extends Singleton
/**
* Contains the list of database connection strings.
*
* @var array<string>
* @var array<string,string>
*/
private array $connections = [];

Expand Down
14 changes: 7 additions & 7 deletions lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class Connection
/**
* Default PDO options to set for each connection.
*
* @var array<mixed>
* @var list<int|bool>
*/
public static array $PDO_OPTIONS = [
\PDO::ATTR_CASE => \PDO::CASE_LOWER,
Expand Down Expand Up @@ -292,7 +292,7 @@ protected function __construct(array $info)
*
* @param string $table Name of a table
*
* @return array<Column> an array of {@link Column} objects
* @return array<string,Column> an array of {@link Column} objects
*/
public function columns(string $table): array
{
Expand Down Expand Up @@ -332,8 +332,8 @@ public function insert_id($sequence = null): int
/**
* Execute a raw SQL query on the database.
*
* @param string $sql raw SQL string to execute
* @param array<mixed> &$values Optional array of bind values
* @param string $sql raw SQL string to execute
* @param list<mixed> &$values Optional array of bind values
*
* @return mixed A result set object
*/
Expand Down Expand Up @@ -391,8 +391,8 @@ public function query_and_fetch_one(string $sql, array &$values = []): int
/**
* Execute a raw SQL query and fetch the results.
*
* @param string $sql raw SQL string to execute
* @param array<mixed> $values
* @param string $sql raw SQL string to execute
* @param list<mixed> $values
*/
public function query_and_fetch(string $sql, array $values = [], int $method = \PDO::FETCH_ASSOC): \Generator
{
Expand All @@ -406,7 +406,7 @@ public function query_and_fetch(string $sql, array $values = [], int $method = \
/**
* Returns all tables for the current database.
*
* @return array<string> array containing table names
* @return list<string> array containing table names
*/
public function tables(): array
{
Expand Down
2 changes: 1 addition & 1 deletion lib/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConnectionManager extends Singleton
/**
* Array of {@link Connection} objects.
*
* @var array<Connection>
* @var array<string,Connection>
*/
private static array $connections = [];

Expand Down
4 changes: 2 additions & 2 deletions lib/Exception/UndefinedPropertyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class UndefinedPropertyException extends ModelException
/**
* Sets the exception message to show the undefined property's name.
*
* @param string $class_name name of the class with the missing property
* @param string|array<string> $property_name name of undefined property
* @param string $class_name name of the class with the missing property
* @param string|list<string> $property_name name of undefined property
*/
public function __construct(string $class_name, string|array $property_name)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Model
* echo $person->id; # => null
* ```
*
* @var array<string>
* @var list<string>
*/
public static array $attr_accessible = [];

Expand Down Expand Up @@ -804,7 +804,7 @@ public function get_validation_rules(): array
/**
* Returns an associative array containing values for all the attributes in $attributes
*
* @param array<string> $attributes Array containing attribute names
* @param list<string> $attributes Array containing attribute names
*
* @return Attributes A hash containing $name => $value
*/
Expand Down Expand Up @@ -1901,7 +1901,7 @@ public static function last(int $limit = null): static|array|null
* "last" static|null User::find("last", ["name"=>"William"]);
* "all" static[] User::find("all", ["name"=>"Stephen"]
* ...int|string static[] User::find(1, 3, 5, 8);
* array<int,int|string> static[] User::find([1,3,5,8]);
* list<int|string> static[] User::find([1,3,5,8]);
*/
public static function find(/* $pk */): Model|array|null
{
Expand Down
26 changes: 13 additions & 13 deletions lib/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class AbstractRelationship
/**
* List of valid options for relationships.
*
* @var array<string>
* @var list<string>
*/
protected static $valid_association_options = [
'association_foreign_key',
Expand Down Expand Up @@ -98,9 +98,9 @@ protected function get_table(): Table
}

/**
* @param array<Model> $models of model objects
* @param array<Attributes> $attributes of attributes from $models
* @param array<mixed> $includes of eager load directives
* @param list<Model> $models of model objects
* @param list<Attributes> $attributes of attributes from $models
* @param list<mixed> $includes of eager load directives
*/
abstract public function load_eagerly(array $models, array $attributes, array $includes, Table $table): void;

Expand All @@ -119,11 +119,11 @@ public function is_poly(): bool
* the related table by PK/FK and attaches the array of returned relationships to the appropriately named relationship on
* $models.
*
* @param array<Model> $models of model objects
* @param array<Attributes> $attributes of attributes from $models
* @param array<mixed> $includes of eager load directives
* @param array<string> $query_keys -> key(s) to be queried for on included/related table
* @param array<string> $model_values_keys -> key(s)/value(s) to be used in query from model which is including
* @param list<Model> $models of model objects
* @param list<Attributes> $attributes of attributes from $models
* @param array<mixed> $includes of eager load directives
* @param list<string> $query_keys -> key(s) to be queried for on included/related table
* @param list<string> $model_values_keys -> key(s)/value(s) to be used in query from model which is including
*/
protected function query_and_attach_related_models_eagerly(Table $table, array $models, array $attributes, array $includes = [], array $query_keys = [], array $model_values_keys = []): void
{
Expand All @@ -132,7 +132,7 @@ protected function query_and_attach_related_models_eagerly(Table $table, array $
$query_key = $query_keys[0];
$model_values_key = $model_values_keys[0];

foreach ($attributes as $column => $value) {
foreach ($attributes as $value) {
$values[] = $value[Inflector::variablize($model_values_key)];
}

Expand Down Expand Up @@ -308,10 +308,10 @@ protected function set_class_name(string $class_name): void
}

/**
* @param array<string> $condition_keys
* @param array<string> $value_keys
* @param list<string> $condition_keys
* @param list<string> $value_keys
*
* @return array<mixed>
* @return list<mixed>
*/
protected function create_conditions_from_keys(Model $model, array $condition_keys = [], array $value_keys = []): ?array
{
Expand Down
10 changes: 5 additions & 5 deletions lib/Relationship/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class BelongsTo extends AbstractRelationship
public string $class_name;

/**
* @var array<string>
* @var list<string>
*/
private array $primary_key;

/**
* @return array<string>
* @return list<string>
*/
public function primary_key(): array
{
Expand Down Expand Up @@ -108,9 +108,9 @@ public function load(Model $model): ?Model
}

/**
* @param array<Model> $models
* @param array<Attributes> $attributes
* @param array<mixed> $includes
* @param list<Model> $models
* @param list<Attributes> $attributes
* @param array<mixed> $includes
*/
public function load_eagerly(array $models, array $attributes, array $includes, Table $table): void
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Relationship/HasAndBelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function is_poly(): bool
}

/**
* @return array<TModel>
* @return list<TModel>
*/
public function load(Model $model): mixed
{
Expand Down
13 changes: 9 additions & 4 deletions lib/Relationship/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HasMany extends AbstractRelationship
/**
* Valid options to use for a {@link HasMany} relationship.
*
* @var array<string>
* @var list<string>
*/
protected static $valid_association_options = [
'primary_key',
Expand All @@ -73,7 +73,7 @@ class HasMany extends AbstractRelationship
];

/**
* @var array<string>
* @var list<string>
*/
protected array $primary_key;

Expand Down Expand Up @@ -129,7 +129,7 @@ protected function set_keys(string $model_class_name, bool $override = false): v
* @throws HasManyThroughAssociationException
* @throws \ActiveRecord\Exception\RelationshipException
*
* @return Model|array<Model>|null
* @return Model|list<Model>|null
*/
public function load(Model $model): mixed
{
Expand Down Expand Up @@ -249,7 +249,12 @@ public function create_association(Model $model, $attributes = [], $guard_attrib
return $record;
}

public function load_eagerly($models, $attributes, $includes, Table $table): void
/**
* @param list<Model> $models
* @param list<Attributes> $attributes
* @param array<mixed> $includes
*/
public function load_eagerly(array $models, array $attributes, array $includes, Table $table): void
{
$this->set_keys($table->class->name);
$this->query_and_attach_related_models_eagerly($table, $models, $attributes, $includes, $this->foreign_key, $table->pk);
Expand Down
6 changes: 3 additions & 3 deletions lib/SQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SQLBuilder
private array $data = [];

/**
* @var array<string>
* @var list<string>
*/
private array $sequence = [];

Expand Down Expand Up @@ -116,7 +116,7 @@ public function get_where_values(): array
}

/**
* @param array<WhereClause> $clauses
* @param list<WhereClause> $clauses
* @param array<string,string> $mappedNames
*
* @throws Exception\ExpressionsException
Expand Down Expand Up @@ -404,7 +404,7 @@ private function build_update(): string
}

/**
* @return array<string>
* @return list<string>
*/
private function quoted_key_names(): array
{
Expand Down
4 changes: 4 additions & 0 deletions lib/Serialize/CsvSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace ActiveRecord\Serialize;

use ActiveRecord\Types;

/**
* CSV serializer.
*
* @phpstan-import-type Attributes from Types
*/
class CsvSerializer extends Serialization
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function reestablish_connection(bool $close = true): Connection
}

/**
* @param array<string>|string $joins
* @param list<string>|string $joins
*
* @throws RelationshipException
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limit?: int,
* offset?: int,
* order?: string,
* primary_key?: string|array<string>,
* primary_key?: string|list<string>,
* through?: string
* }
* @phpstan-type HasAndBelongsToManyOptions array{
Expand All @@ -35,22 +35,22 @@
* @phpstan-type DelegateOptions array{
* to: string,
* prefix?: string,
* delegate: array<string>
* delegate: list<string>
* }
* @phpstan-type RelationOptions array{
* conditions?: array<WhereClause>,
* conditions?: list<WhereClause>,
* from?: string,
* group?: string,
* having?: string,
* include?: string|array<string>,
* joins?: string|array<string>,
* include?: string|list<string>,
* joins?: string|list<string>,
* limit?: int,
* mapped_names?: array<string, string>,
* offset?: int,
* order?: string,
* readonly?: bool,
* distinct?: bool,
* select?: string|array<string>,
* select?: string|list<string>,
* }
*/
abstract class Types
Expand Down
2 changes: 1 addition & 1 deletion lib/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static function is_blank(string|null $var): bool
];

/**
* @var array<string>
* @var array<string,string>
*/
private static array $singular = [
'/(quiz)zes$/i' => '$1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ValidationErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ValidationErrors implements \IteratorAggregate
private array $errors;

/**
* @var array<string>
* @var array<string,string>
*/
public static array $DEFAULT_ERROR_MESSAGES = [
'inclusion' => 'is not included in the list',
Expand Down
6 changes: 3 additions & 3 deletions lib/Validations.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
* }
* @phpstan-type ValidateInclusionOptions array{
* message?: string|null,
* in?: array<string>,
* within?: array<string>
* in?: list<string>,
* within?: list<string>
* }
* @phpstan-type ValidateFormatOptions array{
* with: string,
Expand Down Expand Up @@ -116,7 +116,7 @@ class Validations
];

/**
* @var array<string>
* @var list<string>
*/
private static array $ALL_RANGE_OPTIONS = [
'is',
Expand Down
Loading