Skip to content

Commit

Permalink
[All] fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jan 16, 2024
1 parent 31c26d7 commit f5043f8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
28 changes: 28 additions & 0 deletions packages/core/Reflection/ReflectionExtractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Draw\Component\Core\Reflection;

class ReflectionExtractor
{
public static function getClasses(null|\ReflectionNamedType|\ReflectionUnionType|\ReflectionIntersectionType $reflector): array
{
if ($reflector instanceof \ReflectionIntersectionType) {
throw new \InvalidArgumentException('Intersection type is not supported');
}

if (!$reflector) {
return [];
}

if ($reflector instanceof \ReflectionNamedType) {
return [$reflector->getName()];
}

$classes = [];
foreach ($reflector->getTypes() as $type) {
$classes = array_merge($classes, static::getClasses($type));
}

return array_values(array_unique($classes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;

use Draw\Component\Core\Reflection\ReflectionAccessor;
use Draw\Component\Core\Reflection\ReflectionExtractor;
use Draw\Component\Mailer\EmailComposer;
use Draw\Component\Mailer\EmailWriter\EmailWriterInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down Expand Up @@ -32,7 +33,11 @@ public function process(ContainerBuilder $container): void
$priority = 0;
}

foreach ($this->getClasses((new \ReflectionMethod($class, $methodName))->getParameters()[0]) as $emailType) {
$emailTypes = ReflectionExtractor::getClasses(
(new \ReflectionMethod($class, $methodName))->getParameters()[0]->getType()

Check failure on line 37 in packages/framework-extra-bundle/DependencyInjection/Compiler/EmailWriterCompilerPass.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $reflector of static method Draw\Component\Core\Reflection\ReflectionExtractor::getClasses() expects ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null, ReflectionType|null given.
);

foreach ($emailTypes as $emailType) {
$emailWriterListenerDefinition
->addMethodCall('addWriter', [$emailType, $id, $methodName, $priority]);
}
Expand All @@ -45,27 +50,4 @@ public function process(ContainerBuilder $container): void
ServiceLocatorTagPass::register($container, $writers)
);
}

/**
* Extract classes base on union and name type.
*
* @return array<class-string>
*/
private function getClasses(\ReflectionParameter $reflectionParameter): array
{
$type = $reflectionParameter->getType();

if ($type instanceof \ReflectionNamedType) {
return [$type->getName()];
}

if ($type instanceof \ReflectionUnionType) {
return array_map(
fn (\ReflectionNamedType $type) => $type->getName(),
$type->getTypes()
);
}

throw new \InvalidArgumentException('Unable to extract classes from parameter. Only named type and union type are supported.');
}
}
10 changes: 8 additions & 2 deletions packages/mailer/EmailComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Draw\Component\Mailer;

use Draw\Component\Core\Reflection\ReflectionAccessor;
use Draw\Component\Core\Reflection\ReflectionExtractor;
use Draw\Component\Mailer\Email\LocalizeEmailInterface;
use Draw\Component\Mailer\EmailWriter\EmailWriterInterface;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -63,8 +64,13 @@ public function registerEmailWriter(EmailWriterInterface $emailWriter): void
$priority = 0;
}

$emailType = (new \ReflectionMethod($class, $methodName))->getParameters()[0]->getClass()->name;
$this->addWriter($emailType, $emailWriter, $methodName, $priority);
$emailTypes = ReflectionExtractor::getClasses(
(new \ReflectionMethod($class, $methodName))->getParameters()[0]->getType()

Check failure on line 68 in packages/mailer/EmailComposer.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $reflector of static method Draw\Component\Core\Reflection\ReflectionExtractor::getClasses() expects ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType|null, ReflectionType|null given.
);

foreach ($emailTypes as $emailType) {
$this->addWriter($emailType, $emailWriter, $methodName, $priority);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public function extract($source, $target, ExtractionContextInterface $extraction
continue;
}

$controller = explode('::', $route->getDefault('_controller'));
$controller = $route->getDefault('_controller');

if (!\is_string($controller)) {
continue;
}

$controller = explode('::', $controller);

if (2 != \count($controller)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ private function getManagerForClass(string $class): ObjectManager
{
return $this->ormManagerRegistry?->getManagerForClass($class)
?? $this->odmManagerRegistry?->getManagerForClass($class)
?? throw new \RuntimeException('No object manager found for class ' . $class);
?? throw new \RuntimeException('No object manager found for class '.$class);
}
}
2 changes: 1 addition & 1 deletion packages/tester/Http/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function matchesDomain($domain)
{
// Remove the leading '.' as per spec in RFC 6265.
// http://tools.ietf.org/html/rfc6265#section-5.2.3
$cookieDomain = ltrim($this->getDomain(), '.');
$cookieDomain = ltrim((string) $this->getDomain(), '.');
// Domain not set or exact match.
if (!$cookieDomain || !strcasecmp($domain, $cookieDomain)) {
return true;
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
colors="true"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerDeprecations="true"
>
<php>
<ini name="memory_limit" value="4096M"/>
Expand Down

0 comments on commit f5043f8

Please sign in to comment.