Skip to content
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Earlier releases are listed on the [releases page](https://github.com/Pollora/co

## [Unreleased]

### Changed

- PHPDoc only, no change of signature or behaviour: array value types and the missing `@return` / `@param` tags that PHPStan level 6 asks for. Array types are written `array<mixed>`, so a subclass that redeclares one of these properties or methods is not held to a narrower type. The analysed level stays at 5.
- PHPDoc only: generic types on most relations, on the relation factories of `Model`, on query scope parameters, collections and builders (the three builders now declare a `TModel` template with a default). Static analysis of a project that overrides one of these relations with another related model class can now report the mismatch.

## [11.1.0] - 2026-11-19

### Changed
Expand Down
3 changes: 2 additions & 1 deletion src/Concerns/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
trait Aliases
{
/**
* @return array
* @return array<mixed>
*/
public static function getAliases()
{
Expand All @@ -28,6 +28,7 @@ public static function getAliases()
/**
* @param string $new
* @param string $old
* @return void
*/
public static function addAlias($new, $old)
{
Expand Down
22 changes: 13 additions & 9 deletions src/Concerns/MetaFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Support\Collection;
use Pollora\Colt\Model\Comment;
use Pollora\Colt\Model\Meta\CommentMeta;
use Pollora\Colt\Model\Meta\Meta;
use Pollora\Colt\Model\Meta\PostMeta;
use Pollora\Colt\Model\Meta\TermMeta;
use Pollora\Colt\Model\Meta\UserMeta;
Expand All @@ -26,7 +27,7 @@
trait MetaFields
{
/**
* @var array<class-string, class-string>
* @var array<class-string, class-string<Meta>>
*/
protected $builtInClasses = [
Comment::class => CommentMeta::class,
Expand All @@ -36,24 +37,26 @@ trait MetaFields
];

/**
* @return HasMany
* @return HasMany<Meta, $this>
*/
public function fields()
{
return $this->meta();
}

/**
* @return HasMany
* @return HasMany<Meta, $this>
*/
public function meta()
{
return $this->hasMany($this->getMetaClass(), $this->getMetaForeignKey());
}

/**
* @param string|array $meta
* @param Builder<static> $query
* @param string|array<mixed> $meta
* @param mixed $value
* @return Builder<static>
*/
public function scopeHasMeta(Builder $query, $meta, $value = null, string $operator = '='): Builder
{
Expand All @@ -78,9 +81,10 @@ public function scopeHasMeta(Builder $query, $meta, $value = null, string $opera
}

/**
* @param Builder<static> $query
* @param string $meta
* @param mixed $value
* @return Builder
* @return Builder<static>
*/
public function scopeHasMetaLike(Builder $query, $meta, $value = null)
{
Expand All @@ -98,7 +102,7 @@ public function saveField($key, $value)
}

/**
* @param string|array $key
* @param string|array<mixed> $key
* @param mixed $value
* @return bool
*/
Expand Down Expand Up @@ -128,9 +132,9 @@ public function createField($key, $value)
}

/**
* @param string|array $key
* @param string|array<mixed> $key
* @param mixed $value
* @return Model|Collection
* @return Model|Collection<array-key, Model|null>
*/
public function createMeta($key, $value = null)
{
Expand All @@ -155,7 +159,7 @@ public function getMeta($attribute)
}

/**
* @return string
* @return class-string<Meta>
*
* @throws UnexpectedValueException
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Concerns/OrderScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
trait OrderScopes
{
/**
* @param Builder<static> $query
* @return Builder
*/
public function scopeNewest(Builder $query)
Expand All @@ -22,6 +23,7 @@ public function scopeNewest(Builder $query)
}

/**
* @param Builder<static> $query
* @return Builder
*/
public function scopeOldest(Builder $query)
Expand Down
10 changes: 9 additions & 1 deletion src/Concerns/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
trait Shortcodes
{
/**
* @var array
* @var array<mixed>
*/
protected static $shortcodes = [];

Expand All @@ -28,6 +28,7 @@ trait Shortcodes
/**
* @param string $tag the shortcode tag
* @param \Closure $function the shortcode handling function
* @return void
*/
public static function addShortcode($tag, $function)
{
Expand All @@ -38,6 +39,7 @@ public static function addShortcode($tag, $function)
* Removes a shortcode handler.
*
* @param string $tag the shortcode tag
* @return void
*/
public static function removeShortcode($tag)
{
Expand Down Expand Up @@ -84,13 +86,19 @@ private function getShortcodeHandlerInstance(): ShortcodeFacade
});
}

/**
* @return void
*/
private function parseClassShortcodes(ShortcodeFacade $facade)
{
foreach (self::$shortcodes as $tag => $func) {
$facade->addHandler($tag, $func);
}
}

/**
* @return void
*/
private function parseConfigShortcodes(ShortcodeFacade $facade)
{
if (Colt::isLaravel()) {
Expand Down
5 changes: 4 additions & 1 deletion src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Database
{
/**
* @var array
* @var array<mixed>
*/
protected static $baseParams = [
'driver' => 'mysql',
Expand All @@ -25,6 +25,9 @@ class Database
'prefix' => 'wp_',
];

/**
* @param array<mixed> $params connection settings, merged over the defaults
*/
public static function connect(array $params): Manager
{
$capsule = new Capsule;
Expand Down
11 changes: 10 additions & 1 deletion src/Laravel/Auth/AuthUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
class AuthUserProvider implements UserProvider
{
/**
* @var array
* @var array<mixed>
*/
protected $config = [];

/**
* @param array<mixed> $config
*/
public function __construct(array $config = [])
{
$this->config = $config;
Expand Down Expand Up @@ -74,6 +77,7 @@ public function updateRememberToken(Authenticatable $user, $token)
/**
* Retrieve a user by the given credentials.
*
* @param array<mixed> $credentials
* @return Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
Expand All @@ -95,6 +99,8 @@ public function retrieveByCredentials(array $credentials)

/**
* Validate a user against the given credentials.
*
* @param array<mixed> $credentials
*/
public function validateCredentials(Authenticatable $user, array $credentials): bool
{
Expand All @@ -106,6 +112,9 @@ public function validateCredentials(Authenticatable $user, array $credentials):
->check($credentials['password'], $user->user_pass);
}

/**
* @param array<mixed> $credentials
*/
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false)
{
//
Expand Down
33 changes: 27 additions & 6 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ class Model extends Eloquent
* do not load it with their query (terms, comments): reading `meta` then
* loads it for the whole collection at once. First collection wins, so a
* filtered copy does not narrow the batch.
*
* @var MetaSiblingsCollection<array-key, covariant Model>|null
*/
protected ?MetaSiblingsCollection $metaSiblings = null;

/**
* Replace the original hasMany function to forward the connection name.
*
* @param string $related
* @template TRelatedModel of Eloquent
*
* @param class-string<TRelatedModel> $related
* @param string $foreignKey
* @param string $localKey
* @return HasMany
Expand All @@ -59,7 +63,9 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
/**
* Replace the original hasOne function to forward the connection name.
*
* @param string $related
* @template TRelatedModel of Eloquent
*
* @param class-string<TRelatedModel> $related
* @param string $foreignKey
* @param string $localKey
* @return HasOne
Expand All @@ -80,11 +86,13 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
/**
* Replace the original belongsTo function to forward the connection name.
*
* @param string $related
* @template TRelatedModel of Eloquent
*
* @param class-string<TRelatedModel> $related
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return BelongsTo
* @return BelongsTo<TRelatedModel, $this>
*/
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{
Expand All @@ -109,14 +117,16 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
/**
* Replace the original belongsToMany function to forward the connection name.
*
* @param string $related
* @template TRelatedModel of Eloquent
*
* @param class-string<TRelatedModel> $related
* @param string $table
* @param string $foreignPivotKey
* @param string $relatedPivotKey
* @param string $parentKey
* @param string $relatedKey
* @param string $relation
* @return BelongsToMany
* @return BelongsToMany<TRelatedModel, $this>
*/
public function belongsToMany(
$related,
Expand Down Expand Up @@ -196,6 +206,8 @@ public function newCollection(array $models = [])
/**
* Remembers the collection that holds this model.
*
* @param MetaSiblingsCollection<array-key, covariant Model> $siblings
*
* @internal called by MetaSiblingsCollection
*/
public function joinMetaSiblings(MetaSiblingsCollection $siblings): void
Expand All @@ -222,6 +234,9 @@ public function getConnectionName()

/**
* Set the connection name to model.
*
* @param mixed $model anything; only Eloquent models are touched
* @return void
*/
protected function setRelationConnection($model)
{
Expand All @@ -230,6 +245,12 @@ protected function setRelationConnection($model)
}
}

/**
* @template TInstance of Eloquent
*
* @param TInstance $instance the related model
* @return TInstance
*/
protected function setInstanceConnection($instance)
{
return $instance->setConnection(
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Attachment extends Post
protected $postType = 'attachment';

/**
* @var array
* @var array<mixed>
*/
protected $appends = [
'title',
Expand All @@ -37,7 +37,7 @@ class Attachment extends Post
];

/**
* @var array
* @var array<mixed>
*/
protected static $aliases = [
'title' => 'post_title',
Expand Down
4 changes: 4 additions & 0 deletions src/Model/Builder/CommentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* Class CommentBuilder
*
* @author Junior Grossi <juniorgro@gmail.com>
*
* @template TModel of \Pollora\Colt\Model\Comment = \Pollora\Colt\Model\Comment
*
* @extends Builder<TModel>
*/
class CommentBuilder extends Builder
{
Expand Down
Loading