Skip to content

Commit d122853

Browse files
committed
ZendCode: upgrade dependency and adapt code
1 parent de3f2f6 commit d122853

8 files changed

+139
-115
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"symfony/filesystem": "^2.7 || ^3 || ^4",
3535
"ramsey/uuid": "^3.7",
3636
"doctrine/annotations": "^1.6",
37-
"zendframework/zend-code": "^3.3.1",
37+
"zendframework/zend-code": "^3.4",
3838
"psr/container": "^1",
3939
"ext-PDO": "*",
4040
"ext-json": "*",

src/Utils/BeanDescriptor.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ private function generateBeanConstructor() : MethodGenerator
361361
$constructorProperties = $this->getConstructorProperties();
362362

363363
$constructor = new MethodGenerator('__construct', [], MethodGenerator::FLAG_PUBLIC);
364-
$constructor->setDocBlock('The constructor takes all compulsory arguments.');
365-
$constructor->getDocBlock()->setWordWrap(false);
364+
$constructorDocBlock = new DocBlockGenerator('The constructor takes all compulsory arguments.');
365+
$constructorDocBlock->setWordWrap(false);
366+
$constructor->setDocBlock($constructorDocBlock);
366367

367368
$assigns = [];
368369
$parentConstructorArguments = [];
@@ -374,7 +375,7 @@ private function generateBeanConstructor() : MethodGenerator
374375
}
375376
$constructor->setParameter($parameter);
376377

377-
$constructor->getDocBlock()->setTag($property->getParamAnnotation());
378+
$constructorDocBlock->setTag($property->getParamAnnotation());
378379

379380
if ($property->getTable()->getName() === $this->table->getName()) {
380381
$assigns[] = $property->getConstructorAssignCode()."\n";
@@ -487,9 +488,14 @@ public function generateJsonSerialize(): MethodGenerator
487488
$parentFk = $this->schemaAnalyzer->getParentRelationship($tableName);
488489

489490
$method = new MethodGenerator('jsonSerialize');
490-
$method->setDocBlock('Serializes the object for JSON encoding.');
491-
$method->getDocBlock()->setTag(new ParamTag('$stopRecursion', ['bool'], 'Parameter used internally by TDBM to stop embedded objects from embedding other objects.'));
492-
$method->getDocBlock()->setTag(new ReturnTag(['array']));
491+
$method->setDocBlock(new DocBlockGenerator(
492+
'Serializes the object for JSON encoding.',
493+
null,
494+
[
495+
new ParamTag('$stopRecursion', ['bool'], 'Parameter used internally by TDBM to stop embedded objects from embedding other objects.'),
496+
new ReturnTag(['array'])
497+
]
498+
));
493499
$method->setParameter(new ParameterGenerator('stopRecursion', 'bool', false));
494500

495501
if ($parentFk !== null) {
@@ -1409,8 +1415,11 @@ private function generateGetUsedTablesCode(): MethodGenerator
14091415
}
14101416

14111417
$method = new MethodGenerator('getUsedTables');
1412-
$method->setDocBlock('Returns an array of used tables by this bean (from parent to child relationship).');
1413-
$method->getDocBlock()->setTag(new ReturnTag(['string[]']));
1418+
$method->setDocBlock(new DocBlockGenerator(
1419+
'Returns an array of used tables by this bean (from parent to child relationship).',
1420+
null,
1421+
[new ReturnTag(['string[]'])]
1422+
));
14141423
$method->setReturnType('array');
14151424
$method->setBody($code);
14161425

@@ -1433,7 +1442,7 @@ private function generateOnDeleteCode(): ?MethodGenerator
14331442
}
14341443

