Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DI] Remove symfony/dependency-injection dependency #4796

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ jobs:
-
name: 'Detect unused dependencies'
# "default" format overrides default "github" in CI
run: vendor/bin/composer-unused --ansi --output-format=default
run: |
composer require icanhazstring/composer-unused --dev
vendor/bin/composer-unused --ansi --output-format=default
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@
"phpstan/phpdoc-parser": "^1.23",
"phpstan/phpstan": "^1.10.26",
"react/event-loop": "^1.3",
"react/socket": "^1.12",
"react/promise": "^2.10",
"react/socket": "^1.12",
"rector/extension-installer": "^0.11.2",
"rector/rector-doctrine": "dev-main",
"rector/rector-downgrade-php": "dev-main",
"rector/rector-phpunit": "dev-main",
"rector/rector-symfony": "dev-main",
"sebastian/diff": "^5.0",
"symfony/config": "^6.2",
"symfony/console": "^6.3",
"symfony/contracts": "^3.2",
"symfony/dependency-injection": "6.1.*",
"symfony/filesystem": "^6.3",
"symfony/finder": "^6.3",
"symfony/process": "^6.3",
"symplify/easy-parallel": "^11.1",
Expand All @@ -46,7 +44,6 @@
},
"require-dev": {
"cweagans/composer-patches": "^1.7.2",
"icanhazstring/composer-unused": "^0.8.5",
"nategood/httpful": "^0.3.2",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Exception\ShouldNotHappenException;
use Symfony\Contracts\Service\Attribute\Required;

final class PlainValueParser
{
Expand All @@ -33,7 +32,6 @@ public function __construct(
) {
}

#[Required]
public function autowire(
StaticDoctrineAnnotationParser $staticDoctrineAnnotationParser,
ArrayParser $arrayParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeCommonTypeNarrower;
use Rector\TypeDeclaration\NodeTypeAnalyzer\DetailedTypeAnalyzer;
use Rector\TypeDeclaration\TypeAnalyzer\GenericClassStringTypeNormalizer;
use Symfony\Contracts\Service\Attribute\Required;

/**
* @see \Rector\Tests\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapperTest
Expand All @@ -53,7 +52,6 @@ public function __construct(

// To avoid circular dependency

#[Required]
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper): void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Symfony\Contracts\Service\Attribute\Required;

/**
* @implements TypeMapperInterface<ConditionalTypeForParameter>
Expand All @@ -21,7 +20,6 @@ final class ConditionalTypeForParameterMapper implements TypeMapperInterface
{
private PHPStanStaticTypeMapper $phpStanStaticTypeMapper;

#[Required]
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper): void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Symfony\Contracts\Service\Attribute\Required;

/**
* @implements TypeMapperInterface<ConditionalType>
Expand All @@ -25,7 +24,9 @@ final class ConditionalTypeMapper implements TypeMapperInterface
{
private PHPStanStaticTypeMapper $phpStanStaticTypeMapper;

#[Required]
/**
* @api used in autowire, @todo add to lazy container or remove
*/
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper): void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeCommonTypeNarrower;
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
use Symfony\Contracts\Service\Attribute\Required;
use Webmozart\Assert\Assert;
use Webmozart\Assert\InvalidArgumentException;

Expand All @@ -60,7 +59,6 @@ public function __construct(
) {
}

#[Required]
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper): void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpAttribute\Enum\DocTagNodeState;
use Symfony\Contracts\Service\Attribute\Required;
use Webmozart\Assert\Assert;

/**
Expand All @@ -29,7 +28,6 @@ public function __construct(
) {
}

#[Required]
public function autowire(AnnotationToAttributeMapper $annotationToAttributeMapper): void
{
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpAttribute\Enum\DocTagNodeState;
use Symfony\Contracts\Service\Attribute\Required;
use Webmozart\Assert\InvalidArgumentException;

/**
Expand All @@ -28,7 +27,6 @@ final class ArrayItemNodeAnnotationToAttributeMapper implements AnnotationToAttr
/**
* Avoid circular reference
*/
#[Required]
public function autowire(AnnotationToAttributeMapper $annotationToAttributeMapper): void
{
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpAttribute\Enum\DocTagNodeState;
use Symfony\Contracts\Service\Attribute\Required;
use Webmozart\Assert\Assert;

/**
Expand All @@ -24,7 +23,6 @@ final class CurlyListNodeAnnotationToAttributeMapper implements AnnotationToAttr
/**
* Avoid circular reference
*/
#[Required]
public function autowire(AnnotationToAttributeMapper $annotationToAttributeMapper): void
{
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\AttributeArrayNameInliner;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Symfony\Contracts\Service\Attribute\Required;

/**
* @implements AnnotationToAttributeMapperInterface<DoctrineAnnotationTagValueNode>
Expand All @@ -32,7 +31,6 @@ public function __construct(
/**
* Avoid circular reference
*/
#[Required]
public function autowire(AnnotationToAttributeMapper $annotationToAttributeMapper): void
{
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
Expand Down
2 changes: 0 additions & 2 deletions packages/StaticTypeMapper/Naming/NameScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Rector\Naming\Naming\UseImportsResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Symfony\Contracts\Service\Attribute\Required;

/**
* @see https://github.com/phpstan/phpstan-src/blob/8376548f76e2c845ae047e3010e873015b796818/src/Analyser/NameScope.php#L32
Expand All @@ -40,7 +39,6 @@ public function __construct(

// This is needed to avoid circular references

#[Required]
public function autowire(PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper): void
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
'SomeClass::SOME_CONSTANT'
),

new ReplaceArgumentDefaultValue(
'Symfony\Component\DependencyInjection\Definition',
'setScope',
0,
'Symfony\Component\DependencyInjection\ContainerBuilder::SCOPE_PROTOTYPE',
false
),
new ReplaceArgumentDefaultValue('Symfony\Component\Yaml\Yaml', 'parse', 1, [
false,
false,
Expand Down
13 changes: 2 additions & 11 deletions src/Configuration/ConfigInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,18 @@
use Rector\Core\Php\PhpVersionProvider;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

final class ConfigInitializer
{
/**
* @var RectorInterface[]
*/
private array $rectors = [];

/**
* @param RewindableGenerator<RectorInterface>|RectorInterface[] $rectors
* @param RectorInterface[] $rectors
*/
public function __construct(
iterable $rectors,
private readonly array $rectors,
private readonly InitFilePathsResolver $initFilePathsResolver,
private readonly SymfonyStyle $symfonyStyle,
private readonly PhpVersionProvider $phpVersionProvider,
) {
$this->rectors = $rectors instanceof RewindableGenerator ? iterator_to_array(
$rectors->getIterator()
) : $rectors;
}

public function createConfig(string $projectDirectory): void
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Parameter/SimpleParameterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\Core\Configuration\Parameter;

use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Rector\Core\Exception\ShouldNotHappenException;
use Webmozart\Assert\Assert;

/**
Expand Down Expand Up @@ -113,6 +113,6 @@ private static function ensureParameterIsSet(string $name): void
return;
}

throw new ParameterNotFoundException($name);
throw new ShouldNotHappenException(sprintf('Parameter "%s" was not found', $name));
}
}
16 changes: 2 additions & 14 deletions src/Console/Command/ListRulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,18 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

final class ListRulesCommand extends Command
{
/**
* @var RectorInterface[]
*/
private array $rectors = [];

/**
* @param RewindableGenerator<RectorInterface>|RectorInterface[] $rectors
* @param RectorInterface[] $rectors
*/
public function __construct(
private readonly SymfonyStyle $symfonyStyle,
private readonly SkippedClassResolver $skippedClassResolver,
iterable $rectors
private readonly array $rectors
) {
parent::__construct();

if ($rectors instanceof RewindableGenerator) {
$rectors = iterator_to_array($rectors->getIterator());
}

$this->rectors = $rectors;
}

protected function configure(): void
Expand Down

This file was deleted.

Loading