Skip to content

Commit

Permalink
Greatly simplify the PhpStan configuration (see #1948)
Browse files Browse the repository at this point in the history
Description
-----------

While trying to figure out #1940, I realized that we do not need `contao/phpstan` anymore in Contao 4.10.

Commits
-------

ab5a4cf Greatly simplify the PhpStan configuration
8baf34f Remove the phpstan/phpstan-symfony and psalm/plugin-symfony packages
d70f85f Re-add the Symfony and Doctrine plugins
  • Loading branch information
leofeyer committed Jul 21, 2020
1 parent f0fa5d5 commit e06d9f6
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 56 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@
"composer/composer": "^1.0",
"contao/easy-coding-standard": "^2.0",
"contao/monorepo-tools": "dev-master",
"contao/phpstan": "^0.12",
"contao/test-case": "^4.2",
"doctrine/event-manager": "^1.0",
"monolog/monolog": "^1.24",
"phpunit/phpunit": "^8.4",
"psalm/plugin-phpunit": "^0.9",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-symfony": "^0.12",
"psalm/plugin-phpunit": "^0.10",
"psalm/plugin-symfony": "^1.0",
"psr/event-dispatcher": "^1.0",
"slam/phpstan-extensions": "^5.0",
"symfony/browser-kit": "4.4.*",
"symfony/phpunit-bridge": "4.4.*",
"vimeo/psalm": "^3.9",
"weirdan/doctrine-psalm-plugin": "^0.10"
"weirdan/doctrine-psalm-plugin": "^0.11"
},
"extra": {
"branch-alias": {
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ protected function tagResponse(array $tags): void
return;
}

/* @phpstan-ignore-next-line */
$this->get('fos_http_cache.http.symfony_response_tagger')->addTags($tags);
}

Expand Down
4 changes: 4 additions & 0 deletions core-bundle/src/Controller/InitializeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function indexAction(): InitializeControllerResponse
$realRequest->setSession($masterRequest->getSession());
}

if (!\defined('TL_SCRIPT')) {
\define('TL_SCRIPT', '');
}

