From 0a7b057df1f70749331315ea9e9f5d9694821846 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Thu, 16 Jun 2022 09:08:57 +0300 Subject: [PATCH] [DI] skip checking naming convention for env var parameters (#265) --- src/Handler/ContainerHandler.php | 11 ++++++++++- .../acceptance/NamingConventions.feature | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Handler/ContainerHandler.php b/src/Handler/ContainerHandler.php index fa16fa9..ce167fc 100644 --- a/src/Handler/ContainerHandler.php +++ b/src/Handler/ContainerHandler.php @@ -65,7 +65,7 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi if (!self::isContainerMethod($declaring_method_id, 'get')) { if (self::isContainerMethod($declaring_method_id, 'getparameter')) { $argument = $firstArg->value; - if ($argument instanceof String_ && !self::followsNamingConvention($argument->value) && false === strpos($argument->value, '\\')) { + if ($argument instanceof String_ && !self::followsParameterNamingConvention($argument->value) && false === strpos($argument->value, '\\')) { IssueBuffer::accepts( new NamingConventionViolation(new CodeLocation($statements_source, $argument)), $statements_source->getSuppressedIssues() @@ -186,6 +186,15 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi ); } + private static function followsParameterNamingConvention(string $name): bool + { + if (0 === strpos($name, 'env(')) { + return true; + } + + return self::followsNamingConvention($name); + } + /** * @see https://symfony.com/doc/current/contributing/code/standards.html#naming-conventions */ diff --git a/tests/acceptance/acceptance/NamingConventions.feature b/tests/acceptance/acceptance/NamingConventions.feature index 37e032a..a376170 100644 --- a/tests/acceptance/acceptance/NamingConventions.feature +++ b/tests/acceptance/acceptance/NamingConventions.feature @@ -105,3 +105,21 @@ Feature: Naming conventions | Type | Message | | NamingConventionViolation | Use snake_case for configuration parameter and service names | And I see no other errors + + Scenario: No parameter naming convention violation when using environment variables + Given I have the following code + """ + container->getParameter('env(SOME_ENV_VAR)'); + } + } + """ + When I run Psalm + Then I see no errors