14351444
$method = new MethodGenerator('onDelete');
1436-
$method->setDocBlock('Method called when the bean is removed from database.');
1445+
$method->setDocBlock(new DocBlockGenerator('Method called when the bean is removed from database.'));
14371446
$method->setReturnType('void');
14381447
$method->setBody('parent::onDelete();
14391448
'.$code);
@@ -1453,8 +1462,11 @@ private function generateGetManyToManyRelationshipDescriptorCode(array $pivotTab
14531462

14541463
$method = new MethodGenerator('_getManyToManyRelationshipDescriptor');
14551464
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
1456-
$method->setDocBlock('Get the paths used for many to many relationships methods.');
1457-
$method->getDocBlock()->setTag(new GenericTag('internal'));
1465+
$method->setDocBlock(new DocBlockGenerator(
1466+
'Get the paths used for many to many relationships methods.',
1467+
null,
1468+
[new GenericTag('internal')]
1469+
));
14581470
$method->setReturnType(ManyToManyRelationshipPathDescriptor::class);
14591471

14601472
$parameter = new ParameterGenerator('pathKey');
@@ -1488,9 +1500,11 @@ private function generateGetManyToManyRelationshipDescriptorKeysCode(array $pivo
14881500
$method = new MethodGenerator('_getManyToManyRelationshipDescriptorKeys');
14891501
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
14901502
$method->setReturnType('array');
1491-
$method->setDocBlock('Returns the list of keys supported for many to many relationships');
1492-
$method->getDocBlock()->setTag(new GenericTag('internal'));
1493-
$method->getDocBlock()->setTag(new ReturnTag('string[]'));
1503+
$method->setDocBlock(new DocBlockGenerator(
1504+
'Returns the list of keys supported for many to many relationships',
1505+
null,
1506+
[new GenericTag('internal'), new ReturnTag('string[]')]
1507+
));
14941508

14951509
$keys = [];
14961510
foreach ($pivotTableMethodsDescriptors as $pivotTableMethodsDescriptor) {
@@ -1664,7 +1678,7 @@ private function generateGetForeignKeys(array $fks): MethodGenerator
16641678
$method = new MethodGenerator('getForeignKeys');
16651679
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PROTECTED);
16661680
$method->setStatic(true);
1667-
$method->setDocBlock('Internal method used to retrieve the list of foreign keys attached to this bean.');
1681+
$method->setDocBlock(new DocBlockGenerator('Internal method used to retrieve the list of foreign keys attached to this bean.'));
16681682
$method->setReturnType(ForeignKeys::class);
16691683

16701684
$parameter = new ParameterGenerator('tableName');

src/Utils/DirectForeignKeyMethodDescriptor.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use TheCodingMachine\TDBM\Utils\Annotation;
1414
use Zend\Code\Generator\AbstractMemberGenerator;
1515
use Zend\Code\Generator\DocBlock\Tag\ReturnTag;
16+
use Zend\Code\Generator\DocBlockGenerator;
1617
use Zend\Code\Generator\MethodGenerator;
1718

1819
/**
@@ -127,9 +128,11 @@ public function getCode() : array
127128
$getter = new MethodGenerator($this->getName());
128129

129130
if ($this->hasLocalUniqueIndex()) {
130-
$getter->setDocBlock(sprintf('Returns the %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
131131
$classType = '\\' . $this->beanNamespace . '\\' . $beanClass;
132-
$getter->getDocBlock()->setTag(new ReturnTag([$classType . '|null']))->setWordWrap(false);
132+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
133+
$getterDocBlock->setTag([new ReturnTag([$classType . '|null'])]);
134+
$getterDocBlock->setWordWrap(false);
135+
$getter->setDocBlock($getterDocBlock);
133136
$getter->setReturnType('?' . $classType);
134137

135138
$code = sprintf(
@@ -139,11 +142,10 @@ public function getCode() : array
139142
$this->getFilters($this->foreignKey)
140143
);
141144
} else {
142-
$getter->setDocBlock(sprintf('Returns the list of %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
143-
$getter->getDocBlock()->setTag(new ReturnTag([
144-
$beanClass . '[]',
145-
'\\' . AlterableResultIterator::class
146-
]))->setWordWrap(false);
145+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the list of %s pointing to this bean via the %s column.', $beanClass, implode(', ', $this->foreignKey->getUnquotedLocalColumns())));
146+
$getterDocBlock->setTag(new ReturnTag([$beanClass . '[]', '\\' . AlterableResultIterator::class]));
147+
$getterDocBlock->setWordWrap(false);
148+
$getter->setDocBlock($getterDocBlock);
147149
$getter->setReturnType(AlterableResultIterator::class);
148150

149151
$code = sprintf(

src/Utils/ObjectBeanPropertyDescriptor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
1111
use TheCodingMachine\TDBM\Utils\Annotation;
1212
use Zend\Code\Generator\AbstractMemberGenerator;
13+
use Zend\Code\Generator\DocBlockGenerator;
1314
use Zend\Code\Generator\MethodGenerator;
1415
use Zend\Code\Generator\ParameterGenerator;
1516

@@ -159,7 +160,7 @@ public function getGetterSetterCode(): array
159160
$referencedBeanName = $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName());
160161

161162
$getter = new MethodGenerator($getterName);
162-
$getter->setDocBlock('Returns the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.');
163+
$getter->setDocBlock(new DocBlockGenerator('Returns the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.'));
163164

164165
/*$types = [ $referencedBeanName ];
165166
if ($isNullable) {
@@ -177,7 +178,7 @@ public function getGetterSetterCode(): array
177178
}
178179

179180
$setter = new MethodGenerator($setterName);
180-
$setter->setDocBlock('The setter for the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.');
181+
$setter->setDocBlock(new DocBlockGenerator('The setter for the ' . $referencedBeanName . ' object bound to this object via the ' . implode(' and ', $this->foreignKey->getUnquotedLocalColumns()) . ' column.'));
181182

182183
$setter->setParameter(new ParameterGenerator('object', ($isNullable ? '?' : '') . $this->beanNamespace . '\\' . $referencedBeanName));
183184

src/Utils/PivotTableMethodsDescriptor.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\Schema\Column;
88
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
99
use Doctrine\DBAL\Schema\Table;
10+
use Zend\Code\Generator\DocBlockGenerator;
1011
use function implode;
1112
use function sprintf;
1213
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
@@ -199,39 +200,49 @@ public function getCode() : array
199200
$localTableName = var_export($this->remoteFk->getLocalTableName(), true);
200201

201202
$getter = new MethodGenerator($this->getName());
202-
$getter->setDocBlock(sprintf('Returns the list of %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
203-
$getter->getDocBlock()->setTag(new ReturnTag([ $fqcnRemoteBeanName.'[]' ]))->setWordWrap(false);
203+
$getterDocBlock = new DocBlockGenerator(sprintf('Returns the list of %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
204+
$getterDocBlock->setTag(new ReturnTag([ $fqcnRemoteBeanName.'[]' ]));
205+
$getterDocBlock->setWordWrap(false);
206+
$getter->setDocBlock($getterDocBlock);
204207
$getter->setReturnType('array');
205208
$getter->setBody(sprintf('return $this->_getRelationships(%s);', $pathKey));
206209

207210

208211
$adder = new MethodGenerator('add'.$singularName);
209-
$adder->setDocBlock(sprintf('Adds a relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
210-
$adder->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
212+
$adderDocBlock = new DocBlockGenerator(sprintf('Adds a relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
213+
$adderDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
214+
$adderDocBlock->setWordWrap(false);
215+
$adder->setDocBlock($adderDocBlock);
211216
$adder->setReturnType('void');
212217
$adder->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
213218
$adder->setBody(sprintf('$this->addRelationship(%s, $%s);', $localTableName, $variableName));
214219

215220
$remover = new MethodGenerator('remove'.$singularName);
216-
$remover->setDocBlock(sprintf('Deletes the relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
217-
$remover->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
221+
$removerDocBlock = new DocBlockGenerator(sprintf('Deletes the relationship with %s associated to this bean via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
222+
$removerDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
223+
$removerDocBlock->setWordWrap(false);
224+
$remover->setDocBlock($removerDocBlock);
218225
$remover->setReturnType('void');
219226
$remover->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
220227
$remover->setBody(sprintf('$this->_removeRelationship(%s, $%s);', $localTableName, $variableName));
221228

222229
$has = new MethodGenerator('has'.$singularName);
223-
$has->setDocBlock(sprintf('Returns whether this bean is associated with %s via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
224-
$has->getDocBlock()->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]))->setWordWrap(false);
225-
$has->getDocBlock()->setTag(new ReturnTag([ 'bool' ]));
230+
$hasDocBlock = new DocBlockGenerator(sprintf('Returns whether this bean is associated with %s via the %s pivot table.', $remoteBeanName, $this->pivotTable->getName()));
231+
$hasDocBlock->setTag(new ParamTag($variableName, [ $fqcnRemoteBeanName ]));
232+
$hasDocBlock->setTag(new ReturnTag([ 'bool' ]));
233+
$hasDocBlock->setWordWrap(false);
234+
$has->setDocBlock($hasDocBlock);
226235
$has->setReturnType('bool');
227236
$has->setParameter(new ParameterGenerator($variableName, $fqcnRemoteBeanName));
228237
$has->setBody(sprintf('return $this->hasRelationship(%s, $%s);', $pathKey, $variableName));
229238

230239
$setter = new MethodGenerator('set'.$pluralName);
231-
$setter->setDocBlock(sprintf('Sets all relationships with %s associated to this bean via the %s pivot table.
240+
$setterDocBlock = new DocBlockGenerator(sprintf('Sets all relationships with %s associated to this bean via the %s pivot table.
232241
Exiting relationships will be removed and replaced by the provided relationships.', $remoteBeanName, $this->pivotTable->getName()));
233-
$setter->getDocBlock()->setTag(new ParamTag($pluralVariableName, [ $fqcnRemoteBeanName.'[]' ]))->setWordWrap(false)->setWordWrap(false);
234-
$setter->getDocBlock()->setTag(new ReturnTag([ 'void' ]));
242+
$setterDocBlock->setTag(new ParamTag($pluralVariableName, [ $fqcnRemoteBeanName.'[]' ]));
243+
$setterDocBlock->setTag(new ReturnTag([ 'void' ]));
244+
$setterDocBlock->setWordWrap(false);
245+
$setter->setDocBlock($setterDocBlock);
235246
$setter->setReturnType('void');
236247
$setter->setParameter(new ParameterGenerator($pluralVariableName, 'array'));
237248
$setter->setBody(sprintf('$this->setRelationships(%s, $%s);', $pathKey, $pluralVariableName));

src/Utils/ScalarBeanPropertyDescriptor.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Zend\Code\Generator\AbstractMemberGenerator;
1515
use Zend\Code\Generator\DocBlock\Tag\ParamTag;
1616
use Zend\Code\Generator\DocBlock\Tag\ReturnTag;
17+
use Zend\Code\Generator\DocBlockGenerator;
1718
use Zend\Code\Generator\MethodGenerator;
1819
use Zend\Code\Generator\ParameterGenerator;
1920

@@ -222,21 +223,20 @@ public function getGetterSetterCode(): array
222223
$resourceTypeCheck = sprintf($resourceTypeCheck, $checkNullable, $this->column->getName(), $this->column->getName());
223224
}
224225

226+
$types = [ $normalizedType ];
227+
if ($isNullable) {
228+
$types[] = 'null';
229+
}
225230

226231
$paramType = null;
227232
if ($this->isTypeHintable()) {
228233
$paramType = ($isNullable?'?':'').$normalizedType;
229234
}
230235

231236
$getter = new MethodGenerator($columnGetterName);
232-
$getter->setDocBlock(sprintf('The getter for the "%s" column.', $this->column->getName()));
233-
234-
$types = [ $normalizedType ];
235-
if ($isNullable) {
236-
$types[] = 'null';
237-
}
238-
$getter->getDocBlock()->setTag(new ReturnTag($types))->setWordWrap(false);
239-
237+
$getterDocBlock = new DocBlockGenerator(sprintf('The getter for the "%s" column.', $this->column->getName()));
238+
$getterDocBlock->setTag(new ReturnTag($types))->setWordWrap(false);
239+
$getter->setDocBlock($getterDocBlock);
240240
$getter->setReturnType($paramType);
241241

242242
$getter->setBody(sprintf(
@@ -250,13 +250,9 @@ public function getGetterSetterCode(): array
250250
}
251251

252252
$setter = new MethodGenerator($columnSetterName);
253-
$setter->setDocBlock(sprintf('The setter for the "%s" column.', $this->column->getName()));
254-
255-
$types = [ $normalizedType ];
256-
if ($isNullable) {
257-
$types[] = 'null';
258-
}
259-
$setter->getDocBlock()->setTag(new ParamTag($this->column->getName(), $types))->setWordWrap(false);
253+
$setterDocBlock = new DocBlockGenerator(sprintf('The setter for the "%s" column.', $this->column->getName()));
254+
$setterDocBlock->setTag(new ParamTag($this->column->getName(), $types))->setWordWrap(false);
255+
$setter->setDocBlock($setterDocBlock);
260256

261257
$parameter = new ParameterGenerator($this->column->getName(), $paramType);
262258
$setter->setParameter($parameter);

0 commit comments

Comments
 (0)