From 980d3902ad8b8e08efee5ad193be8ea258fd8bbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pudil?= <me@jiripudil.cz>
Date: Fri, 30 Oct 2020 17:08:26 +0100
Subject: [PATCH] Remove Table::add()

---
 src/Scaffolding/TableDecorator.php | 72 +++++++++++++++---------------
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/src/Scaffolding/TableDecorator.php b/src/Scaffolding/TableDecorator.php
index 37f0e69..7436f28 100644
--- a/src/Scaffolding/TableDecorator.php
+++ b/src/Scaffolding/TableDecorator.php
@@ -148,49 +148,47 @@ final class TableDecorator implements ClassDecorator
 				]
 			);
 
-		foreach (['add', 'new'] as $methodName) {
-			$classType->addMethod("${methodName}Empty")
-				->setReturnType($this->modificationClass)
-				->setBody(
-					'return ?::new();',
-					[new Code\PhpLiteral($namespace->unresolveName($this->modificationClass))],
-				);
+		$classType->addMethod('newEmpty')
+			->setReturnType($this->modificationClass)
+			->setBody(
+				'return ?::new();',
+				[new Code\PhpLiteral($namespace->unresolveName($this->modificationClass))],
+			);
 
-			$addMethod = $classType->addMethod($methodName)
-				->setReturnType($this->modificationClass)
-				->addBody(
-					'$modifications = ?::new();',
-					[new Code\PhpLiteral($namespace->unresolveName($this->modificationClass))],
-				);
+		$newMethod = $classType->addMethod('new')
+			->setReturnType($this->modificationClass)
+			->addBody(
+				'$modifications = ?::new();',
+				[new Code\PhpLiteral($namespace->unresolveName($this->modificationClass))],
+			);
 
-			foreach ($this->columnInfo as $columnInfo) {
-				if ( ! $columnInfo->hasDefaultValue()) {
-					$fieldName = $columnInfo->getName();
-					$fieldType = $this->columnPhpTypes[$fieldName];
-
-					$addMethod->addParameter($fieldName)
-						->setTypeHint($fieldType->getTypeHint())
-						->setNullable($fieldType->isNullable());
-
-					if ($fieldType->requiresDocComment()) {
-						$addMethod->addComment(\sprintf(
-							'@param %s $%s%s',
-							$fieldType->getDocCommentType($namespace),
-							$fieldName,
-							$fieldType->hasComment() ? ' ' . $fieldType->getComment($namespace) : '',
-						));
-					}
-
-					$addMethod->addBody(
-						'$modifications->modify' . \ucfirst($fieldName) . '(?);',
-						[new Code\PhpLiteral('$' . $fieldName)],
-					);
+		foreach ($this->columnInfo as $columnInfo) {
+			if ( ! $columnInfo->hasDefaultValue()) {
+				$fieldName = $columnInfo->getName();
+				$fieldType = $this->columnPhpTypes[$fieldName];
+
+				$newMethod->addParameter($fieldName)
+					->setTypeHint($fieldType->getTypeHint())
+					->setNullable($fieldType->isNullable());
+
+				if ($fieldType->requiresDocComment()) {
+					$newMethod->addComment(\sprintf(
+						'@param %s $%s%s',
+						$fieldType->getDocCommentType($namespace),
+						$fieldName,
+						$fieldType->hasComment() ? ' ' . $fieldType->getComment($namespace) : '',
+					));
 				}
-			}
 
-			$addMethod->addBody('return $modifications;');
+				$newMethod->addBody(
+					'$modifications->modify' . \ucfirst($fieldName) . '(?);',
+					[new Code\PhpLiteral('$' . $fieldName)],
+				);
+			}
 		}
 
+		$newMethod->addBody('return $modifications;');
+
 
 		$classType->addMethod('edit')
 			->setReturnType($this->modificationClass)
-- 
GitLab