Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Support PHP 8.2 true and null type #50560

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

Merged
merged 1 commit into from
Jun 5, 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
[DependencyInjection] Support PHP 8.2 true type
Add test for `null` type
  • Loading branch information
ruudk committed Jun 5, 2023
commit 3fb90e28300f3c000c321035a6ca1f8ece577b96
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
if (false === $value) {
return;
}
} elseif ('true' === $type) {
if (true === $value) {
return;
}
} elseif ($reflectionType->isBuiltin()) {
$checkFunction = sprintf('is_%s', $type);
if ($checkFunction($value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\IntersectionConstructor;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructorPHP82;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\WaldoFoo;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Wobble;
Expand Down Expand Up @@ -868,6 +869,26 @@ public function testUnionTypePassesWithFalse()
$this->addToAssertionCount(1);
}

/**
* @requires PHP 8.2
*/
public function testUnionTypePassesWithTrue()
{
$container = new ContainerBuilder();

$container->register('unionTrue', UnionConstructorPHP82::class)
->setFactory([UnionConstructorPHP82::class, 'createTrue'])
->setArguments([true]);

$container->register('unionNull', UnionConstructorPHP82::class)
->setFactory([UnionConstructorPHP82::class, 'createNull'])
->setArguments([null]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}

/**
* @requires PHP 8
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;

class UnionConstructorPHP82
{
public static function createTrue(array|true $arg): static
{
return new static(0);
}

public static function createNull(null $arg): static
{
return new static(0);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.