Skip to content

Commit

Permalink
Merge branch '2.3.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.3.x:
  Bump doctrine/.github from 5.0.0 to 5.0.1
  Set label of GH actions dependabot PRs to CI
  Bump ramsey/composer-install from 2 to 3 (#417)
  Bump actions/checkout from 3 to 4
  Pass CODECOV_TOKEN to the shared workflow
  Bump doctrine/.github from 1.5.0 to 5.0.0
  Enable dependabot
  Add tests
  Repeat closure type
  Add isNotNull to ExpressionBuilder (#408)
  • Loading branch information
derrabus committed Aug 27, 2024
2 parents 885a8f8 + 2d861b0 commit 7e9be5a
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "CI"
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@1.5.0"
uses: "doctrine/.github/.github/workflows/[email protected].1"
with:
php-version: "8.1"
2 changes: 1 addition & 1 deletion .github/workflows/composer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ on:
jobs:
composer-lint:
name: "Composer Lint"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@1.5.0"
uses: "doctrine/.github/.github/workflows/[email protected].1"
with:
php-version: "8.1"
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:
jobs:
phpunit:
name: "PHPUnit"
uses: "doctrine/.github/.github/workflows/continuous-integration.yml@1.5.0"
uses: "doctrine/.github/.github/workflows/[email protected].1"
with:
php-versions: '["8.1"]'
secrets:
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -36,7 +36,7 @@ jobs:
run: "composer require --dev phpdocumentor/guides-cli --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.5.0"
uses: "doctrine/.github/.github/workflows/[email protected].1"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:
jobs:
static-analysis:
name: "Static Analysis"
uses: "doctrine/.github/.github/workflows/static-analysis.yml@1.5.0"
uses: "doctrine/.github/.github/workflows/[email protected].1"
with:
php-version: "8.1"
10 changes: 10 additions & 0 deletions docs/en/expression-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ isNull
$collection->matching(new Criteria($expression));
isNotNull
---------

.. code-block:: php
$expressionBuilder = Criteria::expr();
$expression = $expressionBuilder->isNotNull('foo');
$collection->matching(new Criteria($expression));
in
---

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
level: 8
paths:
- src
- tests/StaticAnalysis

ignoreErrors:
# https://github.com/phpstan/phpstan-src/pull/1289
Expand Down
1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<projectFiles>
<directory name="src" />
<directory name="tests/StaticAnalysis" />
<ignoreFiles>
<directory name="vendor" />
<directory name="src/Expr"/>
Expand Down
2 changes: 2 additions & 0 deletions src/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public function reduce(Closure $func, $initial = null): mixed
/**
* {@inheritDoc}
*
* @psalm-param Closure(T, TKey):bool $p
*
* @return static
* @psalm-return static<TKey,T>
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ public function map(Closure $func): self;
/**
* {@inheritDoc}
*
* @psalm-param Closure(T, TKey):bool $p
*
* @return Collection<mixed> A collection with the results of the filter operation.
* @psalm-return Collection<TKey, T>
*/
public function filter(Closure $p): self;

/**
* {@inheritDoc}
*
* @psalm-param Closure(TKey, T):bool $p
*
* @return Collection<mixed>[] An array with two elements. The first element contains the collection
* of elements where the predicate returned TRUE, the second element
* contains the collection of elements where the predicate returned FALSE.
Expand Down
5 changes: 5 additions & 0 deletions src/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public function isNull(string $field): Comparison
return new Comparison($field, Comparison::EQ, new Value(null));
}

public function isNotNull(string $field): Comparison
{
return new Comparison($field, Comparison::NEQ, new Value(null));
}

/** @param mixed[] $values */
public function in(string $field, array $values): Comparison
{
Expand Down
8 changes: 8 additions & 0 deletions tests/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function testIsNull(): void
self::assertEquals(Comparison::EQ, $expr->getOperator());
}

public function testIsNotNull(): void
{
$expr = $this->builder->isNotNull('a');

self::assertInstanceOf(Comparison::class, $expr);
self::assertEquals(Comparison::NEQ, $expr->getOperator());
}

public function testContains(): void
{
$expr = $this->builder->contains('a', 'b');
Expand Down
46 changes: 46 additions & 0 deletions tests/StaticAnalysis/CustomCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Common\Collections\StaticAnalysis;

use Closure;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

/**
* @phpstan-template TKey of array-key
* @phpstan-template T of object
* @phpstan-implements Collection<TKey, T>
*/
abstract class CustomCollection implements Collection

Check failure on line 16 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.1)

MethodSignatureMismatch

tests/StaticAnalysis/CustomCollection.php:16:16: MethodSignatureMismatch: Method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::filter with return type '' is different to return type 'Doctrine\Common\Collections\Collection' of inherited method Doctrine\Common\Collections\Collection::filter (see https://psalm.dev/042)

Check failure on line 16 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.1)

MethodSignatureMismatch

tests/StaticAnalysis/CustomCollection.php:16:16: MethodSignatureMismatch: Method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::partition with return type '' is different to return type 'array<array-key, mixed>' of inherited method Doctrine\Common\Collections\Collection::partition (see https://psalm.dev/042)

Check failure on line 16 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.1)

MethodSignatureMismatch

tests/StaticAnalysis/CustomCollection.php:16:16: MethodSignatureMismatch: Method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::filter with return type '' is different to return type 'Doctrine\Common\Collections\ReadableCollection' of inherited method Doctrine\Common\Collections\ReadableCollection::filter (see https://psalm.dev/042)

Check failure on line 16 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.1)

MethodSignatureMismatch

tests/StaticAnalysis/CustomCollection.php:16:16: MethodSignatureMismatch: Method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::partition with return type '' is different to return type 'array<array-key, mixed>' of inherited method Doctrine\Common\Collections\ReadableCollection::partition (see https://psalm.dev/042)
{
/** @var ArrayCollection<TKey, T> */
private ArrayCollection $collection;

/** @param ArrayCollection<TKey, T> $arrayCollection */
public function __construct(ArrayCollection $arrayCollection)
{
$this->collection = $arrayCollection;
}

/**
* @psalm-param Closure(T, TKey):bool $p
*
* @return Collection<TKey, T>
*/
public function filter(Closure $p)

Check failure on line 32 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.1)

Return type mixed of method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::filter() is not covariant with return type Doctrine\Common\Collections\Collection of method Doctrine\Common\Collections\Collection::filter().

Check failure on line 32 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.1)

Method \Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::filter() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "Collection<TKey, T>".
{
return $this->collection->filter($p);
}

/**
* @psalm-param Closure(TKey, T):bool $p
*
* @psalm-return array{0: Collection<TKey, T>, 1: Collection<TKey, T>}
*/
public function partition(Closure $p)

Check failure on line 42 in tests/StaticAnalysis/CustomCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.1)

Return type mixed of method Doctrine\Tests\Common\Collections\StaticAnalysis\CustomCollection::partition() is not covariant with return type array of method Doctrine\Common\Collections\Collection::partition().
{
return $this->collection->partition($p);
}
}

0 comments on commit 7e9be5a

Please sign in to comment.