Skip to content

Commit

Permalink
Introduce PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jan 11, 2021
1 parent 5158b45 commit a040209
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/tests export-ignore
/phpcs.xml.dist export-ignore
/phpstan.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.github export-ignore
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Static Analysis"

on:
pull_request:
push:
branches:
- "master"

jobs:
static-analysis-phpstan:
name: "Static Analysis with PHPStan"
runs-on: "ubuntu-20.04"

strategy:
matrix:
php-version:
- "7.2"

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

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: "cs2pr"
extensions: pdo_sqlite

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ phpunit.xml
composer.lock
.idea/
phpcs.xml
phpstan.xml
.phpcs-cache
/doc/_build/*
/.phpunit.result.cache
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"doctrine/phpcr-odm": "^1.3|^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.1.5",
"ocramius/proxy-manager": "^1.0|^2.0",
"phpstan/phpstan": "^0.12.65",
"phpunit/phpunit": "^8.0||^9.0",
"psr/container": "^1.0",
"symfony/dependency-injection": "^3.0|^4.0|^5.0",
Expand Down
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Class JMS\\\\Serializer\\\\Handler\\\\iterable not found\\.$#"
count: 2
path: src/Handler/IteratorHandler.php

-
message: "#^Variable \\$previousEntityLoaderState might not be defined\\.$#"
count: 1
path: src/XmlDeserializationVisitor.php

13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
level: 1

ignoreErrors:
- '~Class Doctrine\\ODM\\MongoDB\\PersistentCollection not found~'
- '~Class Symfony\\Component\\Translation\\TranslatorInterface not found~'

paths:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests

includes:
- phpstan-baseline.neon
5 changes: 4 additions & 1 deletion src/Handler/FormErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface as TranslatorContract;

use function get_class;

final class FormErrorHandler implements SubscribingHandlerInterface
{
/**
Expand Down Expand Up @@ -53,7 +55,8 @@ public function __construct(?object $translator = null, string $translationDomai
'The first argument passed to %s must be instance of %s or %s, %s given',
self::class,
TranslatorInterface::class,
TranslatorContract::class
TranslatorContract::class,
get_class($translator)
));
}

Expand Down
4 changes: 0 additions & 4 deletions src/XmlSerializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@ public function getCurrentMetadata(): ?PropertyMetadata

public function getDocument(): \DOMDocument
{
if (null === $this->document) {
$this->document = $this->createDocument();
}

return $this->document;
}

Expand Down
4 changes: 0 additions & 4 deletions tests/Metadata/Driver/BaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,6 @@ public function testExcludePropertyNoPublicAccessorException()
{
$first = $this->getDriver()->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\ExcludePublicAccessor'));

if ($this instanceof PhpDriverTest) {
return;
}

self::assertArrayHasKey('id', $first->propertyMetadata);
self::assertArrayNotHasKey('iShallNotBeAccessed', $first->propertyMetadata);
}
Expand Down

0 comments on commit a040209

Please sign in to comment.