Skip to content

Commit

Permalink
Merge branch '5.x' into fix-service-locator-int-key
Browse files Browse the repository at this point in the history
  • Loading branch information
seferov committed Jun 5, 2024
2 parents 8b490de + 2ee2ae1 commit 45b80c2
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 279 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
fail-fast: false
matrix:
php-version:
- 8.0
- 8.1
- 8.2

dependencies:
- highest
- lowest

steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
Expand All @@ -41,7 +41,7 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "Cache cache directory for vimeo/psalm"
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .build/psalm
key: php-${{ matrix.php-version }}-psalm-${{ github.sha }}
Expand All @@ -64,26 +64,20 @@ jobs:
fail-fast: false
matrix:
php-version:
- 8.0
- 8.1
- 8.2

symfony-version:
- 5
- 6
- 7

exclude:
- php-version: 8.0
symfony-version: 6
- php-version: 8.0
symfony-version: 7
- php-version: 8.1
symfony-version: 7

steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vendor/bin/psalm-plugin enable psalm/plugin-symfony

| Symfony Psalm Plugin | PHP | Symfony | Psalm |
|----------------------|------------|---------|-------|
| 5.x | ^7.4, ^8.0 | 5, 6, 7 | 5 |
| 5.x | ^8.0 | 5, 6, 7 | 5 |
| 4.x | ^7.4, ^8.0 | 4, 5, 6 | 4 |
| 3.x | ^7.1, ^8.0 | 4, 5, 6 | 4 |
| 2.x | ^7.1, ^8.0 | 4, 5 | 4 |
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-simplexml": "*",
"symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0",
"vimeo/psalm": "^5.1"
"vimeo/psalm": "^5.24"
},
"require-dev": {
"symfony/form": "^5.0 || ^6.0 || ^7.0",
"doctrine/annotations": "^1.8|^2",
"doctrine/orm": "^2.9",
"phpunit/phpunit": "~7.5 || ~9.5",
"symfony/cache-contracts": "^1.0 || ^2.0",
"symfony/console": "*",
"symfony/form": "^5.0 || ^6.0 || ^7.0",
"symfony/messenger": "^5.0 || ^6.0 || ^7.0",
"symfony/security-guard": "*",
"symfony/security-core": "*",
"symfony/serializer": "^5.0 || ^6.0 || ^7.0",
"symfony/validator": "*",
"twig/twig": "^2.10 || ^3.0",
Expand Down
15 changes: 6 additions & 9 deletions src/Handler/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi
'Symfony\Bundle\FrameworkBundle\Test\TestContainer',
];

/**
* @var ContainerMeta|null
*/
private static $containerMeta;
private static ?ContainerMeta $containerMeta = null;

/**
* @var array<string> collection of cower-cased class names that are present in the container
Expand Down Expand Up @@ -114,7 +111,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
} else {
try {
$serviceId = \constant($className.'::'.$idArgument->name->name);
} catch (\Exception $e) {
} catch (\Exception) {
return;
}
}
Expand All @@ -133,7 +130,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
}

$class = $service->getClass();
if ($class) {
if (null !== $class) {
$codebase->classlikes->addFullyQualifiedClassName($class);
$event->setReturnTypeCandidate(new Union([new TNamedObject($class)]));
}
Expand All @@ -152,15 +149,15 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
);
}
}
} catch (ServiceNotFoundException $e) {
} catch (ServiceNotFoundException) {
IssueBuffer::accepts(
new ServiceNotFound($serviceId, new CodeLocation($statements_source, $firstArg->value)),
$statements_source->getSuppressedIssues()
);
}
}

public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event)
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void
{
$codebase = $event->getCodebase();
$statements_source = $event->getStatementsSource();
Expand Down Expand Up @@ -221,7 +218,7 @@ function ($c) use ($methodName) {

private static function followsParameterNamingConvention(string $name): bool
{
if (0 === strpos($name, 'env(')) {
if (str_starts_with($name, 'env(')) {
return true;
}

Expand Down
40 changes: 20 additions & 20 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class Plugin implements PluginEntryPointInterface
{
public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config = null): void
public function __invoke(RegistrationInterface $registration, ?\SimpleXMLElement $config = null): void
{
require_once __DIR__.'/Handler/HeaderBagHandler.php';
require_once __DIR__.'/Handler/ContainerHandler.php';
Expand All @@ -39,13 +39,13 @@ public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config
require_once __DIR__.'/Handler/DoctrineQueryBuilderHandler.php';
require_once __DIR__.'/Provider/FormGetErrorsReturnTypeProvider.php';

$api->registerHooksFromClass(HeaderBagHandler::class);
$api->registerHooksFromClass(ConsoleHandler::class);
$api->registerHooksFromClass(ContainerDependencyHandler::class);
$api->registerHooksFromClass(RequiredSetterHandler::class);
$registration->registerHooksFromClass(HeaderBagHandler::class);
$registration->registerHooksFromClass(ConsoleHandler::class);
$registration->registerHooksFromClass(ContainerDependencyHandler::class);
$registration->registerHooksFromClass(RequiredSetterHandler::class);

if (class_exists(\Doctrine\ORM\QueryBuilder::class)) {
$api->registerHooksFromClass(DoctrineQueryBuilderHandler::class);
$registration->registerHooksFromClass(DoctrineQueryBuilderHandler::class);
}

if (class_exists(AnnotationRegistry::class)) {
Expand All @@ -54,10 +54,10 @@ public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config
/** @psalm-suppress DeprecatedMethod */
AnnotationRegistry::registerLoader('class_exists');
}
$api->registerHooksFromClass(DoctrineRepositoryHandler::class);
$registration->registerHooksFromClass(DoctrineRepositoryHandler::class);

