Skip to content

Commit 1e1812a

Browse files
authored
Fix support for symfony/property-info 7.3@beta (#274)
To test it, I forced 7.3@beta in the `composer.json`. But I didn't commit it! ``` >…re/dev/github.com/jolicode/automapper(sf7-3 *) composer show symfony/property-info name : symfony/property-info descrip. : Extracts information about PHP class' properties using metadata of popular sources keywords : doctrine, phpdoc, property, symfony, type, validator versions : * v7.3.0-BETA1 released : 2025-04-04, 3 weeks ago type : library license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText homepage : https://symfony.com source : [git] https://github.com/symfony/property-info.git 200d230d8553610ada73ac557501dc4609aad31f dist : [zip] https://api.github.com/repos/symfony/property-info/zipball/200d230d8553610ada73ac557501dc4609aad31f 200d230d8553610ada73ac557501dc4609aad31f path : /home/gregoire/dev/github.com/jolicode/automapper/vendor/symfony/property-info names : symfony/property-info support source : https://github.com/symfony/property-info/tree/v7.3.0-BETA1 autoload psr-4 Symfony\Component\PropertyInfo\ => . exclude-from-classmap requires php >=8.2 symfony/deprecation-contracts ^2.5|^3 symfony/string ^6.4|^7.0 symfony/type-info ~7.1.9|^7.2.2 requires (dev) phpdocumentor/reflection-docblock ^5.2 phpstan/phpdoc-parser ^1.0|^2.0 symfony/cache ^6.4|^7.0 symfony/dependency-injection ^6.4|^7.0 symfony/serializer ^6.4|^7.0 conflicts phpdocumentor/reflection-docblock <5.2 phpdocumentor/type-resolver <1.5.1 symfony/cache <6.4 symfony/dependency-injection <6.4 symfony/serializer <6.4 >…re/dev/github.com/jolicode/automapper(sf7-3 *) ./vendor/bin/phpunit PHPUnit 9.6.23 by Sebastian Bergmann and contributors. ............................................................... 63 / 342 ( 18%) ............................................................... 126 / 342 ( 36%) .........................................S..................... 189 / 342 ( 55%) ..........................................SSSSSSSSSSSSSSSSSSSSS 252 / 342 ( 73%) ......S.......S.....SS......................................... 315 / 342 ( 92%) ........................... 342 / 342 (100%) Time: 00:04.116, Memory: 38.00 MB OK, but incomplete, skipped, or risky tests! Tests: 342, Assertions: 1013, Skipped: 26. ```
2 parents 321cc75 + 430fb82 commit 1e1812a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- [GH#274](https://github.com/jolicode/automapper/pull/274) Fix support for Symfony 7.3
12+
1013
### Added
1114
- [GH#246](https://github.com/jolicode/automapper/pull/246) Add support for PHP 8.4
1215
- [GH#246](https://github.com/jolicode/automapper/pull/246) Add support for API Platform 4

src/Extractor/GetTypeTrait.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
use PHPStan\PhpDocParser\Parser\TokenIterator;
1414
use PHPStan\PhpDocParser\Parser\TypeParser;
1515
use PHPStan\PhpDocParser\ParserConfig;
16+
use Symfony\Component\PropertyInfo\PhpStan\NameScope;
1617
use Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory;
1718
use Symfony\Component\PropertyInfo\Type;
1819
use Symfony\Component\PropertyInfo\Util\PhpStanTypeHelper;
20+
use Symfony\Component\TypeInfo\TypeContext\TypeContext;
21+
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
1922

2023
/**
2124
* Add helper functions to extract types from a property.
@@ -58,13 +61,12 @@ private function extractFromDocBlock(string|false|null $rawDocNode, string $clas
5861
}
5962
}
6063

61-
static $nameScopeFactory = new NameScopeFactory();
6264
static $phpStanTypeHelper = new PhpStanTypeHelper();
6365

6466
$tokens = new TokenIterator($lexer->tokenize($rawDocNode));
6567
$docNode = $phpDocParser->parse($tokens);
6668
$tokens->consumeTokenType(Lexer::TOKEN_END);
67-
$nameScope = $nameScopeFactory->create($class, $declaringClass);
69+
$nameScope = $this->createNameScope($class, $declaringClass);
6870

6971
$types = [];
7072

@@ -159,4 +161,18 @@ private function resolveTypeName(string $name, \ReflectionClass $declaringClass)
159161

160162
return $name;
161163
}
164+
165+
private function createNameScope(string $class, string $declaringClass): NameScope|TypeContext
166+
{
167+
// For Symfony <=7.2. To remove when we drop support for Symfony <= 7.2
168+
if (class_exists(NameScopeFactory::class)) {
169+
static $nameScopeFactory = new NameScopeFactory();
170+
171+
return $nameScopeFactory->create($class, $declaringClass);
172+
}
173+
174+
static $typeContextFactory = new TypeContextFactory();
175+
176+
return $typeContextFactory->createFromClassName($class, $declaringClass);
177+
}
162178
}

0 commit comments

Comments
 (0)