Skip to content

Commit

Permalink
remove phpdoc's phpstan prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 8, 2023
1 parent 4aed5fc commit 6c25c26
Show file tree
Hide file tree
Showing 61 changed files with 401 additions and 674 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/NetteDI/IRepositoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface IRepositoryFinder
{
/**
* @phpstan-param class-string<IModel> $modelClass
* @param class-string<IModel> $modelClass
*/
public function __construct(string $modelClass, ContainerBuilder $containerBuilder, OrmExtension $extension);

Expand Down
13 changes: 7 additions & 6 deletions src/Bridges/NetteDI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Nette\Caching\Cache;
use Nette\DI\CompilerExtension;
use Nette\DI\ContainerBuilder;
use Nette\PhpGenerator\ClassType;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nextras\Dbal\IConnection;
Expand All @@ -20,7 +19,6 @@
use Nextras\Orm\Repository\IRepository;
use stdClass;
use function is_subclass_of;
use function method_exists;


/**
Expand All @@ -47,6 +45,7 @@ public function getConfigSchema(): Schema
]);
}


public function loadConfiguration(): void
{
$this->builder = $this->getContainerBuilder();
Expand Down Expand Up @@ -89,6 +88,7 @@ public function beforeCompile(): void
$this->setupDbalMapperDependencies();
}


protected function setupCache(): void
{
$cacheName = $this->prefix('cache');
Expand Down Expand Up @@ -168,10 +168,10 @@ protected function setupMetadataStorage(array $entityClassMap): void


/**
* @phpstan-param array{
* array<class-string<\Nextras\Orm\Repository\IRepository<\Nextras\Orm\Entity\IEntity>>, true>,
* array<string, class-string<\Nextras\Orm\Repository\IRepository<\Nextras\Orm\Entity\IEntity>>>,
* array<class-string<\Nextras\Orm\Entity\IEntity>, class-string<\Nextras\Orm\Repository\IRepository<\Nextras\Orm\Entity\IEntity>>>
* @param array{
* array<class-string<IRepository<IEntity>>, true>,
* array<string, class-string<IRepository<IEntity>>>,
* array<class-string<IEntity>, class-string<IRepository<IEntity>>>
* } $repositoriesConfig
*/
protected function setupModel(string $modelClass, array $repositoriesConfig): void
Expand All @@ -190,6 +190,7 @@ protected function setupModel(string $modelClass, array $repositoriesConfig): vo
]);
}