require_once __DIR__.'/Handler/AnnotationHandler.php';
$api->registerHooksFromClass(AnnotationHandler::class);
$registration->registerHooksFromClass(AnnotationHandler::class);
}

if (isset($config->containerXml)) {
Expand All @@ -83,14 +83,14 @@ public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config

require_once __DIR__.'/Handler/ParameterBagHandler.php';
ParameterBagHandler::init($containerMeta);
$api->registerHooksFromClass(ParameterBagHandler::class);
$registration->registerHooksFromClass(ParameterBagHandler::class);
}

$api->registerHooksFromClass(ContainerHandler::class);
$registration->registerHooksFromClass(ContainerHandler::class);

$this->addStubs($api, __DIR__.'/Stubs/common');
$this->addStubs($api, __DIR__.'/Stubs/'.Kernel::MAJOR_VERSION);
$this->addStubs($api, __DIR__.'/Stubs/php');
$this->addStubs($registration, __DIR__.'/Stubs/common');
$this->addStubs($registration, __DIR__.'/Stubs/'.Kernel::MAJOR_VERSION);
$this->addStubs($registration, __DIR__.'/Stubs/php');

if (isset($config->twigCachePath)) {
$twig_cache_path = getcwd().DIRECTORY_SEPARATOR.ltrim((string) $config->twigCachePath, DIRECTORY_SEPARATOR);
Expand All @@ -99,15 +99,15 @@ public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config
}

require_once __DIR__.'/Twig/CachedTemplatesTainter.php';
$api->registerHooksFromClass(CachedTemplatesTainter::class);
$registration->registerHooksFromClass(CachedTemplatesTainter::class);

require_once __DIR__.'/Twig/CachedTemplatesMapping.php';
$api->registerHooksFromClass(CachedTemplatesMapping::class);
$registration->registerHooksFromClass(CachedTemplatesMapping::class);
CachedTemplatesMapping::setCachePath($twig_cache_path);
}

require_once __DIR__.'/Twig/AnalyzedTemplatesTainter.php';
$api->registerHooksFromClass(AnalyzedTemplatesTainter::class);
$registration->registerHooksFromClass(AnalyzedTemplatesTainter::class);

if (isset($config->twigRootPath)) {
$twig_root_path = trim((string) $config->twigRootPath, DIRECTORY_SEPARATOR);
Expand All @@ -119,20 +119,20 @@ public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config
TemplateFileAnalyzer::setTemplateRootPath($twig_root_path);
}

$api->registerHooksFromClass(FormGetErrorsReturnTypeProvider::class);
$registration->registerHooksFromClass(FormGetErrorsReturnTypeProvider::class);
}

private function addStubs(RegistrationInterface $api, string $path): void
private function addStubs(RegistrationInterface $registration, string $path): void
{
if (!is_dir($path)) {
// e.g. looking for stubs for version 3, but there aren't any at time of writing, so don't try and load them.
// e.g., looking for stubs for version 3, but there aren't any at time of writing, so don't try and load them.
return;
}

$a = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($a as $file) {
if (!$file->isDir()) {
$api->addStubFile($file->getPathname());
$registration->addStubFile($file->getPathname());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ interface PropertyAccessorInterface
* @psalm-param mixed $value
* @psalm-param-out T $objectOrArray
*/
public function setValue(&$objectOrArray, $propertyPath, $value);
public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value);

/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return mixed
*/
public function getValue($objectOrArray, $propertyPath);
public function getValue(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): mixed;

/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return bool
*/
public function isWritable($objectOrArray, $propertyPath);
public function isWritable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;

/**
* @param object|array $objectOrArray
* @param string|PropertyPathInterface $propertyPath
*
* @return bool
*/
public function isReadable($objectOrArray, $propertyPath);
public function isReadable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;
}

This file was deleted.

24 changes: 9 additions & 15 deletions src/Symfony/ContainerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ class ContainerMeta
/**
* @var array<string>
*/
private $classNames = [];
private array $classNames = [];

/**
* @var array<string, string>
*/
private $classLocators = [];
private array $classLocators = [];

/**
* @var array<string, array<string, string>>
*/
private $serviceLocators = [];
private array $serviceLocators = [];

/**
* @var ContainerBuilder
*/
private $container;
private ContainerBuilder $container;

public function __construct(array $containerXmlPaths)
{
Expand Down Expand Up @@ -67,10 +64,7 @@ public function get(string $id, ?string $contextClass = null): Definition
return $definition;
}

/**
* @return mixed|null
*/
public function getParameter(string $key)
public function getParameter(string $key): mixed
{
return $this->container->getParameter($key);
}
Expand Down Expand Up @@ -111,7 +105,7 @@ private function init(array $containerXmlPaths): void
$this->classLocators[$this->container->getDefinition($id)->getClass() ?? $id] = (string) $reference;
} elseif ($definition->hasTag('container.service_locator')) {
continue;
} elseif ($className = $definition->getClass()) {
} elseif (null !== $className = $definition->getClass()) {
$this->classNames[] = $className;
}
}
Expand Down Expand Up @@ -141,10 +135,10 @@ private function addServiceLocator(string $key, mixed $id, Reference $reference)
try {
$definition = $this->getDefinition((string) $reference);
$className = $definition->getClass();
if ($className) {
if (null !== $className) {
$this->classNames[] = $className;
}
} catch (ServiceNotFoundException $e) {
} catch (ServiceNotFoundException) {
}
}

Expand All @@ -158,7 +152,7 @@ private function getDefinition(string $id): Definition
} catch (ServiceNotFoundException $serviceNotFoundException) {
try {
$alias = $this->container->getAlias($id);
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
throw $serviceNotFoundException;
}

Expand Down
Loading

0 comments on commit 45b80c2

Please sign in to comment.