mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-26 11:55:00 +01:00
[DI] skip checking naming convention for env var parameters (#265)
This commit is contained in:
parent
c10e7795f4
commit
0a7b057df1
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user