Skip to content

Commit

Permalink
Configuration class no longer needed, pass arguments directly to serv…
Browse files Browse the repository at this point in the history
…ices
  • Loading branch information
ondrejmirtes committed Jan 21, 2025
1 parent c08cd8e commit 7417f3a
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 73 deletions.
25 changes: 14 additions & 11 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,27 @@ parametersSchema:
])

services:
-
factory: PHPStan\Symfony\Configuration(%symfony%)

# console resolver
-
factory: PHPStan\Symfony\ConsoleApplicationResolver
arguments:
consoleApplicationLoader: %symfony.consoleApplicationLoader%

# service map
symfony.serviceMapFactory:
class: PHPStan\Symfony\ServiceMapFactory
factory: PHPStan\Symfony\XmlServiceMapFactory
arguments:
containerXmlPath: %symfony.containerXmlPath%
-
factory: @symfony.serviceMapFactory::create()

# parameter map
symfony.parameterMapFactory:
class: PHPStan\Symfony\ParameterMapFactory
factory: PHPStan\Symfony\XmlParameterMapFactory
arguments:
containerXmlPath: %symfony.containerXmlPath%
-
factory: @symfony.parameterMapFactory::create()

Expand All @@ -131,16 +134,16 @@ services:

# ControllerTrait::get()/has() return type
-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface)
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Psr\Container\ContainerInterface)
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Psr\Container\ContainerInterface, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller)
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController)
factory: PHPStan\Type\Symfony\ServiceDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]

# ControllerTrait::has() type specification
Expand Down Expand Up @@ -296,20 +299,20 @@ services:

# ParameterBagInterface::get()/has() return type
-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface, 'get', 'has')
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface, 'get', 'has', %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]

# ContainerInterface::getParameter()/hasParameter() return type
-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, 'getParameter', 'hasParameter')
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Component\DependencyInjection\ContainerInterface, 'getParameter', 'hasParameter', %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]

# (Abstract)Controller::getParameter() return type
-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, 'getParameter', null)
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\AbstractController, 'getParameter', null, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null)
factory: PHPStan\Type\Symfony\ParameterDynamicReturnTypeExtension(Symfony\Bundle\FrameworkBundle\Controller\Controller, 'getParameter', null, %symfony.constantHassers%)
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
class: PHPStan\Symfony\InputBagStubFilesExtension
Expand Down
34 changes: 0 additions & 34 deletions src/Symfony/Configuration.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Symfony/ConsoleApplicationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class ConsoleApplicationResolver

private ?Application $consoleApplication = null;

public function __construct(Configuration $configuration)
public function __construct(?string $consoleApplicationLoader)
{
$this->consoleApplicationLoader = $configuration->getConsoleApplicationLoader();
$this->consoleApplicationLoader = $consoleApplicationLoader;
}

public function hasConsoleApplicationLoader(): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/XmlParameterMapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ final class XmlParameterMapFactory implements ParameterMapFactory

private ?string $containerXml = null;

public function __construct(Configuration $configuration)
public function __construct(?string $containerXmlPath)
{
$this->containerXml = $configuration->getContainerXmlPath();
$this->containerXml = $containerXmlPath;
}

public function create(): ParameterMap
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/XmlServiceMapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ final class XmlServiceMapFactory implements ServiceMapFactory

private ?string $containerXml = null;

public function __construct(Configuration $configuration)
public function __construct(?string $containerXmlPath)
{
$this->containerXml = $configuration->getContainerXmlPath();
$this->containerXml = $containerXmlPath;
}

public function create(): ServiceMap
Expand Down
5 changes: 2 additions & 3 deletions src/Type/Symfony/ParameterDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPStan\PhpDoc\TypeStringResolver;
use PHPStan\Reflection\MethodReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\ParameterMap;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
Expand Down Expand Up @@ -62,15 +61,15 @@ public function __construct(
string $className,
?string $methodGet,
?string $methodHas,
Configuration $configuration,
bool $constantHassers,
ParameterMap $symfonyParameterMap,
TypeStringResolver $typeStringResolver
)
{
$this->className = $className;
$this->methodGet = $methodGet;
$this->methodHas = $methodHas;
$this->constantHassers = $configuration->hasConstantHassers();
$this->constantHassers = $constantHassers;
$this->parameterMap = $symfonyParameterMap;
$this->typeStringResolver = $typeStringResolver;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Type/Symfony/ServiceDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\ParameterMap;
use PHPStan\Symfony\ServiceDefinition;
use PHPStan\Symfony\ServiceMap;
Expand Down Expand Up @@ -38,13 +37,13 @@ final class ServiceDynamicReturnTypeExtension implements DynamicMethodReturnType
*/
public function __construct(
string $className,
Configuration $configuration,
bool $constantHassers,
ServiceMap $symfonyServiceMap,
ParameterMap $symfonyParameterMap
)
{
$this->className = $className;
$this->constantHassers = $configuration->hasConstantHassers();
$this->constantHassers = $constantHassers;
$this->serviceMap = $symfonyServiceMap;
$this->parameterMap = $symfonyParameterMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPStan\Rules\Symfony;

use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\XmlServiceMapFactory;
use PHPStan\Testing\RuleTestCase;
use function class_exists;
Expand All @@ -17,7 +16,7 @@ final class ContainerInterfacePrivateServiceRuleFakeTest extends RuleTestCase

protected function getRule(): Rule
{
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(new Configuration([])))->create());
return new ContainerInterfacePrivateServiceRule((new XmlServiceMapFactory(null))->create());
}

