Skip to content

Commit 6c5ba90

Browse files
committed
ResultIterator: Use @method to declare getIterator() return type, fix findBy return type
1 parent cb6f501 commit 6c5ba90

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

src/Utils/BeanDescriptor.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,23 +1157,11 @@ public function generateResultIteratorPhpCode(): ?FileGenerator
11571157
$class->setName($baseClassName);
11581158
$class->setExtendedClass(ResultIterator::class);
11591159

1160-
$class->setDocBlock(new DocBlockGenerator("The $baseClassName class will iterate over results of $beanClassWithoutNameSpace class."));
1161-
1162-
$getIteratorMethod = new MethodGenerator(
1163-
'getIterator',
1164-
[],
1165-
MethodGenerator::FLAG_PUBLIC,
1166-
'return parent::getIterator();',
1167-
(new DocBlockGenerator(
1168-
"Return a ResultIterator of $beanClassWithoutNameSpace instances.",
1169-
null,
1170-
[
1171-
new ReturnTag(['\\' . $beanClassName . '[]', '\\' . InnerResultIterator::class])
1172-
]
1173-
))->setWordWrap(false)
1174-
);
1175-
1176-
$class->addMethodFromGenerator($getIteratorMethod);
1160+
$class->setDocBlock((new DocBlockGenerator(
1161+
"The $baseClassName class will iterate over results of $beanClassWithoutNameSpace class.",
1162+
null,
1163+
[new Tag\MethodTag('getIterator', ['\\' . $beanClassName . '[]'])]
1164+
))->setWordWrap(false));
11771165

11781166
return $file;
11791167
}
@@ -1383,8 +1371,7 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa
13831371
$params[] = new ParamTag('additionalTablesFetch', [ 'string[]' ], 'A list of additional tables to fetch (for performance improvement)');
13841372
$parameters[] = (new ParameterGenerator('mode', '?int'))->setDefaultValue(null);
13851373
$params[] = new ParamTag('mode', [ 'int', 'null' ], 'Either TDBMService::MODE_ARRAY or TDBMService::MODE_CURSOR (for large datasets). Defaults to TDBMService::MODE_ARRAY.');
1386-
$params[] = new ReturnTag([ '\\'.$beanNamespace.'\\'.$beanClassName.'[]', '\\'.ResultIterator::class ]);
1387-
$method->setReturnType('\\'.ResultIterator::class);
1374+
$method->setReturnType($this->resultIteratorNamespace . '\\' . $this->getResultIteratorClassName());
13881375

13891376
$docBlock = new DocBlockGenerator("Get a list of $beanClassName filtered by ".implode(', ', $commentArguments).".", null, $params);
13901377
$docBlock->setWordWrap(false);

src/Utils/TDBMDaoGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private function psr2Fix(string $content): string
282282
/**
283283
* Writes the PHP ResultIterator file with typed accessors.
284284
*/
285-
private function generateResultIterator(BeanDescriptor $beanDescriptor)
285+
private function generateResultIterator(BeanDescriptor $beanDescriptor) : void
286286
{
287287
$resultIteratorClassName = $beanDescriptor->getResultIteratorClassName();
288288
$resultIteratorBaseClassName = $beanDescriptor->getBaseResultIteratorClassName();

tests/Commands/AlteredConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function testAlteredConfiguration(): void
3232
$this->assertSame($logger, $alteredConfiguration->getLogger());
3333
$this->assertSame('FooBean', $alteredConfiguration->getBeanNamespace());
3434
$this->assertSame('FooDao', $alteredConfiguration->getDaoNamespace());
35+
$this->assertSame('FooResultIterator', $alteredConfiguration->getResultIteratorNamespace());
3536
$this->assertSame($configuration->getGeneratorEventDispatcher(), $alteredConfiguration->getGeneratorEventDispatcher());
3637
$this->assertSame($schemaAnalyzer, $alteredConfiguration->getSchemaAnalyzer());
3738
$this->assertSame($configuration->getPathFinder(), $alteredConfiguration->getPathFinder());

tests/Utils/BeanDescriptorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function setUp(): void
5959
public function testConstructor(): void
6060
{
6161
$usersTable = $this->schema->getTable('users');
62-
$beanDescriptor = new BeanDescriptor($usersTable, 'Tdbm\\Test\\Beans', 'Tdbm\\Test\\Beans\\Generated', 'Tdbm\\Test\\Daos', 'Tdbm\\Test\\Daos\\Generated', 'Tdbm\\Test\\ResultIterators', 'Tdbm\\Test\\ResultIterators\\Generated', $this->schemaAnalyzer, $this->schema, $this->tdbmSchemaAnalyzer, $this->getNamingStrategy(), AnnotationParser::buildWithDefaultAnnotations([]), new BaseCodeGeneratorListener(), $this->getConfiguration(), $this->createMock(BeanRegistry::class));
62+
$beanDescriptor = new BeanDescriptor($usersTable, 'Tdbm\\Test\\Beans', 'Tdbm\\Test\\Beans\\Generated', 'Tdbm\\Test\\Daos', 'Tdbm\\Test\\Daos\\Generated', 'Tdbm\\Test\\ResultIterators', 'Tdbm\\Test\\ResultIterators\\Generated', $this->schemaAnalyzer, $this->schema, $this->tdbmSchemaAnalyzer, $this->getNamingStrategy(), AnnotationParser::buildWithDefaultAnnotations([]), new BaseCodeGeneratorListener(), $this->getConfiguration(), $this->createMock(BeanRegistry::class));
6363
$beanDescriptor->initBeanPropertyDescriptors();
6464
$propertyDescriptors = $beanDescriptor->getBeanPropertyDescriptors();
6565
$firstElem = reset($propertyDescriptors);

0 commit comments

Comments
 (0)