Skip to content

Commit

Permalink
Synchronize psalm-annotations with yiisoft/data package (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Oct 26, 2020
1 parent f9d5de8 commit 802bd2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 43 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -33,9 +33,9 @@
"yiisoft/yii-console": "@dev"
},
"require-dev": {
"infection/infection": "^0.16.4",
"infection/infection": "^0.18.2",
"phpunit/phpunit": "^9.4",
"vimeo/psalm": "^3.16",
"vimeo/psalm": "^4.0",
"yiisoft/test-support": "^3.0@dev"
},
"autoload": {
Expand Down
76 changes: 35 additions & 41 deletions src/DataReader/SelectDataReader.php
Expand Up @@ -20,9 +20,6 @@
use Yiisoft\Yii\Cycle\DataReader\Processor;
use Yiisoft\Yii\Cycle\DataReader\Processor\QueryBuilderProcessor;

/**
* @psalm-suppress MissingImmutableAnnotation
*/
final class SelectDataReader implements DataReaderInterface
{
/** @var Select|SelectQuery */
Expand Down Expand Up @@ -73,38 +70,69 @@ public function getSort(): ?Sort
return $this->sorting;
}

/**
* @psalm-mutation-free
*/
public function withLimit(int $limit): self
{
$new = clone $this;
$new->setLimit($limit);
if ($new->limit !== $limit) {
$new->limit = $limit;
$new->itemsCache = new CachedCollection();
}
return $new;
}

/**
* @psalm-mutation-free
*/
public function withOffset(int $offset): self
{
$new = clone $this;
$new->setOffset($offset);
if ($new->offset !== $offset) {
$new->offset = $offset;
$new->itemsCache = new CachedCollection();
}
return $new;
}

/**
* @psalm-mutation-free
*/
public function withSort(?Sort $sorting): self
{
$new = clone $this;
$new->setSort($sorting);
if ($new->sorting !== $sorting) {
$new->sorting = $sorting;
$new->itemsCache = new CachedCollection();
$new->oneItemCache = new CachedCollection();
}
return $new;
}

/**
* @psalm-mutation-free
*/
public function withFilter(FilterInterface $filter): self
{
$new = clone $this;
$new->setFilter($filter);
if ($new->filter !== $filter) {
$new->filter = $filter;
$new->itemsCache = new CachedCollection();
$new->oneItemCache = new CachedCollection();
}
return $new;
}

/**
* @psalm-mutation-free
*/
public function withFilterProcessors(FilterProcessorInterface ...$filterProcessors): self
{
$new = clone $this;
/** @psalm-suppress ImpureMethodCall */
$new->setFilterProcessors(...$filterProcessors);
/** @psalm-suppress ImpureMethodCall */
$new->resetCountCache();
$new->itemsCache = new CachedCollection();
$new->oneItemCache = new CachedCollection();
Expand Down Expand Up @@ -163,40 +191,6 @@ public function getSql(): string
return $this->buildQuery()->sqlStatement();
}

private function setSort(?Sort $sorting): void
{
if ($this->sorting !== $sorting) {
$this->sorting = $sorting;
$this->itemsCache = new CachedCollection();
$this->oneItemCache = new CachedCollection();
}
}

private function setLimit(?int $limit): void
{
if ($this->limit !== $limit) {
$this->limit = $limit;
$this->itemsCache = new CachedCollection();
}
}

private function setOffset(?int $offset): void
{
if ($this->offset !== $offset) {
$this->offset = $offset;
$this->itemsCache = new CachedCollection();
}
}

private function setFilter(FilterInterface $filter): void
{
if ($this->filter !== $filter) {
$this->filter = $filter;
$this->itemsCache = new CachedCollection();
$this->oneItemCache = new CachedCollection();
}
}

private function setFilterProcessors(FilterProcessorInterface ...$filterProcessors): void
{
$processors = [];
Expand Down

0 comments on commit 802bd2d

Please sign in to comment.