Skip to content

Commit

Permalink
Add fixture that prefers required if found (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Jan 6, 2025
1 parent 4d9e547 commit 7b98287
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Rector\Symfony\Tests\DependencyInjection\Rector\Class_\GetBySymfonyStringToConstructorInjectionRector\Fixture;

use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class PreferRequiredSetter extends Controller
{
private EventDispatcherInterface $eventDispatcher;

/**
* @required
*/
public function autowire(
EventDispatcherInterface $eventDispatcher
) {
$this->eventDispatcher = $eventDispatcher;
}


public function configure()
{
$someType = $this->get('validator');
}
}

?>
-----
<?php

namespace Rector\Symfony\Tests\DependencyInjection\Rector\Class_\GetBySymfonyStringToConstructorInjectionRector\Fixture;

use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Validator\Validator\ValidatorInterface;

class PreferRequiredSetter extends Controller
{
private EventDispatcherInterface $eventDispatcher;

private ValidatorInterface $validator;

/**
* @required
*/
public function autowire(
EventDispatcherInterface $eventDispatcher,
ValidatorInterface $validator
) {
$this->eventDispatcher = $eventDispatcher;
$this->validator = $validator;
}


public function configure()
{
$someType = $this->validator;
}
}

?>

0 comments on commit 7b98287

Please sign in to comment.