Skip to content

Commit

Permalink
Only added container-loadable classes to specific symfony loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 15, 2020
1 parent 95e6128 commit 08ac379
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
23 changes: 17 additions & 6 deletions src/Handler/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

class ContainerHandler implements AfterMethodCallAnalysisInterface
{
const GET_CLASSLIKES = [
'Psr\Container\ContainerInterface',
'Symfony\Component\DependencyInjection\ContainerInterface',
'Symfony\Bundle\FrameworkBundle\Controller\AbstractController',
'Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait',
];

/**
* {@inheritdoc}
*/
Expand All @@ -39,11 +46,15 @@ public static function afterMethodCallAnalysis(

public static function isContainerGet(string $declaring_method_id): bool
{
return in_array($declaring_method_id, [
'Psr\Container\ContainerInterface::get',
'Symfony\Component\DependencyInjection\ContainerInterface::get',
"Symfony\Bundle\FrameworkBundle\Controller\AbstractController::get",
"Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::get",
]);
return in_array(
$declaring_method_id,
array_map(
function($c) {
return $c . '::get';
},
self::GET_CLASSLIKES
),
true
);
}
}
14 changes: 8 additions & 6 deletions src/Handler/ContainerXmlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ public static function afterClassLikeVisit(
Codebase $codebase,
array &$file_replacements = []
) {
$file_path = $statements_source->getFilePath();
$file_storage = $codebase->file_storage_provider->get($file_path);
if (\in_array($class_storage->name, ContainerHandler::GET_CLASSLIKES)) {
$file_path = $statements_source->getFilePath();
$file_storage = $codebase->file_storage_provider->get($file_path);

if (self::$containerMeta) {
foreach (self::$containerMeta->getClassNames() as $className) {
$codebase->queueClassLikeForScanning($className);
$file_storage->referenced_classlikes[strtolower($className)] = $className;
if (self::$containerMeta) {
foreach (self::$containerMeta->getClassNames() as $className) {
$codebase->queueClassLikeForScanning($className);
$file_storage->referenced_classlikes[strtolower($className)] = $className;
}
}
}
}
Expand Down

0 comments on commit 08ac379

Please sign in to comment.