Skip to content

Commit

Permalink
[minor] Re-enable Psalm and fixed annotations (#95)
Browse files Browse the repository at this point in the history
* [minor] re-enable psalm

* Removed WeirdanDoctrinePsalmPlugin

Doctrine has added the required Psalm annotations since 2.8:
doctrine/orm#8289

* Added function-scope template for proxyResult()

Nothing actually guarantees that a TProxiedObject is provided. This local
template var somehow fixed Psalm's understanding of this method.

* Fixed CS

Co-authored-by: Kevin Bond <kevinbond@gmail.com>
  • Loading branch information
wouterj and kbond committed Dec 9, 2020
1 parent 5085bf1 commit 8511d7a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 37 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,27 +281,27 @@ jobs:
- name: Check CS
run: php php-cs-fixer.phar fix --dry-run --diff --diff-format=udiff

# static-analysis:
# name: Psalm Static Analysis
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v2.3.3
#
# - name: Setup PHP
# uses: shivammathur/setup-php@2.7.0
# with:
# php-version: 7.4
# coverage: none
#
# - name: Cache dependencies
# uses: actions/cache@v2.1.2
# with:
# path: ~/.composer/cache/files
# key: dependencies-7.4-prefer-stable-${{ hashFiles('composer.json') }}
#
# - name: Install dependencies
# run: composer update --prefer-stable --prefer-dist --no-interaction --no-suggest
#
# - name: Run static analysis
# run: vendor/bin/psalm --output-format=github
static-analysis:
name: Psalm Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2.3.3

- name: Setup PHP
uses: shivammathur/setup-php@2.7.0
with:
php-version: 7.4
coverage: none

- name: Cache dependencies
uses: actions/cache@v2.1.2
with:
path: ~/.composer/cache/files
key: dependencies-7.4-prefer-stable-${{ hashFiles('composer.json') }}

- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction --no-suggest

- name: Run static analysis
run: vendor/bin/psalm --output-format=github
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/maker-bundle": "^1.13",
"symfony/phpunit-bridge": "^5.2",
"vimeo/psalm": "^3.18|^4.0",
"weirdan/doctrine-psalm-plugin": "^0.11.3|^1.0@dev"
"vimeo/psalm": "^3.18|^4.0"
},
"config": {
"preferred-install": "dist",
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@

<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
</plugins>
</psalm>
12 changes: 9 additions & 3 deletions src/RepositoryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ public function findOneBy(array $criteria, ?array $orderBy = null): ?Proxy
}
}

return $this->proxyResult($this->repository->findOneBy(self::normalizeCriteria($criteria), $orderBy));
$result = $this->repository->findOneBy(self::normalizeCriteria($criteria), $orderBy);
if (null === $result) {
return null;
}

return $this->proxyResult($result);
}

/**
Expand All @@ -303,8 +308,9 @@ public function getClassName(): string
*
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress InvalidReturnType
* @psalm-param TProxiedObject|list<TProxiedObject> $result
* @psalm-return ($result is array ? list<Proxy<TProxiedObject>> : Proxy<TProxiedObject>)
* @template TResult of object
* @psalm-param TResult|list<TResult> $result
* @psalm-return ($result is array ? list<Proxy<TResult>> : Proxy<TResult>)
*/
private function proxyResult($result)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
final class FactoryTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/GlobalStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class GlobalStateTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ModelFactoryServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class ModelFactoryServiceTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ModelFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
final class ModelFactoryTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
final class ProxyTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/RepositoryProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
final class RepositoryProxyTest extends KernelTestCase
{
use ResetDatabase, Factories, ExpectDeprecationTrait;
use ExpectDeprecationTrait, Factories, ResetDatabase;

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/StoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
final class StoryTest extends KernelTestCase
{
use ResetDatabase, Factories;
use Factories, ResetDatabase;

/**
* @test
Expand Down

0 comments on commit 8511d7a

Please sign in to comment.