Skip to content

Commit

Permalink
Fix nonexistent InputBag on Symfony 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 2, 2021
1 parent 390cfa1 commit c1627fc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": "^7.1 || ^8.0",
"ext-simplexml": "*",
"phpstan/phpstan": "^0.12.97"
"phpstan/phpstan": "^0.12.98"
},
"conflict": {
"symfony/framework-bundle": "<3.0"
Expand Down
6 changes: 4 additions & 2 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ parameters:
- stubs/Symfony/Component/Form/FormView.stub
- stubs/Symfony/Component/HttpFoundation/Cookie.stub
- stubs/Symfony/Component/HttpFoundation/HeaderBag.stub
- stubs/Symfony/Component/HttpFoundation/InputBag.stub
- stubs/Symfony/Component/HttpFoundation/ParameterBag.stub
- stubs/Symfony/Component/HttpFoundation/Request.stub
- stubs/Symfony/Component/HttpFoundation/Session.stub
- stubs/Symfony/Component/Process/Process.stub
- stubs/Symfony/Component/PropertyAccess/PropertyPathInterface.stub
Expand Down Expand Up @@ -245,3 +243,7 @@ services:
-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null, %symfony.constant_hassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
class: PHPStan\Symfony\InputBagStubFilesExtension
tags:
- phpstan.stubFilesExtension
22 changes: 22 additions & 0 deletions src/Symfony/InputBagStubFilesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace PHPStan\Symfony;

use PHPStan\PhpDoc\StubFilesExtension;

class InputBagStubFilesExtension implements StubFilesExtension
{

public function getFiles(): array
{
if (!class_exists('Symfony\Component\HttpFoundation\InputBag')) {
return [];
}

return [
__DIR__ . '/../../stubs/Symfony/Component/HttpFoundation/InputBag.stub',
__DIR__ . '/../../stubs/Symfony/Component/HttpFoundation/Request.stub',
];
}

}
32 changes: 32 additions & 0 deletions tests/Rules/NonexistentInputBagClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types = 1);

namespace PHPStan\Rules;

use PHPStan\Rules\Methods\CallMethodsRule;
use PHPStan\Testing\RuleTestCase;

/**
* @extends RuleTestCase<CallMethodsRule>
*/
class NonexistentInputBagClassTest extends RuleTestCase
{

protected function getRule(): \PHPStan\Rules\Rule
{
return self::getContainer()->getByType(CallMethodsRule::class);
}

public function testInputBag(): void
{
$this->analyse([__DIR__ . '/data/input_bag.php'], []);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../extension.neon',
__DIR__ . '/../../rules.neon',
];
}

}
23 changes: 23 additions & 0 deletions tests/Rules/data/input_bag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace InputBagTest;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
*/
public function index(Request $request): Response
{
$foo = $request->query->get('foo');

return $this->render('test/index.html.twig', [
'controller_name' => 'TestController',
]);
}
}

0 comments on commit c1627fc

Please sign in to comment.