public function testGetPrivateService(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPStan\Rules\Symfony;

use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\XmlServiceMapFactory;
use PHPStan\Testing\RuleTestCase;
use function class_exists;
Expand All @@ -17,7 +16,7 @@ final class ContainerInterfacePrivateServiceRuleTest extends RuleTestCase

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

public function testGetPrivateService(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Node\Printer\Printer;
use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\XmlServiceMapFactory;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\MethodTypeSpecifyingExtension;
Expand All @@ -20,7 +19,7 @@ final class ContainerInterfaceUnknownServiceRuleFakeTest extends RuleTestCase

protected function getRule(): Rule
{
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(new Configuration([])))->create(), self::getContainer()->getByType(Printer::class));
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(null))->create(), self::getContainer()->getByType(Printer::class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Node\Printer\Printer;
use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\XmlServiceMapFactory;
use PHPStan\Testing\RuleTestCase;
use function class_exists;
Expand All @@ -18,7 +17,7 @@ final class ContainerInterfaceUnknownServiceRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml'])))->create(), self::getContainer()->getByType(Printer::class));
return new ContainerInterfaceUnknownServiceRule((new XmlServiceMapFactory(__DIR__ . '/container.xml'))->create(), self::getContainer()->getByType(Printer::class));
}

public function testGetPrivateService(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Rules/Symfony/UndefinedArgumentRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Node\Printer\Printer;
use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\ConsoleApplicationResolver;
use PHPStan\Testing\RuleTestCase;

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

protected function getRule(): Rule
{
return new UndefinedArgumentRule(new ConsoleApplicationResolver(new Configuration(['consoleApplicationLoader' => __DIR__ . '/console_application_loader.php'])), self::getContainer()->getByType(Printer::class));
return new UndefinedArgumentRule(new ConsoleApplicationResolver(__DIR__ . '/console_application_loader.php'), self::getContainer()->getByType(Printer::class));
}

public function testGetArgument(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Rules/Symfony/UndefinedOptionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Node\Printer\Printer;
use PHPStan\Rules\Rule;
use PHPStan\Symfony\Configuration;
use PHPStan\Symfony\ConsoleApplicationResolver;
use PHPStan\Testing\RuleTestCase;

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

protected function getRule(): Rule
{
return new UndefinedOptionRule(new ConsoleApplicationResolver(new Configuration(['consoleApplicationLoader' => __DIR__ . '/console_application_loader.php'])), self::getContainer()->getByType(Printer::class));
return new UndefinedOptionRule(new ConsoleApplicationResolver(__DIR__ . '/console_application_loader.php'), self::getContainer()->getByType(Printer::class));
}

public function testGetArgument(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Symfony/DefaultParameterMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ final class DefaultParameterMapTest extends TestCase
*/
public function testGetParameter(string $key, callable $validator): void
{
$factory = new XmlParameterMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml']));
$factory = new XmlParameterMapFactory(__DIR__ . '/container.xml');
$validator($factory->create()->getParameter($key));
}

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

self::assertNotNull($serviceMap->getParameter('app.string'));
Expand Down
4 changes: 2 additions & 2 deletions tests/Symfony/DefaultServiceMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ final class DefaultServiceMapTest extends TestCase
*/
public function testGetService(string $id, callable $validator): void
{
$factory = new XmlServiceMapFactory(new Configuration(['containerXmlPath' => __DIR__ . '/container.xml']));
$factory = new XmlServiceMapFactory(__DIR__ . '/container.xml');
$validator($factory->create()->getService($id));
}

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

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

0 comments on commit 7417f3a

Please sign in to comment.