From 5b4147d7147a83b604b1e2fef10730384e3e4c61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pudil?= <me@jiripudil.cz>
Date: Mon, 1 Feb 2021 13:25:37 +0100
Subject: [PATCH] update to grifart/scaffolder ^0.5

---
 composer.json                                    |  2 +-
 src/Scaffolding/ModificationsDecorator.php       | 16 ++++++++--------
 src/Scaffolding/PrivateConstructorDecorator.php  |  3 ++-
 .../ReconstituteConstructorDecorator.php         |  2 +-
 src/Scaffolding/TableDecorator.php               | 14 +++++---------
 5 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/composer.json b/composer.json
index 847369f..1f7d564 100644
--- a/composer.json
+++ b/composer.json
@@ -24,7 +24,7 @@
     "require": {
         "php": "^8.0",
         "dibi/dibi": "^4.0.2",
-        "grifart/scaffolder": "^0.4.0",
+        "grifart/scaffolder": "^0.5.0",
         "nette/utils": "^3.0.1"
     },
     "require-dev": {
diff --git a/src/Scaffolding/ModificationsDecorator.php b/src/Scaffolding/ModificationsDecorator.php
index 049fc6e..ea97881 100644
--- a/src/Scaffolding/ModificationsDecorator.php
+++ b/src/Scaffolding/ModificationsDecorator.php
@@ -10,6 +10,7 @@ use Grifart\Tables\ModificationsTrait;
 use Nette\PhpGenerator\ClassType;
 use Nette\PhpGenerator\Parameter;
 use Nette\PhpGenerator\PhpLiteral;
+use Nette\PhpGenerator\PhpNamespace;
 
 final class ModificationsDecorator implements ClassDecorator
 {
@@ -28,11 +29,8 @@ final class ModificationsDecorator implements ClassDecorator
 	}
 
 
-	public function decorate(ClassType $classType, ClassDefinition $definition): void
+	public function decorate(PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
 	{
-		$namespace = $classType->getNamespace();
-		\assert($namespace !== NULL, 'Class Generator always generate class in namespace.');
-
 		$namespace->addUse(ModificationsTrait::class);
 		$classType->addTrait(ModificationsTrait::class);
 
@@ -47,7 +45,7 @@ final class ModificationsDecorator implements ClassDecorator
 			->setReturnType('self')
 			->setParameters([
 				(new Parameter('primaryKey'))
-					->setTypeHint($this->primaryKeyClass)
+					->setType($this->primaryKeyClass)
 			])
 			->setBody('return self::_update($primaryKey);');
 
@@ -68,7 +66,10 @@ final class ModificationsDecorator implements ClassDecorator
 			]);
 
 		// modify*() methods
-		foreach ($definition->getFields() as $fieldName => $type) {
+		foreach ($definition->getFields() as $field) {
+			$fieldName = $field->getName();
+			$type = $field->getType();
+
 			// add getter
 			$modifier = $classType->addMethod('modify' . \ucfirst($fieldName))
 				->setVisibility('public')
@@ -90,10 +91,9 @@ final class ModificationsDecorator implements ClassDecorator
 				$docCommentType = $type->getDocCommentType($namespace);
 
 				$modifier->addComment(\sprintf(
-					'@param %s $%s%s',
+					'@param %s $%s',
 					$docCommentType,
 					$fieldName,
-					$type->hasComment() ? ' ' . $type->getComment($namespace) : '',
 				));
 			}
 		}
diff --git a/src/Scaffolding/PrivateConstructorDecorator.php b/src/Scaffolding/PrivateConstructorDecorator.php
index 0889283..10a36db 100644
--- a/src/Scaffolding/PrivateConstructorDecorator.php
+++ b/src/Scaffolding/PrivateConstructorDecorator.php
@@ -5,11 +5,12 @@ namespace Grifart\Tables\Scaffolding;
 use Grifart\ClassScaffolder\Decorators\ClassDecorator;
 use Grifart\ClassScaffolder\Definition\ClassDefinition;
 use Nette\PhpGenerator\ClassType;
+use Nette\PhpGenerator\PhpNamespace;
 
 final class PrivateConstructorDecorator implements ClassDecorator
 {
 
-	public function decorate(ClassType $classType, ClassDefinition $definition): void
+	public function decorate(PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
 	{
 		$classType->getMethod('__construct')->setPrivate();
 	}
diff --git a/src/Scaffolding/ReconstituteConstructorDecorator.php b/src/Scaffolding/ReconstituteConstructorDecorator.php
index e2739f9..b2c2fb6 100644
--- a/src/Scaffolding/ReconstituteConstructorDecorator.php
+++ b/src/Scaffolding/ReconstituteConstructorDecorator.php
@@ -11,7 +11,7 @@ use Nette\PhpGenerator\Property;
 final class ReconstituteConstructorDecorator implements ClassDecorator
 {
 
-	public function decorate(ClassType $classType, ClassDefinition $definition): void
+	public function decorate(Code\PhpNamespace $namespace, ClassType $classType, ClassDefinition $definition): void
 	{
 		$reconstitute = $classType->addMethod('reconstitute')
 			->setReturnType('static')
diff --git a/src/Scaffolding/TableDecorator.php b/src/Scaffolding/TableDecorator.php
index 61b8328..0615f55 100644
--- a/src/Scaffolding/TableDecorator.php
+++ b/src/Scaffolding/TableDecorator.php
@@ -5,7 +5,6 @@ namespace Grifart\Tables\Scaffolding;
 
 
 use Grifart\ClassScaffolder\Decorators\ClassDecorator;
-use Grifart\ClassScaffolder\Decorators\DecoratorTools;
 use Grifart\ClassScaffolder\Definition\ClassDefinition;
 use Grifart\ClassScaffolder\Definition\Types\Type;
 use Grifart\Tables\CaseConvertion;
@@ -53,10 +52,8 @@ final class TableDecorator implements ClassDecorator
 	}
 
 
-	public function decorate(Code\ClassType $classType, ClassDefinition $definition): void
+	public function decorate(Code\PhpNamespace $namespace, Code\ClassType $classType, ClassDefinition $definition): void
 	{
-		$namespace = DecoratorTools::extractNamespace($classType);
-
 		// implements table
 		$namespace->addUse(Table::class);
 		$classType->addImplement(Table::class);
@@ -101,7 +98,7 @@ final class TableDecorator implements ClassDecorator
 		$classType->addMethod('find')
 			->setParameters([
 				(new Code\Parameter('primaryKey'))
-					->setTypeHint($this->primaryKeyClass)
+					->setType($this->primaryKeyClass)
 			])
 			->setReturnType($this->rowClass)
 			->setReturnNullable()
@@ -116,7 +113,7 @@ final class TableDecorator implements ClassDecorator
 		$classType->addMethod('get')
 			->setParameters([
 				(new Code\Parameter('primaryKey'))
-					->setTypeHint($this->primaryKeyClass)
+					->setType($this->primaryKeyClass)
 			])
 			->setReturnType($this->rowClass)
 			->addComment('@throws RowNotFound')
@@ -131,7 +128,7 @@ final class TableDecorator implements ClassDecorator
 		$classType->addMethod('findBy')
 			->setParameters([
 				(new Code\Parameter('conditions'))
-					->setTypeHint('array')
+					->setType('array')
 			])
 			->setComment('@return ' . $namespace->unresolveName($this->rowClass) . '[]')
 			->setReturnType('array')
@@ -169,10 +166,9 @@ final class TableDecorator implements ClassDecorator
 
 				if ($fieldType->requiresDocComment()) {
 					$newMethod->addComment(\sprintf(
-						'@param %s $%s%s',
+						'@param %s $%s',
 						$fieldType->getDocCommentType($namespace),
 						$fieldName,
-						$fieldType->hasComment() ? ' ' . $fieldType->getComment($namespace) : '',
 					));
 				}
 
-- 
GitLab