Skip to content

Commit c1627fc

Browse files
committed
Fix nonexistent InputBag on Symfony 4.x
1 parent 390cfa1 commit c1627fc

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": "^7.1 || ^8.0",
1717
"ext-simplexml": "*",
18-
"phpstan/phpstan": "^0.12.97"
18+
"phpstan/phpstan": "^0.12.98"
1919
},
2020
"conflict": {
2121
"symfony/framework-bundle": "<3.0"

extension.neon

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ parameters:
2525
- stubs/Symfony/Component/Form/FormView.stub
2626
- stubs/Symfony/Component/HttpFoundation/Cookie.stub
2727
- stubs/Symfony/Component/HttpFoundation/HeaderBag.stub
28-
- stubs/Symfony/Component/HttpFoundation/InputBag.stub
2928
- stubs/Symfony/Component/HttpFoundation/ParameterBag.stub
30-
- stubs/Symfony/Component/HttpFoundation/Request.stub
3129
- stubs/Symfony/Component/HttpFoundation/Session.stub
3230
- stubs/Symfony/Component/Process/Process.stub
3331
- stubs/Symfony/Component/PropertyAccess/PropertyPathInterface.stub
@@ -245,3 +243,7 @@ services:
245243
-
246244
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null, %symfony.constant_hassers%)
247245
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
246+
-
247+
class: PHPStan\Symfony\InputBagStubFilesExtension
248+
tags:
249+
- phpstan.stubFilesExtension
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Symfony;
4+
5+
use PHPStan\PhpDoc\StubFilesExtension;
6+
7+
class InputBagStubFilesExtension implements StubFilesExtension
8+
{
9+
10+
public function getFiles(): array
11+
{
12+
if (!class_exists('Symfony\Component\HttpFoundation\InputBag')) {
13+
return [];
14+
}
15+
16+
return [
17+
__DIR__ . '/../../stubs/Symfony/Component/HttpFoundation/InputBag.stub',
18+
__DIR__ . '/../../stubs/Symfony/Component/HttpFoundation/Request.stub',
19+
];
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules;
4+
5+
use PHPStan\Rules\Methods\CallMethodsRule;
6+
use PHPStan\Testing\RuleTestCase;
7+
8+
/**
9+
* @extends RuleTestCase<CallMethodsRule>
10+
*/
11+
class NonexistentInputBagClassTest extends RuleTestCase
12+
{
13+
14+
protected function getRule(): \PHPStan\Rules\Rule
15+
{
16+
return self::getContainer()->getByType(CallMethodsRule::class);
17+
}
18+
19+
public function testInputBag(): void
20+
{
21+
$this->analyse([__DIR__ . '/data/input_bag.php'], []);
22+
}
23+
24+
public static function getAdditionalConfigFiles(): array
25+
{
26+
return [
27+
__DIR__ . '/../../extension.neon',
28+
__DIR__ . '/../../rules.neon',
29+
];
30+
}
31+
32+
}

tests/Rules/data/input_bag.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace InputBagTest;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
use Symfony\Component\Routing\Annotation\Route;
9+
10+
class TestController extends AbstractController
11+
{
12+
/**
13+
* @Route("/test", name="test")
14+
*/
15+
public function index(Request $request): Response
16+
{
17+
$foo = $request->query->get('foo');
18+
19+
return $this->render('test/index.html.twig', [
20+
'controller_name' => 'TestController',
21+
]);
22+
}
23+
}

0 commit comments

Comments
 (0)