From e02c86f0cea9ed7c2f084cd5e883edd011f29b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pudil?= <me@jiripudil.cz> Date: Wed, 5 Aug 2020 13:38:09 +0200 Subject: [PATCH] Allow mapping complex types --- .gitlab-ci.yml | 11 ----------- composer.json | 11 ++++------- src/Scaffolding/ModificationsDecorator.php | 6 +++--- src/TypeMapper.php | 11 ++++++++--- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9a83221..f3de909 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,17 +12,6 @@ stages: - composer run verify -test.verify.php72: - <<: *test-verify-template - image: grifart/php7.2-with-gulp-and-all-php-modules - - - -test.verify.php73: - <<: *test-verify-template - image: grifart/php7.3-with-gulp-and-all-php-modules - - 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 2d69b66..1ea9ebe 100644 --- a/composer.json +++ b/composer.json @@ -22,20 +22,17 @@ "require": { - "php": "^7.2", - "nette/utils": "^3.0.1", - "dibi/dibi": "^4.0.2" + "php": "^7.4", + "dibi/dibi": "^4.0.2", + "grifart/class-scaffolder": "^0.2.0", + "nette/utils": "^3.0.1" }, "require-dev": { "nette/tester": "^2.3", - "grifart/class-scaffolder": "^0.1.3", "grifart/phpstan-oneline": "^0.2.2", "phpstan/phpstan": "^0.11.17" }, - "suggest": { - "grifart/class-scaffolder": "⚠️ Install grifart/class-scaffolder as your `-dev` dependency to generate table definitions from your DB automatically." - }, "autoload": { diff --git a/src/Scaffolding/ModificationsDecorator.php b/src/Scaffolding/ModificationsDecorator.php index fefb74e..2058f9b 100644 --- a/src/Scaffolding/ModificationsDecorator.php +++ b/src/Scaffolding/ModificationsDecorator.php @@ -93,10 +93,10 @@ final class ModificationsDecorator implements ClassDecorator $docCommentType = $type->getDocCommentType($namespace); $modifier->addComment(\sprintf( - '@param $%s %s%s', - $fieldName, + '@param %s $%s%s', $docCommentType, - $type->hasComment() ? ' ' . $type->getComment($namespace) : '' + $fieldName, + $type->hasComment() ? ' ' . $type->getComment($namespace) : '', )); } } diff --git a/src/TypeMapper.php b/src/TypeMapper.php index 7c484c1..17582a0 100644 --- a/src/TypeMapper.php +++ b/src/TypeMapper.php @@ -2,11 +2,13 @@ namespace Grifart\Tables; +use Grifart\ClassScaffolder\Definition\Types\Type; + final class TypeMapper { /** - * @var (callable(string $typeName, string $location): ?string)[] + * @var (callable(string $typeName, string $location): (string|Type|null))[] */ private $matchers = []; @@ -17,7 +19,7 @@ final class TypeMapper /** - * @param (callable(string $typeName, string $location): ?string) $typeMatcher + * @param (callable(string $typeName, string $location): (string|Type|null)) $typeMatcher * @param (callable(mixed $value, string $typeName): mixed) $mapper * * TODO: isn't it too general? Or just map db-type name to php type and back? @@ -46,7 +48,10 @@ final class TypeMapper return !\is_object($value) ? \gettype($value) : \get_class($value); } - public function mapType(string $location, string $typeName): string + /** + * @return string|Type + */ + public function mapType(string $location, string $typeName) { foreach($this->matchers as $idx => $matcher) { if ( ($translatingType = $matcher($typeName, $location)) !== NULL) { -- GitLab