[DI] skip checking naming convention for env var parameters (#265)

This commit is contained in:
Farhad Safarov 2022-06-16 09:08:57 +03:00 committed by GitHub
parent c10e7795f4
commit 0a7b057df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -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
*/

View File

@ -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
"""
<?php
class SomeController
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
public function __invoke(): void
{
$this->container->getParameter('env(SOME_ENV_VAR)');
}
}
"""
When I run Psalm
Then I see no errors