Skip to content

Commit

Permalink
Add psalm and phpstan (#257)
Browse files Browse the repository at this point in the history
* Add phpstan and psalm through dev-kit

* fix phpstan and psalm issues
  • Loading branch information
jordisala1991 committed Sep 20, 2021
1 parent 020ec23 commit 0ed3f2b
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 81 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/qa.yaml
@@ -0,0 +1,62 @@
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.

name: Quality assurance

on:
push:
branches:
- 1.x
- 2.x
pull_request:

jobs:
phpstan:
name: PHPStan

runs-on: ubuntu-latest

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

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: composer:v2

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"

- name: PHPStan
run: vendor/bin/phpstan --memory-limit=1G analyse
psalm:
name: Psalm

runs-on: ubuntu-latest

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

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: composer:v2

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"

- name: Psalm
run: vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.0
14 changes: 0 additions & 14 deletions .github/workflows/qa.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Expand Up @@ -83,6 +83,10 @@ jobs:
- name: Allow unstable dependencies
run: composer config minimum-stability dev

- name: Remove dev dependencies not compatible with Symfony 6.0
if: matrix.symfony-require == '6.0.*'
run: composer remove vimeo/psalm psalm/plugin-phpunit psalm/plugin-symfony weirdan/doctrine-psalm-plugin --dev --no-update --no-interaction

- name: "Install Composer dependencies (${{ matrix.dependencies }})"
uses: "ramsey/composer-install@v1"
with:
Expand Down
18 changes: 17 additions & 1 deletion composer.json
Expand Up @@ -34,13 +34,21 @@
"require-dev": {
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.84",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.21",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^2.0",
"symfony/browser-kit": "^4.4 || ^5.3 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.3 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0",
"symfony/http-kernel": "^4.4.13 || ^5.3 || ^6.0",
"symfony/phpunit-bridge": "^5.3 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.3 || ^6.0"
"symfony/twig-bundle": "^4.4 || ^5.3 || ^6.0",
"vimeo/psalm": "^4.7.2"
},
"config": {
"sort-packages": true
Expand All @@ -60,5 +68,13 @@
"psr-4": {
"Sonata\\Twig\\Tests\\": "tests/"
}
},
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
]
}
}
21 changes: 8 additions & 13 deletions phpstan.neon.dist
@@ -1,17 +1,12 @@
parameters:
level: 1

bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
paths:
- src
# Uncomment this, when phpstan extensions are allowed
# - tests

excludes_analyse:
- src/Bridge/Symfony/Bundle/SonataTwigBundle.php
- src/Test/AbstractWidgetTestCase.php
- tests/bootstrap.php

autoload_files:
- vendor/autoload.php

ignoreErrors:
- tests
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: true
checkMissingIterableValueType: true
checkMissingVarTagTypehint: true
checkMissingTypehints: true
14 changes: 14 additions & 0 deletions psalm.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="6" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
38 changes: 23 additions & 15 deletions src/Bridge/Symfony/Bundle/SonataTwigBundle.php
Expand Up @@ -13,26 +13,34 @@

namespace Sonata\Twig\Bridge\Symfony\Bundle;

use Sonata\Twig\Bridge\Symfony\SonataTwigBundle as ForwardCompatibleSonataTwigBundle;
use Sonata\Twig\Bridge\Symfony\DependencyInjection\Compiler\StatusRendererCompilerPass;
use Sonata\Twig\Bridge\Symfony\DependencyInjection\SonataTwigExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

@trigger_error(sprintf(
'The %s\SonataTwigBundle class is deprecated since version 1.4, to be removed in 2.0. Use %s instead.',
__NAMESPACE__,
ForwardCompatibleSonataTwigBundle::class
), \E_USER_DEPRECATED);
/**
* @deprecated Since version 1.4, to be removed in 2.0. Use Sonata\Twig\Bridge\Symfony\SonataTwigBundle instead.
*/
final class SonataTwigBundle extends Bundle
{
/**
* @return string
*/
public function getPath()
{
return __DIR__.'/..';
}

public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new StatusRendererCompilerPass());
}

if (false) {
/**
* NEXT_MAJOR: remove this class.
*
* @deprecated since version 1.0, to be removed in 2.0. Use Sonata\Twig\Bridge\Symfony\SonataTwigBundle instead.
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
* @return string
*/
final class SonataTwigBundle extends Bundle
protected function getContainerExtensionClass()
{
return SonataTwigExtension::class;
}
}

class_alias(ForwardCompatibleSonataTwigBundle::class, __NAMESPACE__.'\SonataTwigBundle');
2 changes: 1 addition & 1 deletion src/Node/TemplateBoxNode.php
Expand Up @@ -20,7 +20,7 @@
final class TemplateBoxNode extends Node
{
/**
* @var int
* @var bool
*/
protected $enabled;

Expand Down
1 change: 1 addition & 0 deletions tests/App/AppKernel.php
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

final class AppKernel extends Kernel
Expand Down
36 changes: 0 additions & 36 deletions tests/Fixtures/Bundle/Serializer/FooSerializer.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/TokenParser/TemplateBoxTokenParserTest.php
Expand Up @@ -50,7 +50,7 @@ public function testCompile($enabled, $source, $expected): void
$actual->getIterator()->getFlags()
);
static::assertSame($expected->getTemplateLine(), $actual->getTemplateLine());
static::assertSame($expected->count(), $actual->count());
static::assertCount($expected->count(), $actual);
}

public function getTestsForRender()
Expand Down

0 comments on commit 0ed3f2b

Please sign in to comment.