Skip to content

Commit

Permalink
Merge pull request #359 from Harfusha/generate-strict-annotations-fol…
Browse files Browse the repository at this point in the history
…lowup

Generate strict annotations followup
  • Loading branch information
dereuromark authored Oct 17, 2024
2 parents 49ccd37 + e8a811e commit dee3e6b
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/Annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ Tables should annotate their entity related methods, their relations and behavio
A LocationsTable class would then get the following doc block annotations added if not already present:
```php
/**
* @method \App\Model\Entity\Location get($primaryKey, array $options = [])
* @method \App\Model\Entity\Location newEmptyEntity()
* @method \App\Model\Entity\Location newEntity(array $data, array $options = [])
* @method array<\App\Model\Entity\Location> newEntities(array $data, array $options = [])
* @method \App\Model\Entity\Location get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\Location|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\Location saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\Location patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\App\Model\Entity\Location> patchEntities(iterable $entities, array $data, array $options = [])
* @method \App\Model\Entity\Location findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \App\Model\Entity\Location findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array $options = [])
* @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Location>|false saveMany(iterable $entities, array $options = [])
* @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Location> saveManyOrFail(iterable $entities, array $options = [])
* @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Location>|false deleteMany(iterable $entities, array $options = [])
Expand Down
7 changes: 6 additions & 1 deletion src/Annotator/ControllerAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ protected function getPaginationAnnotations(string $content, ?string $primaryMod

$resultSetInterfaceCollection = GenericString::generate(implode('|', $entities), '\\' . ResultSetInterface::class);

$annotations = [AnnotationFactory::createOrFail(MethodAnnotation::TAG, $resultSetInterfaceCollection, 'paginate($object = null, array $settings = [])')];
$settingsType = 'array';
if (Configure::read('IdeHelper.concreteEntitiesInParam')) {
$settingsType = 'array<string, mixed> ';
}

$annotations = [AnnotationFactory::createOrFail(MethodAnnotation::TAG, $resultSetInterfaceCollection, 'paginate(\Cake\Datasource\RepositoryInterface|\Cake\Datasource\QueryInterface|string|null $object = null, ' . $settingsType . ' $settings = [])')];

return $annotations;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Annotator/ModelAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function buildAnnotations(array $associations, string $entity, array $
$annotations[] = "@method {$fullClassNameCollection} newEntities({$dataType} \$data, {$optionsType} \$options = [])";

$annotations[] = "@method {$fullClassName} get(mixed \$primaryKey, array|string \$finder = 'all', \Psr\SimpleCache\CacheInterface|string|null \$cache = null, \Closure|string|null \$cacheKey = null, mixed ...\$args)";
$annotations[] = "@method {$fullClassName} findOrCreate(\$search, ?callable \$callback = null, {$optionsType} \$options = [])";
$annotations[] = "@method {$fullClassName} findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array \$search, ?callable \$callback = null, {$optionsType} \$options = [])";

$annotations[] = "@method {$fullClassName} patchEntity({$entityInterface} \$entity, {$dataType} \$data, {$optionsType} \$options = [])";
$annotations[] = "@method {$fullClassNameCollection} patchEntities({$itterable} \$entities, {$dataType} \$data, {$optionsType} \$options = [])";
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/DocBlockHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function buildTableAnnotations(
$annotations[] = "@method {$class} newEntity({$dataType} \$data, {$optionsType} \$options = [])";
$annotations[] = "@method {$classes} newEntities({$dataType} \$data, {$optionsType} \$options = [])";
$annotations[] = "@method {$class} get(mixed \$primaryKey, array|string \$finder = 'all', \Psr\SimpleCache\CacheInterface|string|null \$cache = null, \Closure|string|null \$cacheKey = null, mixed ...\$args)";
$annotations[] = "@method {$class} findOrCreate(\$search, ?callable \$callback = null, {$optionsType} \$options = [])";
$annotations[] = "@method {$class} findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array \$search, ?callable \$callback = null, {$optionsType} \$options = [])";
$annotations[] = "@method {$class} patchEntity({$classInterface} \$entity, {$dataType} \$data, {$optionsType} \$options = [])";
$annotations[] = "@method {$classes} patchEntities({$itterable} \$entities, {$dataType} \$data, {$optionsType} \$options = [])";
$annotations[] = "@method {$class}|false save({$classInterface} \$entity, {$optionsType} \$options = [])";
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Controller/BarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @property \TestApp\Model\Table\BarBarsTable $BarBars
* @property \MyNamespace\MyPlugin\Controller\Component\MyComponent $My
*
* @method \TestApp\Model\Entity\BarBar[]|\Cake\Datasource\ResultSetInterface<\TestApp\Model\Entity\BarBar> paginate($object = null, array $settings = [])
* @method \TestApp\Model\Entity\BarBar[]|\Cake\Datasource\ResultSetInterface<\TestApp\Model\Entity\BarBar> paginate(\Cake\Datasource\RepositoryInterface|\Cake\Datasource\QueryInterface|string|null $object = null, array $settings = [])
*/
class BarController extends AppController {

Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/BarBarsAbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @method \TestApp\Model\Entity\BarBarsAbstract newEntity(array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract[] newEntities(array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\BarBarsAbstract findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/BarBarsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @method \TestApp\Model\Entity\BarBar newEntity(array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBar[] newEntities(array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBar get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\BarBar findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\BarBar findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\BarBar patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBar[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \TestApp\Model\Entity\BarBar|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/FooTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @method \TestApp\Model\Entity\Foo saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \TestApp\Model\Entity\Foo patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \TestApp\Model\Entity\Foo[] patchEntities($entities, array $data, array $options = [])
* @method \TestApp\Model\Entity\Foo findOrCreate($search, callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\Foo findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, callable $callback = null, array $options = [])
*
* @mixin \Cake\ORM\Behavior\TimestampBehavior
* @mixin \MyNamespace\MyPlugin\Model\Behavior\MyBehavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @method \TestApp\Model\Entity\BarBarsAbstract newEntity(array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract[] newEntities(array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\BarBarsAbstract findOrCreate($search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract patchEntity(\TestApp\Model\Entity\BarBarsAbstract $entity, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract[] patchEntities(iterable<\TestApp\Model\Entity\BarBarsAbstract> $entities, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBarsAbstract|false save(\TestApp\Model\Entity\BarBarsAbstract $entity, array<string, mixed> $options = [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/Specific/BarBarsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @method \TestApp\Model\Entity\BarBar newEntity(array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar[] newEntities(array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\BarBar findOrCreate($search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar patchEntity(\TestApp\Model\Entity\BarBar $entity, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar[] patchEntities(iterable<\TestApp\Model\Entity\BarBar> $entities, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\BarBar|false save(\TestApp\Model\Entity\BarBar $entity, array<string, mixed> $options = [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/Specific/FooTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @method \TestApp\Model\Entity\Foo saveOrFail(\TestApp\Model\Entity\Foo $entity, array $options = [])
* @method \TestApp\Model\Entity\Foo patchEntity(\TestApp\Model\Entity\Foo $entity, array $data, array $options = [])
* @method \TestApp\Model\Entity\Foo[] patchEntities($entities, array $data, array $options = [])
* @method \TestApp\Model\Entity\Foo findOrCreate($search, callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\Foo findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, callable $callback = null, array $options = [])
*
* @mixin \Cake\ORM\Behavior\TimestampBehavior
* @mixin \MyNamespace\MyPlugin\Model\Behavior\MyBehavior
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/Specific/WheelsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @method \TestApp\Model\Entity\Wheel newEmptyEntity()
* @method \TestApp\Model\Entity\Wheel[] newEntities(array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\Wheel get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\Wheel findOrCreate($search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\Wheel findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\Wheel patchEntity(\TestApp\Model\Entity\Wheel $entity, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\Wheel[] patchEntities(iterable<\TestApp\Model\Entity\Wheel> $entities, array<mixed> $data, array<string, mixed> $options = [])
* @method \TestApp\Model\Entity\Wheel|false save(\TestApp\Model\Entity\Wheel $entity, array<string, mixed> $options = [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/Model/Table/WheelsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @method \TestApp\Model\Entity\Wheel newEmptyEntity()
* @method \TestApp\Model\Entity\Wheel[] newEntities(array $data, array $options = [])
* @method \TestApp\Model\Entity\Wheel get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \TestApp\Model\Entity\Wheel findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\Wheel findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array $options = [])
* @method \TestApp\Model\Entity\Wheel patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \TestApp\Model\Entity\Wheel[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \TestApp\Model\Entity\Wheel|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
Expand Down

0 comments on commit dee3e6b

Please sign in to comment.