// Necessary to generate the correct base path
foreach (['REQUEST_URI', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF'] as $name) {
$realRequest->server->set(
Expand Down
1 change: 1 addition & 0 deletions core-bundle/src/Session/LazySessionAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private function startSession(): void

$this->session->start();

/* @phpstan-ignore-next-line */
if ($_SESSION instanceof self) {
throw new \RuntimeException('Unable to start the native session, $_SESSION was not replaced.');
}
Expand Down
3 changes: 3 additions & 0 deletions core-bundle/tests/Controller/FaviconControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Contao\FilesModel;
use Contao\PageModel;
use FOS\HttpCache\ResponseTagger;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -68,10 +69,12 @@ public function testSvgFavicon(): void

private function getController(string $iconPath): FaviconController
{
/** @var PageModel&MockObject $pageModel */
$pageModel = $this->mockClassWithProperties(PageModel::class);
$pageModel->id = 42;
$pageModel->favicon = 'favicon-uuid';

/** @var FilesModel&MockObject $faviconModel */
$faviconModel = $this->mockClassWithProperties(FilesModel::class);
$faviconModel->path = $iconPath;
$faviconModel->extension = substr($iconPath, -3);
Expand Down
27 changes: 20 additions & 7 deletions core-bundle/tests/Doctrine/Schema/DcaSchemaProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public function testCreatesASchema(array $dca = [], array $sql = []): void
$this->assertTrue($table->getColumn('id')->getNotnull());
$this->assertFalse($table->getColumn('id')->getFixed());

if (null !== ($default = $table->getColumn('id')->getDefault())) {
$this->assertSame(0, $default);
/** @var int|null $idDefault */
$idDefault = $table->getColumn('id')->getDefault();

if (null !== $idDefault) {
$this->assertSame(0, $idDefault);
}

$this->assertTrue($table->hasColumn('pid'));
Expand All @@ -59,8 +62,10 @@ public function testCreatesASchema(array $dca = [], array $sql = []): void
$this->assertSame(128, $table->getColumn('title')->getLength());
$this->assertSame('utf8mb4_bin', $table->getColumn('title')->getPlatformOption('collation'));

if (null !== ($default = $table->getColumn('title')->getDefault())) {
$this->assertSame('', $default);
$titleDefault = $table->getColumn('title')->getDefault();

if (null !== $titleDefault) {
$this->assertSame('', $titleDefault);
}

$this->assertTrue($table->hasColumn('uppercase'));
Expand Down Expand Up @@ -94,7 +99,13 @@ public function testCreatesASchema(array $dca = [], array $sql = []): void
$this->assertFalse($table->getColumn('price')->getFixed());
$this->assertSame(6, $table->getColumn('price')->getPrecision());
$this->assertSame(2, $table->getColumn('price')->getScale());
$this->assertSame(1.99, $table->getColumn('price')->getDefault());

/** @var float|null $priceDefault */
$priceDefault = $table->getColumn('price')->getDefault();

if (null !== $priceDefault) {
$this->assertSame(1.99, $priceDefault);
}

$this->assertTrue($table->hasColumn('thumb'));
$this->assertSame('blob', $table->getColumn('thumb')->getType()->getName());
Expand All @@ -119,8 +130,10 @@ public function testCreatesASchema(array $dca = [], array $sql = []): void
$this->assertTrue($table->getColumn('published')->getNotnull());
$this->assertTrue($table->getColumn('published')->getFixed());

if (null !== ($default = $table->getColumn('published')->getDefault())) {
$this->assertSame('', $default);
$publishedDefault = $table->getColumn('published')->getDefault();

if (null !== $publishedDefault) {
$this->assertSame('', $publishedDefault);
}
}

Expand Down
1 change: 1 addition & 0 deletions core-bundle/tests/Framework/ContaoFrameworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ public function testRegistersTheLazySessionAccessObject(): void
$framework->setContainer($this->getContainerWithContaoConfiguration());
$framework->initialize();

/* @phpstan-ignore-next-line */
$this->assertInstanceOf(LazySessionAccess::class, $_SESSION);
$this->assertInstanceOf(ArrayAttributeBag::class, $_SESSION['BE_DATA']);
$this->assertInstanceOf(ArrayAttributeBag::class, $_SESSION['FE_DATA']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Contao\System;
use Contao\Template;
use Imagine\Gd\Imagine as ImagineGd;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\NullLogger;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -1456,7 +1457,7 @@ private function setUpTestCase(\Closure $testCase): array

$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = [self::class, 'replaceFileTestInsertTag'];

// Register dummy page
/** @var PageModel&MockObject $page */
$page = $this->mockClassWithProperties(PageModel::class);
$page->language = 'en';

Expand Down
2 changes: 2 additions & 0 deletions core-bundle/tests/Mailer/ContaoMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Contao\CoreBundle\Mailer\TransportConfig;
use Contao\CoreBundle\Tests\TestCase;
use Contao\PageModel;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Mailer\Mailer;
Expand All @@ -29,6 +30,7 @@ class ContaoMailerTest extends TestCase
{
public function testSetsTransportForRequest(): void
{
/** @var PageModel&MockObject $pageModel */
$pageModel = $this->mockClassWithProperties(PageModel::class);
$pageModel->mailerTransport = 'foobar';

Expand Down
9 changes: 4 additions & 5 deletions core-bundle/tests/Routing/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ public function testDoesNotModifyTheContextIfThereIsAHostname(): void

public function testHandlesNonArrayParameters(): void
{
/* @phpstan-ignore-next-line */
$this
->getUrlGenerator($this->mockRouterWithContext(['alias' => 'foo']))
->generate('foo', 'bar')
;
$generator = $this->getUrlGenerator($this->mockRouterWithContext(['alias' => 'foo']));

/* @phpstan-ignore-next-line */
$generator->generate('foo', 'bar');
}

private function getUrlGenerator(UrlGeneratorInterface $router, bool $prependLocale = false, bool $useAutoItem = true): UrlGenerator
Expand Down
8 changes: 4 additions & 4 deletions monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ composer:
require-dev:
contao/easy-coding-standard: ^2.0
contao/monorepo-tools: dev-master
contao/phpstan: ^0.12
psalm/plugin-phpunit: ^0.9
phpstan/phpstan-phpunit: ^0.12
phpstan/phpstan-symfony: ^0.12
psalm/plugin-phpunit: ^0.10
psalm/plugin-symfony: ^1.0
slam/phpstan-extensions: ^5.0
vimeo/psalm: ^3.9
weirdan/doctrine-psalm-plugin: ^0.10
weirdan/doctrine-psalm-plugin: ^0.11

repositories:
core-bundle:
Expand Down
27 changes: 4 additions & 23 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
includes:
- vendor/contao/phpstan/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-symfony/extension.neon
Expand All @@ -11,15 +10,13 @@ rules:
- TheCodingMachine\PHPStan\Rules\Exceptions\ThrowMustBundlePreviousExceptionRule

parameters:
contao:
services_yml_path: %currentWorkingDirectory%/core-bundle/src/Resources/config/services.yml

symfony:
container_xml_path: %currentWorkingDirectory%/core-bundle/var/cache/phpstan/appContao_CoreBundle_Tests_Functional_app_AppKernelPhpstanDebugContainer.xml

dynamicConstantNames:
- BE_USER_LOGGED_IN

universalObjectCratesClasses:
- Contao\Model
- Contao\Template

excludes_analyse:
- %currentWorkingDirectory%/core-bundle/src/Resources/*
- %currentWorkingDirectory%/core-bundle/tests/Fixtures/*
Expand All @@ -34,25 +31,9 @@ parameters:
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#'
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::addDefaultsIfNotSet\(\)\.#'

# Ignore $_SESSION type errors in the lazy session access test
- '#Instanceof between array<string, mixed> and Contao\\CoreBundle\\Session\\LazySessionAccess will always evaluate to false\.#'

# Ignore the wrong return type hint of the UrlGeneratorInterface::generate() method
- '#Method Contao\\CoreBundle\\Picker\\AbstractPickerProvider::generateUrl\(\) never returns null so it can be removed from the return typehint\.#'

# Ignore constant errors due to bootstrap.php in contao/contao-phpstan (see https://github.com/contao/contao/pull/1451)
- message: '#Call to method PHPUnit\\Framework\\Assert::assert(Same|Null|True|InstanceOf)\(\) with .* will always evaluate to false\.#'
paths:
- %currentWorkingDirectory%/core-bundle/tests/Framework/ContaoFrameworkTest.php
- %currentWorkingDirectory%/core-bundle/tests/Doctrine/Schema/DcaSchemaProviderTest.php

# Ignore that $container->get() always returns false (see https://github.com/phpstan/phpstan-symfony/issues/74)
- message: '#Negated boolean expression is always (false|true)\.#'
paths:
- %currentWorkingDirectory%/core-bundle/src/Monolog/ContaoTableHandler.php
- %currentWorkingDirectory%/core-bundle/src/DependencyInjection/Compiler/*Pass.php
- %currentWorkingDirectory%/core-bundle/src/Controller/AbstractController.php

treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false
inferPrivatePropertyTypeFromConstructor: true
11 changes: 0 additions & 11 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@
<ignoreFiles>
<directory name="core-bundle/src/Resources"/>
<directory name="core-bundle/tests/Fixtures"/>
<!--
Symfony's ForwardCompatTestTrait definition makes Psalm fail with a
"Could not locate trait statement" exception, therefore we have to
ignore the RoutingTest.php file for now.
The ForwardCompatTestTrait has been removed in Symfony 5, so as
soon as we are compatible, this can be removed again.
@see https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/Test/ForwardCompatTestTrait.php
-->
<file name="core-bundle/tests/Functional/RoutingTest.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down

0 comments on commit e06d9f6

Please sign in to comment.