Skip to content

Commit 39ac41f

Browse files
lookymanondrejmirtes
authored andcommitted
Use camelCase config parameters (old ones still work)
1 parent d31922c commit 39ac41f

16 files changed

+86
-36
lines changed

Diff for: README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ You have to provide a path to `srcDevDebugProjectContainer.xml` or similar XML f
6161
```yaml
6262
parameters:
6363
symfony:
64-
container_xml_path: var/cache/dev/srcDevDebugProjectContainer.xml
64+
containerXmlPath: var/cache/dev/srcDevDebugProjectContainer.xml
6565
# or with Symfony 4.2+
66-
container_xml_path: var/cache/dev/srcApp_KernelDevDebugContainer.xml
66+
containerXmlPath: var/cache/dev/srcApp_KernelDevDebugContainer.xml
6767
# or with Symfony 5+
68-
container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml
68+
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
6969
# If you're using PHP config files for Symfony 5.3+, you also need this for auto-loading of `Symfony\Config`:
7070
scanDirectories:
7171
- var/cache/dev/Symfony/Config
@@ -86,7 +86,7 @@ In that case, you can disable the `::has()` method return type resolving like th
8686
```
8787
parameters:
8888
symfony:
89-
constant_hassers: false
89+
constantHassers: false
9090
```
9191

9292
Be aware that it may hide genuine errors in your application.
@@ -99,7 +99,7 @@ by providing the console application from your own application. This will allow
9999
```neon
100100
parameters:
101101
symfony:
102-
console_application_loader: tests/console-application.php
102+
consoleApplicationLoader: tests/console-application.php
103103
```
104104

105105
Symfony 4:

Diff for: extension.neon

+19-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ parameters:
66
- 'Symfony\Component\Console\Exception\InvalidArgumentException'
77
symfony:
88
container_xml_path: null
9+
containerXmlPath: null
910
constant_hassers: true
11+
constantHassers: true
1012
console_application_loader: null
13+
consoleApplicationLoader: null
1114
stubFiles:
1215
- stubs/Symfony/Bundle/FrameworkBundle/KernelBrowser.stub
1316
- stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub
@@ -53,43 +56,47 @@ parameters:
5356
parametersSchema:
5457
symfony: structure([
5558
container_xml_path: schema(string(), nullable())
59+
containerXmlPath: schema(string(), nullable())
5660
constant_hassers: bool()
61+
constantHassers: bool()
5762
console_application_loader: schema(string(), nullable())
63+
consoleApplicationLoader: schema(string(), nullable())
5864
])
5965

6066
services:
67+
-
68+
factory: PHPStan\Symfony\Configuration(%symfony%)
69+
6170
# console resolver
6271
-
6372
factory: PHPStan\Symfony\ConsoleApplicationResolver
64-
arguments:
65-
consoleApplicationLoader: %symfony.console_application_loader%
6673

6774
# service map
6875
symfony.serviceMapFactory:
6976
class: PHPStan\Symfony\ServiceMapFactory
70-
factory: PHPStan\Symfony\XmlServiceMapFactory(%symfony.container_xml_path%)
77+
factory: PHPStan\Symfony\XmlServiceMapFactory
7178
-
7279
factory: @symfony.serviceMapFactory::create()
7380

7481
# parameter map
7582
symfony.parameterMapFactory:
7683
class: PHPStan\Symfony\ParameterMapFactory
77-
factory: PHPStan\Symfony\XmlParameterMapFactory(%symfony.container_xml_path%)
84+
factory: PHPStan\Symfony\XmlParameterMapFactory
7885
-
7986
factory: @symfony.parameterMapFactory::create()
8087

8188
# ControllerTrait::get()/has() return type
8289
-
83-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, %symfony.constant_hassers%)
90+
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface)
8491
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
8592
-
86-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Psr\Container\ContainerInterface, %symfony.constant_hassers%)
93+
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Psr\Container\ContainerInterface)
8794
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
8895
-
89-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, %symfony.constant_hassers%)
96+
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller)
9097
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
9198
-
92-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, %symfony.constant_hassers%)
99+
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController)
93100
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
94101

95102
# ControllerTrait::has() type specification
@@ -233,20 +240,20 @@ services:
233240

234241
# ParameterBagInterface::get()/has() return type
235242
-
236-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface, 'get', 'has', %symfony.constant_hassers%)
243+
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface, 'get', 'has')
237244
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
238245

239246
# ContainerInterface::getParameter()/hasParameter() return type
240247
-
241-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, 'getParameter', 'hasParameter', %symfony.constant_hassers%)
248+
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, 'getParameter', 'hasParameter')
242249
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
243250

244251
# (Abstract)Controller::getParameter() return type
245252
-
246-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, 'getParameter', null, %symfony.constant_hassers%)
253+
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, 'getParameter', null)
247254
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
248255
-
249-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null, %symfony.constant_hassers%)
256+
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null)
250257
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
251258
-
252259
class: PHPStan\Symfony\InputBagStubFilesExtension

Diff for: src/Symfony/Configuration.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Symfony;
4+
5+
final class Configuration
6+
{
7+
8+
/** @var array<string, mixed> */
9+
private $parameters;
10+
11+
/**
12+
* @param array<string, mixed> $parameters
13+
*/
14+
public function __construct(array $parameters)
15+
{
16+
$this->parameters = $parameters;
17+
}
18+
19+
public function getContainerXmlPath(): ?string
20+
{
21+
return $this->parameters['containerXmlPath'] ?? $this->parameters['container_xml_path'] ?? null;
22+
}
23+
24+
public function hasConstantHassers(): bool
25+
{
26+
return $this->parameters['constantHassers'] ?? $this->parameters['constant_hassers'] ?? true;
27+
}
28+
29+
public function getConsoleApplicationLoader(): ?string
30+
{
31+
return $this->parameters['consoleApplicationLoader'] ?? $this->parameters['console_application_loader'] ?? null;
32+
}
33+
34+
}

Diff for: src/Symfony/ConsoleApplicationResolver.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ final class ConsoleApplicationResolver
1616
/** @var \Symfony\Component\Console\Application|null */
1717
private $consoleApplication;
1818

19-
public function __construct(?string $consoleApplicationLoader)
19+
public function __construct(Configuration $configuration)
2020
{
21+
$consoleApplicationLoader = $configuration->getConsoleApplicationLoader();
2122
if ($consoleApplicationLoader === null) {
2223
return;
2324
}

Diff for: src/Symfony/XmlParameterMapFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ final class XmlParameterMapFactory implements ParameterMapFactory
1010
/** @var string|null */
1111
private $containerXml;
1212

13-
public function __construct(?string $containerXml)
13+
public function __construct(Configuration $configuration)
1414
{
15-
$this->containerXml = $containerXml;
15+
$this->containerXml = $configuration->getContainerXmlPath();
1616
}
1717

1818
public function create(): ParameterMap

Diff for: src/Symfony/XmlServiceMapFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ final class XmlServiceMapFactory implements ServiceMapFactory
1313
/** @var string|null */
1414
private $containerXml;
1515

16-
public function __construct(?string $containerXml)
16+
public function __construct(Configuration $configuration)
1717
{
18-
$this->containerXml = $containerXml;
18+
$this->containerXml = $configuration->getContainerXmlPath();
1919
}
2020

2121
public function create(): ServiceMap

Diff for: src/Type/Symfony/ParameterDynamicReturnTypeExtension.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
99
use PHPStan\ShouldNotHappenException;
10+
use PHPStan\Symfony\Configuration;
1011
use PHPStan\Symfony\ParameterMap;
1112
use PHPStan\Type\ArrayType;
1213
use PHPStan\Type\BooleanType;
@@ -43,12 +44,12 @@ final class ParameterDynamicReturnTypeExtension implements DynamicMethodReturnTy
4344
/** @var \PHPStan\Symfony\ParameterMap */
4445
private $parameterMap;
4546

46-
public function __construct(string $className, ?string $methodGet, ?string $methodHas, bool $constantHassers, ParameterMap $symfonyParameterMap)
47+
public function __construct(string $className, ?string $methodGet, ?string $methodHas, Configuration $configuration, ParameterMap $symfonyParameterMap)
4748
{
4849
$this->className = $className;
4950
$this->methodGet = $methodGet;
5051
$this->methodHas = $methodHas;
51-
$this->constantHassers = $constantHassers;
52+
$this->constantHassers = $configuration->hasConstantHassers();
5253
$this->parameterMap = $symfonyParameterMap;
5354
}
5455

Diff for: src/Type/Symfony/ServiceDynamicReturnTypeExtension.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
99
use PHPStan\ShouldNotHappenException;
10+
use PHPStan\Symfony\Configuration;
1011
use PHPStan\Symfony\ServiceMap;
1112
use PHPStan\Type\Constant\ConstantBooleanType;
1213
use PHPStan\Type\DynamicMethodReturnTypeExtension;
@@ -26,10 +27,10 @@ final class ServiceDynamicReturnTypeExtension implements DynamicMethodReturnType
2627
/** @var \PHPStan\Symfony\ServiceMap */
2728
private $serviceMap;
2829

29-
public function __construct(string $className, bool $constantHassers, ServiceMap $symfonyServiceMap)
30+
public function __construct(string $className, Configuration $configuration, ServiceMap $symfonyServiceMap)
3031
{
3132
$this->className = $className;
32-
$this->constantHassers = $constantHassers;
33+
$this->constantHassers = $configuration->hasConstantHassers();
3334
$this->serviceMap = $symfonyServiceMap;
3435
}
3536

Diff for: tests/Rules/Symfony/ContainerInterfacePrivateServiceRuleFakeTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Rules\Symfony;
44

55
use PHPStan\Rules\Rule;
6+
use PHPStan\Symfony\Configuration;
67
use PHPStan\Symfony\XmlServiceMapFactory;
78
use PHPStan\Testing\RuleTestCase;
89

@@ -14,7 +15,7 @@ final class ContainerInterfacePrivateServiceRuleFakeTest extends RuleTestCase
1415

1516
protected function getRule(): Rule
1617
{
17-
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(null))->create());
18+
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(new Configuration([])))->create());
1819
}
1920

2021
public function testGetPrivateService(): void

Diff for: tests/Rules/Symfony/ContainerInterfacePrivateServiceRuleTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Rules\Symfony;
44

55
use PHPStan\Rules\Rule;
6+
use PHPStan\Symfony\Configuration;
67
use PHPStan\Symfony\XmlServiceMapFactory;
78
use PHPStan\Testing\RuleTestCase;
89

@@ -14,7 +15,7 @@ final class ContainerInterfacePrivateServiceRuleTest extends RuleTestCase
1415

1516
protected function getRule(): Rule
1617
{
17-
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(__DIR__ . '/container.xml'))->create());
18+
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml'])))->create());
1819
}
1920

2021
public function testGetPrivateService(): void

Diff for: tests/Rules/Symfony/ContainerInterfaceUnknownServiceRuleFakeTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\PrettyPrinter\Standard;
66
use PHPStan\Rules\Rule;
7+
use PHPStan\Symfony\Configuration;
78
use PHPStan\Symfony\XmlServiceMapFactory;
89
use PHPStan\Testing\RuleTestCase;
910
use PHPStan\Type\Symfony\ServiceTypeSpecifyingExtension;
@@ -16,7 +17,7 @@ final class ContainerInterfaceUnknownServiceRuleFakeTest extends RuleTestCase
1617

1718
protected function getRule(): Rule
1819
{
19-
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(null))->create(), new Standard());
20+
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(new Configuration([])))->create(), new Standard());
2021
}
2122

2223
/**

Diff for: tests/Rules/Symfony/ContainerInterfaceUnknownServiceRuleTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\PrettyPrinter\Standard;
66
use PHPStan\Rules\Rule;
7+
use PHPStan\Symfony\Configuration;
78
use PHPStan\Symfony\XmlServiceMapFactory;
89
use PHPStan\Testing\RuleTestCase;
910

@@ -15,7 +16,7 @@ final class ContainerInterfaceUnknownServiceRuleTest extends RuleTestCase
1516

1617
protected function getRule(): Rule
1718
{
18-
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(__DIR__ . '/container.xml'))->create(), new Standard());
19+
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml'])))->create(), new Standard());
1920
}
2021

2122
public function testGetPrivateService(): void

Diff for: tests/Rules/Symfony/UndefinedArgumentRuleTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\PrettyPrinter\Standard;
66
use PHPStan\Rules\Rule;
7+
use PHPStan\Symfony\Configuration;
78
use PHPStan\Symfony\ConsoleApplicationResolver;
89
use PHPStan\Testing\RuleTestCase;
910

@@ -15,7 +16,7 @@ final class UndefinedArgumentRuleTest extends RuleTestCase
1516

1617
protected function getRule(): Rule
1718
{
18-
return new UndefinedArgumentRule(new ConsoleApplicationResolver(__DIR__ . '/console_application_loader.php'), new Standard());
19+
return new UndefinedArgumentRule(new ConsoleApplicationResolver(new Configuration(['consoleApplicationLoader' => __DIR__ . '/console_application_loader.php'])), new Standard());
1920
}
2021

2122
public function testGetArgument(): void

Diff for: tests/Rules/Symfony/UndefinedOptionRuleTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\PrettyPrinter\Standard;
66
use PHPStan\Rules\Rule;
7+
use PHPStan\Symfony\Configuration;
78
use PHPStan\Symfony\ConsoleApplicationResolver;
89
use PHPStan\Testing\RuleTestCase;
910

@@ -15,7 +16,7 @@ final class UndefinedOptionRuleTest extends RuleTestCase
1516

1617
protected function getRule(): Rule
1718
{
18-
return new UndefinedOptionRule(new ConsoleApplicationResolver(__DIR__ . '/console_application_loader.php'), new Standard());
19+
return new UndefinedOptionRule(new ConsoleApplicationResolver(new Configuration(['consoleApplicationLoader' => __DIR__ . '/console_application_loader.php'])), new Standard());
1920
}
2021

2122
public function testGetArgument(): void

Diff for: tests/Symfony/DefaultParameterMapTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ final class DefaultParameterMapTest extends TestCase
1313
*/
1414
public function testGetParameter(string $key, callable $validator): void
1515
{
16-
$factory = new XmlParameterMapFactory(__DIR__ . '/container.xml');
16+
$factory = new XmlParameterMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml']));
1717
$validator($factory->create()->getParameter($key));
1818
}
1919

2020
public function testGetParameterEscapedPath(): void
2121
{
22-
$factory = new XmlParameterMapFactory(__DIR__ . '/containers/bugfix%2Fcontainer.xml');
22+
$factory = new XmlParameterMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/containers/bugfix%2Fcontainer.xml']));
2323
$serviceMap = $factory->create();
2424

2525
self::assertNotNull($serviceMap->getParameter('app.string'));

Diff for: tests/Symfony/DefaultServiceMapTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ final class DefaultServiceMapTest extends TestCase
1313
*/
1414
public function testGetService(string $id, callable $validator): void
1515
{
16-
$factory = new XmlServiceMapFactory(__DIR__ . '/container.xml');
16+
$factory = new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml']));
1717
$validator($factory->create()->getService($id));
1818
}
1919

2020
public function testGetContainerEscapedPath(): void
2121
{
22-
$factory = new XmlServiceMapFactory(__DIR__ . '/containers/bugfix%2Fcontainer.xml');
22+
$factory = new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/containers/bugfix%2Fcontainer.xml']));
2323
$serviceMap = $factory->create();
2424

2525
self::assertNotNull($serviceMap->getService('withClass'));

0 commit comments

Comments
 (0)