Skip to content

Commit

Permalink
minor #51778 [Console][Form][FrameworkBundle][HttpKernel][PropertyInf…
Browse files Browse the repository at this point in the history
…o][Validator][WebProfilerBundle] Remove optional before required param (HypeMC)

This PR was merged into the 6.4 branch.

Discussion
----------

[Console][Form][FrameworkBundle][HttpKernel][PropertyInfo][Validator][WebProfilerBundle] Remove optional before required param

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT

I'm guessing this trick was used to make arguments nullable for PHP prior to 7.1, but since Symfony now requires at least PHP 8.1 it shouldn't be necessary any more. As far as I can tell there's no breaking change: https://3v4l.org/USkgi .

There are still four places that this is used, but I believe those to be intentional test cases:
https://github.com/symfony/symfony/blob/38506585012540306b4a7166a4812d35ad6b8a3c/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php#L179-L184
https://github.com/symfony/symfony/blob/38506585012540306b4a7166a4812d35ad6b8a3c/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/MultipleArgumentsOptionalScalarNotReallyOptional.php#L8-L13
https://github.com/symfony/symfony/blob/38506585012540306b4a7166a4812d35ad6b8a3c/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php#L653-L655
https://github.com/symfony/symfony/blob/38506585012540306b4a7166a4812d35ad6b8a3c/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php#L589-L598

Commits
-------

426c4e0 [FrameworkBundle][WebProfilerBundle][Console][Form][HttpKernel][PropertyInfo][Validator] Remove optional before required param
  • Loading branch information
nicolas-grekas committed Sep 29, 2023
2 parents d65c4af + 426c4e0 commit 67e53fb
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/expected-missing-return-types.diff
Original file line number Diff line number Diff line change
Expand Up @@ -13166,8 +13166,8 @@ diff --git a/src/Symfony/Component/Validator/Context/ExecutionContextInterface.p
@@ -127,5 +127,5 @@ interface ExecutionContextInterface
* @return void
*/
- public function setNode(mixed $value, ?object $object, MetadataInterface $metadata = null, string $propertyPath);
+ public function setNode(mixed $value, ?object $object, MetadataInterface $metadata = null, string $propertyPath): void;
- public function setNode(mixed $value, ?object $object, ?MetadataInterface $metadata, string $propertyPath);
+ public function setNode(mixed $value, ?object $object, ?MetadataInterface $metadata, string $propertyPath): void;

/**
@@ -136,5 +136,5 @@ interface ExecutionContextInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AutowiredServices
private EventDispatcherInterface $dispatcher;
private CacheItemPoolInterface $cachePool;

public function __construct(Reader $annotationReader = null, EventDispatcherInterface $dispatcher, CacheItemPoolInterface $cachePool)
public function __construct(?Reader $annotationReader, EventDispatcherInterface $dispatcher, CacheItemPoolInterface $cachePool)
{
$this->annotationReader = $annotationReader;
$this->dispatcher = $dispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ProfilerController
private ?ContentSecurityPolicyHandler $cspHandler;
private ?string $baseDir;

public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, ContentSecurityPolicyHandler $cspHandler = null, string $baseDir = null)
public function __construct(UrlGeneratorInterface $generator, ?Profiler $profiler, Environment $twig, array $templates, ContentSecurityPolicyHandler $cspHandler = null, string $baseDir = null)
{
$this->generator = $generator;
$this->profiler = $profiler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RouterController
*/
private iterable $expressionLanguageProviders;

public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
public function __construct(?Profiler $profiler, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null, iterable $expressionLanguageProviders = [])
{
$this->profiler = $profiler;
$this->twig = $twig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testIsGithubActionEnvironment()
/**
* @dataProvider annotationsFormatProvider
*/
public function testAnnotationsFormat(string $type, string $message, string $file = null, int $line = null, int $col = null, string $expected)
public function testAnnotationsFormat(string $type, string $message, ?string $file, ?int $line, ?int $col, string $expected)
{
$reporter = new GithubActionReporter($buffer = new BufferedOutput());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &
return $output;
}

private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash): array
private function &recursiveBuildFinalFormTree(?FormInterface $form, FormView $view, array &$outputByHash): array
{
$viewHash = spl_object_hash($view);
$formHash = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
*
* @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported
*/
public function __construct(SurrogateInterface $surrogate = null, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
public function __construct(?SurrogateInterface $surrogate, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
{
$this->surrogate = $surrogate;
$this->inlineStrategy = $inlineStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function setUp(): void
/**
* @dataProvider typesProvider
*/
public function testExtract($property, array $type = null, $shortDescription, $longDescription)
public function testExtract($property, ?array $type, $shortDescription, $longDescription)
{
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
$this->assertSame($shortDescription, $this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
Expand Down Expand Up @@ -131,7 +131,7 @@ public static function typesProvider()
/**
* @dataProvider provideCollectionTypes
*/
public function testExtractCollection($property, array $type = null, $shortDescription, $longDescription)
public function testExtractCollection($property, ?array $type, $shortDescription, $longDescription)
{
$this->testExtract($property, $type, $shortDescription, $longDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function __construct(ValidatorInterface $validator, mixed $root, Translat
$this->cachedObjectsRefs = new \SplObjectStorage();
}

public function setNode(mixed $value, ?object $object, MetadataInterface $metadata = null, string $propertyPath): void
public function setNode(mixed $value, ?object $object, ?MetadataInterface $metadata, string $propertyPath): void
{
$this->value = $value;
$this->object = $object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getObject(): ?object;
*
* @return void
*/
public function setNode(mixed $value, ?object $object, MetadataInterface $metadata = null, string $propertyPath);
public function setNode(mixed $value, ?object $object, ?MetadataInterface $metadata, string $propertyPath);

/**
* Warning: Should not be called by user code, to be used by the validator engine only.
Expand Down

0 comments on commit 67e53fb

Please sign in to comment.