Skip to content

Commit

Permalink
Add compatibility with Symfony Components v7
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Jan 1, 2024
1 parent 64690f7 commit bb29175
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"nikic/php-parser": "^4.10",
"psr/log": "^3.0",
"ramsey/uuid": "^3.9 || ^4.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/finder": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/serializer": "^5.4 || ^6.0",
"symfony/stopwatch": "^5.4 || ^6.0"
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/finder": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
"symfony/stopwatch": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
"bamarni/composer-bin-plugin": "^1.8"
},
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion docs/exclusions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ try {
$dump = reset($data);
var_export($dump);
} catch (HandlerFailedException $e) {
foreach ($e->getNestedExceptions() as $ex) {
foreach ($e->getWrappedExceptions() as $ex) {
printf('Exception -- %s >> %s%s' . $ex->getMessage(), $ex->getTraceAsString(), PHP_EOL);
};
}
Expand Down
2 changes: 1 addition & 1 deletion examples/api_analyser_run.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$dump = reset($data);
var_export($dump);
} catch (HandlerFailedException $e) {
foreach ($e->getNestedExceptions() as $ex) {
foreach ($e->getWrappedExceptions() as $ex) {
printf('Exception -- %s%s%s%s', $ex->getMessage(), PHP_EOL, $ex->getTraceAsString(), PHP_EOL);
};
}
18 changes: 15 additions & 3 deletions src/Application/DataCollector/Normalizer/NodeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

use ArrayObject;

/**
* @author Laurent Laville
* @since Release 5.4.0
Expand All @@ -27,9 +29,8 @@ final class NodeNormalizer implements NormalizerInterface
/**
* {@inheritDoc}
* @param array<string, string> $context
* @return null|array<string, mixed>
*/
public function normalize($object, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = []): float|array|ArrayObject|bool|int|string|null
{
$node = $object;
$this->attributeNamespacedName = $context['nodeAttributeNamespacedName'] ?? 'bartlett.name';
Expand Down Expand Up @@ -74,8 +75,11 @@ public function normalize($object, $format = null, array $context = [])

/**
* {@inheritDoc}
* @param mixed $data
* @param string|null $format
* @param array $context
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
if ($data instanceof Node\Expr\New_) {
$this->name = $data->class instanceof Node\Stmt\Class_ ? 'class' : (string) $data->class;
Expand Down Expand Up @@ -155,6 +159,14 @@ public function supportsNormalization($data, $format = null)
return true;
}

/**
* @link https://symfony.com/blog/new-in-symfony-6-3-performance-improvements#improved-performance-of-serializer-normalizers-denormalizers
*/
public function getSupportedTypes(?string $format): array
{
return [];
}

private function getType(Node $node): string
{
if ($this->isConstantDefineExpression($node)) {
Expand Down
10 changes: 7 additions & 3 deletions src/Presentation/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
namespace Bartlett\CompatInfo\Presentation\Console;

use Bartlett\CompatInfo\Presentation\Console\Command\AbstractCommand;
use Bartlett\CompatInfoDb\Infrastructure\Framework\Composer\InstalledVersions;

use Symfony\Component\Console\Application as SymfonyApplication;
Expand All @@ -18,7 +17,7 @@
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

use Phar;
Expand All @@ -32,7 +31,12 @@
*/
class Application extends SymfonyApplication implements ApplicationInterface
{
use ContainerAwareTrait;
protected ?ContainerInterface $container;

public function setContainer(ContainerInterface $container = null): void
{
$this->container = $container;
}

/**
* @var string
Expand Down
10 changes: 5 additions & 5 deletions src/Presentation/Console/ApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
namespace Bartlett\CompatInfo\Presentation\Console;

use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Console Application contract.
*
* @since Release 6.0.0
* @author Laurent Laville
*/
interface ApplicationInterface extends ContainerAwareInterface
interface ApplicationInterface
{
public const NAME = 'phpCompatInfo';

public function setContainer(ContainerInterface $container = null): void;

/**
* @return void
*/
public function setCommandLoader(CommandLoaderInterface $commandLoader);

/**
* Gets the name of the application.
*
* @return string
*/
public function getName();
public function getName(): string;

public function getInstalledVersion(bool $withRef = true, string $packageName = 'bartlett/php-compatinfo'): ?string;

Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/Console/Command/AnalyserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->queryBus->query($compatibilityQuery);
} catch (HandlerFailedException $e) {
$exceptions = [];
foreach ($e->getNestedExceptions() as $exception) {
foreach ($e->getWrappedExceptions() as $exception) {
$exceptions[] = $exception->getMessage()
. sprintf(' from file "%s" at line %d', $exception->getFile(), $exception->getLine());
}
Expand Down

0 comments on commit bb29175

Please sign in to comment.