diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f3de909c5a15f18d51c236df497c1ce93c227a7b..61aa2464abaef325181bd7566a76adfecbe6acf7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,9 @@ stages: - test -.test-verify-template: &test-verify-template +test-verify: stage: test + image: grifart/php8.0-with-all-modules-and-various-tools interruptible: true before_script: @@ -10,8 +11,3 @@ stages: script: - composer run verify - - -test.verify.php74: - <<: *test-verify-template - image: grifart/php7.4-with-gulp-and-all-php-modules diff --git a/composer.json b/composer.json index 5676bfc979d8a12f7634b83b14dd84dd6484df0c..23abd38e50b43dfe47b6625bbbe5d2d918d2f774 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,14 @@ "require": { - "php": "^7.4", + "php": "^8.0", "dibi/dibi": "^4.0.2", - "grifart/class-scaffolder": "^0.2.0|^0.3.0", + "grifart/class-scaffolder": "^0.4.0", "nette/utils": "^3.0.1" }, "require-dev": { "nette/tester": "^2.3", - "grifart/phpstan-oneline": "^0.3", + "grifart/phpstan-oneline": "^0.4.0", "phpstan/phpstan": "^0.12" }, diff --git a/src/Row.php b/src/Row.php index 52088e5b2c5825d0883f6c4e9d0d9eecb8a62672..0db2c7713767f2747e7b6d8025602d2d47ebd5dd 100644 --- a/src/Row.php +++ b/src/Row.php @@ -9,8 +9,7 @@ interface Row /** * @param mixed[] $values - * @return self */ - public static function reconstitute(array $values); + public static function reconstitute(array $values): static; } diff --git a/src/Scaffolding/Column.php b/src/Scaffolding/Column.php index 34086dd1acd8bf963e17056ce9399d3a5060a995..6d1cf634062065b2cbacea69b029df6d87c4d715 100644 --- a/src/Scaffolding/Column.php +++ b/src/Scaffolding/Column.php @@ -7,21 +7,12 @@ namespace Grifart\Tables\Scaffolding; final class Column { - private string $name; - - private string $type; - - private bool $nullable; - - private bool $hasDefaultValue; - - public function __construct(string $name, string $type, bool $nullable, bool $hasDefaultValue) - { - $this->name = $name; - $this->type = $type; - $this->nullable = $nullable; - $this->hasDefaultValue = $hasDefaultValue; - } + public function __construct( + private string $name, + private string $type, + private bool $nullable, + private bool $hasDefaultValue, + ) {} public function getName(): string { diff --git a/src/Scaffolding/PostgresReflector.php b/src/Scaffolding/PostgresReflector.php index 871dc7d01513f4ad1323c52876ab575c7b4dffc4..a580c8d8e0338cb0d184f946d93963a8bb7912dd 100644 --- a/src/Scaffolding/PostgresReflector.php +++ b/src/Scaffolding/PostgresReflector.php @@ -9,13 +9,9 @@ use Dibi\Connection; final class PostgresReflector { - /** @var Connection */ - private $connection; - - public function __construct(Connection $connection) - { - $this->connection = $connection; - } + public function __construct( + private Connection $connection + ) {} /** * source: https://stackoverflow.com/a/51897900/631369 diff --git a/src/Scaffolding/PrivateConstructorDecorator.php b/src/Scaffolding/PrivateConstructorDecorator.php index 0007998e332f424d6d64c4dcb67a7df8c9da0c2c..0889283bc8501ad4bd0a1d90bab1a2caa25711f4 100644 --- a/src/Scaffolding/PrivateConstructorDecorator.php +++ b/src/Scaffolding/PrivateConstructorDecorator.php @@ -11,6 +11,6 @@ final class PrivateConstructorDecorator implements ClassDecorator public function decorate(ClassType $classType, ClassDefinition $definition): void { - $classType->getMethod('__construct')->setVisibility('private'); + $classType->getMethod('__construct')->setPrivate(); } } diff --git a/src/Scaffolding/ReconstituteConstructorDecorator.php b/src/Scaffolding/ReconstituteConstructorDecorator.php index 046c3cfb121292525875a4d15d43028042c73433..e2739f939588db64df6738f5d1945e615f720693 100644 --- a/src/Scaffolding/ReconstituteConstructorDecorator.php +++ b/src/Scaffolding/ReconstituteConstructorDecorator.php @@ -14,7 +14,7 @@ final class ReconstituteConstructorDecorator implements ClassDecorator public function decorate(ClassType $classType, ClassDefinition $definition): void { $reconstitute = $classType->addMethod('reconstitute') - ->setReturnType('self') + ->setReturnType('static') ->setParameters([(new Code\Parameter('values'))->setTypeHint('array')]) ->setStatic(); @@ -25,6 +25,6 @@ final class ReconstituteConstructorDecorator implements ClassDecorator // todo: add array_keys that it contains just keys that are necessary - $reconstitute->addBody("return new self($questionMarks);", \array_values($literals)); + $reconstitute->addBody("return new static($questionMarks);", \array_values($literals)); } } diff --git a/src/Scaffolding/TableDecorator.php b/src/Scaffolding/TableDecorator.php index f5c412f7a9523f6460b24b2f4440a4172838859f..61b8328974644785381995dcdaaa74f1a28a907a 100644 --- a/src/Scaffolding/TableDecorator.php +++ b/src/Scaffolding/TableDecorator.php @@ -18,26 +18,21 @@ use Webmozart\Assert\Assert; final class TableDecorator implements ClassDecorator { - /** @var string */ - private $schema; + private string $schema; - /** @var string */ - private $tableName; + private string $tableName; - /** @var string */ - private $primaryKeyClass; + private string $primaryKeyClass; - /** @var string */ - private $rowClass; + private string $rowClass; - /** @var string */ - private $modificationClass; + private string $modificationClass; /** @var Column[] */ - private $columnInfo; + private array $columnInfo; /** @var array<string, Type> */ - private $columnPhpTypes; + private array $columnPhpTypes; /** * @param array<string, Column> $columnInfo @@ -270,10 +265,7 @@ final class TableDecorator implements ClassDecorator $this->implementConfigMethod($classType, $name, new Code\PhpLiteral($namespace->unresolveName($class) . '::class')); } - /** - * @param mixed $value - */ - private function implementConfigMethod(Code\ClassType $classType, string $name, $value): void + private function implementConfigMethod(Code\ClassType $classType, string $name, mixed $value): void { $classType->addMethod($name) ->setStatic() diff --git a/src/TableManager.php b/src/TableManager.php index 1bc71181eab74b280aecdf19a72de700ae23c811..7a921cd5990ee3194090173d2d26447d1b9afb45 100644 --- a/src/TableManager.php +++ b/src/TableManager.php @@ -15,21 +15,11 @@ use Dibi\Connection; final class TableManager { - /** @var Connection */ - private $connection; - - /** @var TypeMapper */ - private $phpToDatabaseMapper; - - /** @var TypeMapper */ - private $databaseToPhpMapper; - - public function __construct(Connection $connection, TypeMapper $phpToDatabaseMapper, TypeMapper $databaseToPhpMapper) - { - $this->connection = $connection; - $this->phpToDatabaseMapper = $phpToDatabaseMapper; - $this->databaseToPhpMapper = $databaseToPhpMapper; - } + public function __construct( + private Connection $connection, + private TypeMapper $phpToDatabaseMapper, + private TypeMapper $databaseToPhpMapper, + ) {} public function insert(Table $table, Modifications $changes): void diff --git a/src/TypeMapper.php b/src/TypeMapper.php index 3ded68d38960800b33ace8721c4d4895db0fcc53..310d60731a2a7eaafa718a3db7149fb1b0393fe4 100644 --- a/src/TypeMapper.php +++ b/src/TypeMapper.php @@ -10,12 +10,12 @@ final class TypeMapper /** * @var (callable(string $typeName, string $location): (string|Type|null))[] */ - private $matchers = []; + private array $matchers = []; /** * @var (callable(mixed $value, string $typeName): mixed)[] */ - private $mappings = []; + private array $mappings = []; /** @@ -29,11 +29,7 @@ final class TypeMapper $this->mappings[] = $mapper; } - /** - * @param mixed $value - * @return mixed - */ - public function map(string $location, string $typeName, $value) { + public function map(string $location, string $typeName, mixed $value): mixed { if ($value === NULL) { return NULL; // todo: really do not translate? } @@ -48,17 +44,7 @@ final class TypeMapper throw CouldNotMapTypeException::didYouRegisterTypeMapperFor($typeName, $value); } - /** - * @param mixed $value - */ - private function getTypeForValue($value): string { - return !\is_object($value) ? \gettype($value) : \get_class($value); - } - - /** - * @return string|Type - */ - public function mapType(string $location, string $typeName) + public function mapType(string $location, string $typeName): string|Type { foreach($this->matchers as $idx => $matcher) { if ( ($translatingType = $matcher($typeName, $location)) !== NULL) { diff --git a/src/exceptions.php b/src/exceptions.php index e1e80ebc4f34b602bfe5c064d9f5f3994bb5b630..405d957461b58f38a46a0a0dc4f171086f1ce3fb 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -21,10 +21,7 @@ final class ProbablyBrokenPrimaryIndexImplementation extends UsageException { final class CouldNotMapTypeException extends UsageException { - /** - * @param mixed $value - */ - public static function didYouRegisterTypeMapperFor(string $typeName, $value): self + public static function didYouRegisterTypeMapperFor(string $typeName, mixed $value): self { return new self( "Did you register type mapper for type '$typeName' and value of type "