protected function initializeMetadata(bool $init): void
{
if (!$init) {
Expand Down
12 changes: 4 additions & 8 deletions src/Bridges/NetteDI/PhpDocRepositoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

class PhpDocRepositoryFinder implements IRepositoryFinder
{
/**
* @var string
* @phpstan-var class-string<IModel>
*/
/** @var class-string<IModel> */
protected $modelClass;

/** @var ContainerBuilder */
Expand Down Expand Up @@ -60,9 +57,8 @@ public function beforeCompile(): ?array


/**
* @return array<string, string>
* @phpstan-param class-string<IModel> $modelClass
* @phpstan-return array<string, class-string<IRepository<IEntity>>>
* @param class-string<IModel> $modelClass
* @return array<string, class-string<IRepository<IEntity>>>
*/
protected function findRepositories(string $modelClass): array
{
Expand All @@ -86,7 +82,7 @@ protected function findRepositories(string $modelClass): array
* @var string $name
*/
foreach ($matches as [, $type, $name]) {
/** @phpstan-var class-string<IRepository<IEntity>> $type */
/** @var class-string<IRepository<IEntity>> $type */
$type = Reflection::expandClassName($type, $modelReflection);
if (!class_exists($type)) {
throw new RuntimeException("Repository '{$type}' does not exist.");
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/NetteDI/RepositoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public function hasRepository(string $className): bool

/**
* Returns instance of repository.
* @template R of IRepository<\Nextras\Orm\Entity\IEntity>
* @phpstan-param class-string<R> $className
* @phpstan-return R
* @template R of IRepository<IEntity>
* @param class-string<R> $className
* @return R
*/
public function getRepository(string $className): IRepository
{
/** @phpstan-var R */
/** @var R */
return $this->container->getService($this->repositoryNamesMap[$className]);
}

Expand Down
39 changes: 10 additions & 29 deletions src/Collection/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@
*/
class ArrayCollection implements ICollection, MemoryCollection
{
/**
* @var callable[]
* @phpstan-var list<callable(\Traversable<E> $entities): void>
*/
/** @var list<callable(\Traversable<E> $entities): void> */
public $onEntityFetch = [];

/**
* @var IEntity[]
* @phpstan-var list<E>
*/
/** @var list<E> */
protected $data;

/** @var IRelationshipMapper|null */
Expand All @@ -44,31 +38,19 @@ class ArrayCollection implements ICollection, MemoryCollection
/** @var IEntity|null */
protected $relationshipParent;

/**
* @var Iterator<IEntity>|null
* @phpstan-var Iterator<E>|null
*/
/** @var Iterator<E>|null */
protected $fetchIterator;

/**
* @var IRepository<IEntity>
* @phpstan-var IRepository<E>
*/
/** @var IRepository<E> */
protected $repository;

/** @var ArrayCollectionHelper */
protected $helper;

/**
* @var Closure[]
* @phpstan-var array<Closure(E): ArrayExpressionResult>
*/
/** @var array<Closure(E): ArrayExpressionResult> */
protected $collectionFilter = [];

/**
* @var array
* @phpstan-var list<array{mixed, string}>
*/
/** @var list<array{mixed, string}> */
protected $collectionSorter = [];

/** @var null|array{int, int|null} */
Expand All @@ -79,9 +61,8 @@ class ArrayCollection implements ICollection, MemoryCollection


/**
* @param IEntity[] $entities
* @phpstan-param IRepository<E> $repository
* @phpstan-param list<E> $entities
* @param list<E> $entities
* @param IRepository<E> $repository
*/
public function __construct(array $entities, IRepository $repository)
{
Expand Down Expand Up @@ -199,7 +180,7 @@ public function fetchPairs(string $key = null, string $value = null): array

/**
* @param mixed[] $args
* @phpstan-return never
* @return never
* @throws MemberAccessException
*/
public function __call(string $name, array $args)
Expand All @@ -210,7 +191,7 @@ public function __call(string $name, array $args)


/**
* @phpstan-return Iterator<int, E>
* @return Iterator<int, E>
*/
public function getIterator(): Iterator
{
Expand Down
36 changes: 10 additions & 26 deletions src/Collection/DbalCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
*/
class DbalCollection implements ICollection
{
/**
* @var callable[]
* @phpstan-var list<callable(\Traversable<E> $entities): void>
*/
/** @var list<callable(\Traversable<E> $entities): void> */
public $onEntityFetch = [];

/** @var IRelationshipMapper|null */
Expand All @@ -37,16 +34,10 @@ class DbalCollection implements ICollection
/** @var IEntity|null */
protected $relationshipParent;

/**
* @var Iterator<IEntity>|null
* @phpstan-var Iterator<E>|null
*/
/** @var Iterator<E>|null */
protected $fetchIterator;

/**
* @var DbalMapper
* @phpstan-var DbalMapper<E>
*/
/** @var DbalMapper<E> */
protected $mapper;

/** @var IConnection */
Expand All @@ -64,10 +55,7 @@ class DbalCollection implements ICollection
/** @var DbalQueryBuilderHelper */
protected $helper;

/**
* @var IEntity[]|null
* @phpstan-var list<E>|null
*/
/** @var list<E>|null */
protected $result;

/** @var int|null */
Expand All @@ -78,7 +66,7 @@ class DbalCollection implements ICollection


/**
* @phpstan-param DbalMapper<E> $mapper
* @param DbalMapper<E> $mapper
*/
public function __construct(DbalMapper $mapper, IConnection $connection, QueryBuilder $queryBuilder)
{
Expand Down Expand Up @@ -129,7 +117,7 @@ public function orderBy($expression, string $direction = ICollection::ASC): ICol
$collection = clone $this;
$helper = $collection->getHelper();
if (is_array($expression) && !isset($expression[0])) {
/** @phpstan-var array<string, string> $expression */
/** @var array<string, string> $expression */
$expression = $expression; // no-op for PHPStan

foreach ($expression as $subExpression => $subDirection) {
Expand Down Expand Up @@ -164,10 +152,6 @@ public function limitBy(int $limit, int $offset = null): ICollection
}


/**
* @inheritDoc
* @phpstan-return E|null
*/
public function fetch(): ?IEntity
{
if ($this->fetchIterator === null) {
Expand Down Expand Up @@ -208,7 +192,7 @@ public function fetchPairs(string $key = null, string $value = null): array

/**
* @param mixed[] $args
* @phpstan-return never
* @return never
* @throws MemberAccessException
*/
public function __call(string $name, array $args)
Expand All @@ -219,20 +203,20 @@ public function __call(string $name, array $args)


/**
* @phpstan-return Iterator<int, E>
* @return Iterator<int, E>
*/
public function getIterator(): Iterator
{
if ($this->relationshipParent !== null && $this->relationshipMapper !== null) {
/** @phpstan-var Iterator<E> */
/** @var Iterator<E> $entityIterator */
$entityIterator = $this->relationshipMapper->getIterator($this->relationshipParent, $this);
} else {
if ($this->result === null) {
$this->execute();
}

assert(is_array($this->result));
/** @phpstan-var Iterator<E> */
/** @var Iterator<E> $entityIterator */
$entityIterator = new EntityIterator($this->result);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Collection/EmptyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ public function fetchPairs(string $key = null, string $value = null): array
}


/**
* @phpstan-return Iterator<int, E>
*/
public function getIterator(): Iterator
{
return new EmptyIterator();
Expand Down
13 changes: 3 additions & 10 deletions src/Collection/EntityIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,15 @@ class EntityIterator implements IEntityPreloadContainer, Iterator, Countable
/** @var int */
private $position = 0;

/**
* @var IEntity[]
* @phpstan-var list<IEntity>
*/
/** @var list<IEntity> */
private $iteratable;

/**
* @var array
* @phpstan-var array<string, list<mixed>>
*/
/** @var array<string, list<mixed>> */
private $preloadCache;


/**
* @param IEntity[] $data
* @phpstan-param list<IEntity> $data
* @param list<IEntity> $data
*/
public function __construct(array $data)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Functions/BaseCompareFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract protected function evaluateInPhp(mixed $sourceValue, mixed $targetValue


/**
* @phpstan-param literal-string $modifier
* @param literal-string $modifier
*/
abstract protected function evaluateInDb(
DbalExpressionResult $expression,
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/Functions/CollectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ interface CollectionFunction
* Returns a value depending on values of entity; the expression passed by args is evaluated during this method
* execution.
* Usually returns a boolean for filtering evaluation.
* @phpstan-param array<mixed> $args
* @phpstan-param IArrayAggregator<mixed>|null $aggregator
* @param array<mixed> $args
* @param IArrayAggregator<mixed>|null $aggregator
*/
public function processArrayExpression(
ArrayCollectionHelper $helper,
Expand All @@ -39,7 +39,7 @@ public function processArrayExpression(
/**
* Returns true if entity should stay in the result collection; the condition is evaluated in database and this
* method just returns appropriate Nextras Dbal's filtering expression for passed args.
* @phpstan-param array<int|string, mixed> $args
* @param array<int|string, mixed> $args
*/
public function processDbalExpression(
DbalQueryBuilderHelper $helper,
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/Functions/FetchPropertyFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function processArrayExpression(

/**
* @param string[] $expressionTokens
* @phpstan-param IArrayAggregator<mixed>|null $aggregator
* @param IArrayAggregator<mixed>|null $aggregator
*/
private function getValueByTokens(
ArrayCollectionHelper $helper,
Expand Down Expand Up @@ -327,7 +327,7 @@ private function processRelationship(
$targetMapper->getManyHasManyParameters($sourceProperty, $currentMapper);
}

/** @phpstan-var literal-string $joinAlias */
/** @var literal-string $joinAlias */
$joinAlias = DbalQueryBuilderHelper::getAlias($joinTable, array_slice($tokens, 0, $tokenIndex));
$joins[] = new DbalTableJoin(
toExpression: "%table",
Expand All @@ -346,7 +346,7 @@ private function processRelationship(
}

$targetTable = $targetMapper->getTableName();
/** @phpstan-var literal-string $targetAlias */
/** @var literal-string $targetAlias */
$targetAlias = DbalQueryBuilderHelper::getAlias($tokens[$tokenIndex], array_slice($tokens, 0, $tokenIndex));
if ($makeDistinct) {
$aggregator = $aggregator ?? new AnyAggregator();
Expand Down
Loading

0 comments on commit 6c25c26

Please sign in to comment.