Drop support for PHP 8.3 and lower. The package now declares >=8.4, and CI runs only on 8.4. - composer.json: require php >=8.4. - mago.toml: php-version = "8.4", matching the minimum supported version. - phpstan.neon: phpVersion 80400. - Upgrade phpstan/phpstan to ^2.3: 1.x cannot parse `new Foo()->bar()`, which the 8.4 formatter now emits. - Fix the type errors PHPStan 2 reports: class-string<static> variance, optional array offsets in fromEnvironment, list vs array for PdoConnection::$lru, ReflectionClass<Model> docblocks, Repository made covariant in T, and a redundant null comparison in validateRelationPath. - CI: single PHP 8.4 job using the php:8.4-cli container instead of setup-php, which failed with a TLS handshake timeout on the runner. BREAKING CHANGE: PHP 8.4 is now required.
This commit is contained in:
1 parent
c15015d809
commit
0e756e45c7
20 files changed
+97
-107
No files matched your search
@@ -68,6 +68,7 @@ final class ConnectionFactory
|
||||
|
||||
public static function fromEnvironment(): Connection
|
||||
{
|
||||
/** @var array<string, string> $values */
|
||||
$values = [];
|
||||
$missing = [];
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ final class PdoConnection implements Connection
|
||||
/** @var array<string, PDOStatement> */
|
||||
private array $statements = [];
|
||||
|
||||
/** @var list<string> LRU order, most recent last */
|
||||
/** @var array<int, string> LRU order, most recent last; reindexed after eviction */
|
||||
private array $lru = [];
|
||||
|
||||
/** @var list<string> savepoint names for nested transactions */
|
||||
|
||||
@@ -113,7 +113,7 @@ final class MetadataFactory
|
||||
|
||||
/**
|
||||
* @param class-string<\Camelia\Orm\Model> $class
|
||||
* @param ReflectionClass<object> $reflection
|
||||
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||
*/
|
||||
private function buildProperty(
|
||||
string $class,
|
||||
@@ -169,7 +169,7 @@ final class MetadataFactory
|
||||
|
||||
/**
|
||||
* @param class-string<\Camelia\Orm\Model> $class
|
||||
* @param ReflectionClass<object> $reflection
|
||||
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||
*/
|
||||
private function buildRelation(
|
||||
string $class,
|
||||
@@ -238,7 +238,7 @@ final class MetadataFactory
|
||||
|
||||
/**
|
||||
* @param class-string<\Camelia\Orm\Model> $class
|
||||
* @param ReflectionClass<object> $reflection
|
||||
* @param ReflectionClass<\Camelia\Orm\Model> $reflection
|
||||
* @return class-string<\Camelia\Orm\Model>
|
||||
*/
|
||||
private function resolveRelatedClass(
|
||||
|
||||
+3
-9
@@ -56,10 +56,7 @@ abstract class Model
|
||||
|
||||
public static function metadata(): ClassMetadata
|
||||
{
|
||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
||||
$class = static::class;
|
||||
|
||||
return self::metadataFor($class);
|
||||
return self::metadataFor(static::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +190,7 @@ abstract class Model
|
||||
*/
|
||||
public function validate(): array
|
||||
{
|
||||
return (new Validator())->validate($this);
|
||||
return new Validator()->validate($this);
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
@@ -286,10 +283,7 @@ abstract class Model
|
||||
$errors = $this->validate();
|
||||
|
||||
if ($errors !== []) {
|
||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
||||
$class = static::class;
|
||||
|
||||
throw new ValidationException($errors, $class);
|
||||
throw new ValidationException($errors, static::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -82,14 +82,17 @@ final class Orm
|
||||
*/
|
||||
public function repository(string $class): Repository
|
||||
{
|
||||
/** @var Repository<T> $repository */
|
||||
$repository =
|
||||
$this->repositories[$class] ??= new Repository(
|
||||
if (!isset($this->repositories[$class])) {
|
||||
$this->repositories[$class] = new Repository(
|
||||
$this->connection,
|
||||
$class,
|
||||
$this->dialect,
|
||||
$this->persister(),
|
||||
);
|
||||
}
|
||||
|
||||
/** @var Repository<T> $repository */
|
||||
$repository = $this->repositories[$class];
|
||||
|
||||
return $repository;
|
||||
}
|
||||
|
||||
@@ -303,10 +303,7 @@ final class Persister
|
||||
private function assertNotPartial(Model $model, string $operation): void
|
||||
{
|
||||
if ($model->isPartial()) {
|
||||
/** @var class-string<\Camelia\Orm\Model> $class */
|
||||
$class = $model::class;
|
||||
|
||||
throw PartialModelException::onWrite($class, $operation);
|
||||
throw PartialModelException::onWrite($model::class, $operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ final class QueryBuilder
|
||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||
$list = $this->compileSelectList($metadata, $columns);
|
||||
|
||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
||||
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||
|
||||
$sql = 'SELECT ' . $list . ' FROM ' . $table;
|
||||
|
||||
@@ -56,7 +56,7 @@ final class QueryBuilder
|
||||
public function count(ClassMetadata $metadata, array $criteria): array
|
||||
{
|
||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
||||
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS aggregate FROM ' . $table;
|
||||
|
||||
@@ -89,7 +89,7 @@ final class QueryBuilder
|
||||
|
||||
$quoted = $this->dialect->quoteIdentifier($metadata->propertyMetadata($property)->column);
|
||||
$table = $this->dialect->quoteIdentifier($metadata->table());
|
||||
[$where, $params] = (new CriteriaCompiler($this->dialect))->compile($metadata, $criteria);
|
||||
[$where, $params] = new CriteriaCompiler($this->dialect)->compile($metadata, $criteria);
|
||||
|
||||
$sql = 'SELECT ' . $function . '(' . $quoted . ') AS aggregate FROM ' . $table;
|
||||
|
||||
|
||||
+5
-9
@@ -25,7 +25,7 @@ use Camelia\Orm\Support\TypeCaster;
|
||||
* Public read and write API for one model class.
|
||||
*
|
||||
* @api
|
||||
* @template T of Model
|
||||
* @template-covariant T of Model
|
||||
*/
|
||||
final class Repository
|
||||
{
|
||||
@@ -34,7 +34,7 @@ final class Repository
|
||||
private readonly QueryBuilder $builder;
|
||||
|
||||
/**
|
||||
* @param class-string<T> $class
|
||||
* @param class-string<T> $class Not a field of the covariant template; kept for IDE inference.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Connection $connection,
|
||||
@@ -726,7 +726,9 @@ final class Repository
|
||||
throw ConfigurationException::relationDepthExceeded(self::MAX_RELATION_DEPTH);
|
||||
}
|
||||
|
||||
if (!$metadata->hasProperty($name) || $metadata->properties()[$name]->relation === null) {
|
||||
$relation = $metadata->hasProperty($name) ? $metadata->properties()[$name]->relation : null;
|
||||
|
||||
if ($relation === null) {
|
||||
throw MetadataException::unknownRelation($metadata->class, $name);
|
||||
}
|
||||
|
||||
@@ -734,12 +736,6 @@ final class Repository
|
||||
return;
|
||||
}
|
||||
|
||||
$relation = $metadata->properties()[$name]->relation;
|
||||
|
||||
if ($relation === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = $this->relatedRepository($relation->relatedClass)->metadata();
|
||||
|
||||
foreach ($nested as $key => $value) {
|
||||
|
||||
Reference in new issue
Block a user