Skip to content

Commit b9486ac

Browse files
committed
chore(phpstan): genericise ForbidHttpPrefixedEnvVarsRule example var names
Replace domain-specific example env var names (egress-proxy/HTTP-cache vocabulary) in the rule's error message and its test fixtures with fully generic placeholders (HTTP_API_KEY/APP_API_KEY, HTTP_CACHE_DIR/APP_CACHE_DIR, APP_FEATURE_FLAGS). This is a public, general-purpose library consumed by many unrelated projects — its examples must not carry any one consumer's domain vocabulary. No behavioural change.
1 parent e287140 commit b9486ac

6 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/PHPStan/Rules/ForbidHttpPrefixedEnvVarsRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function processNode(Node $node, Scope $scope): array
105105
'%s:%d: env var \'%s\' is consumed by Symfony but named with an HTTP_ prefix — '
106106
. 'Symfony treats HTTP_* as an HTTP request header and will NOT read it from '
107107
. '$_SERVER, so a CLI process (worker/console/cron) resolves it EMPTY. Rename it '
108-
. 'off the HTTP_ prefix (e.g. HTTP_EGRESS_PROXY -> APP_EGRESS_PROXY).',
108+
. 'off the HTTP_ prefix (e.g. HTTP_API_KEY -> APP_API_KEY).',
109109
$file,
110110
$line,
111111
$name,

tests/Small/PHPStan/Rules/ForbidHttpPrefixedEnvVarsRuleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public function offendingFixtureIsFlaggedWithEveryHttpPrefixedNameInDeterministi
5454
// PHPStan's own file/line metadata cannot point outside the file
5555
// actually being analysed (see the rule's docblock).
5656
$this->analyse([self::ASSETS . '/dummy.php'], [
57-
[$this->expectedMessage(self::ASSETS . '/offending/.env', 4, 'HTTP_EGRESS_PROXY'), 3],
58-
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 2, 'HTTP_EGRESS_PROXY'), 3],
59-
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 8, 'HTTP_EGRESS_PROXY'), 3],
60-
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 9, 'HTTP_CACHE_ROOT'), 3],
57+
[$this->expectedMessage(self::ASSETS . '/offending/.env', 4, 'HTTP_API_KEY'), 3],
58+
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 2, 'HTTP_API_KEY'), 3],
59+
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 8, 'HTTP_API_KEY'), 3],
60+
[$this->expectedMessage(self::ASSETS . '/offending/config/services.yaml', 9, 'HTTP_CACHE_DIR'), 3],
6161
]);
6262
}
6363

@@ -91,7 +91,7 @@ private function expectedMessage(string $file, int $line, string $name): string
9191
'%s:%d: env var \'%s\' is consumed by Symfony but named with an HTTP_ prefix — '
9292
. 'Symfony treats HTTP_* as an HTTP request header and will NOT read it from '
9393
. '$_SERVER, so a CLI process (worker/console/cron) resolves it EMPTY. Rename it '
94-
. 'off the HTTP_ prefix (e.g. HTTP_EGRESS_PROXY -> APP_EGRESS_PROXY).',
94+
. 'off the HTTP_ prefix (e.g. HTTP_API_KEY -> APP_API_KEY).',
9595
$file,
9696
$line,
9797
$name,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
APP_ENV=dev
2-
SITE_FETCH_EGRESS_CHANNELS=proxyA,proxyB
3-
APP_EGRESS_PROXY=http://nordegress:8888
2+
APP_FEATURE_FLAGS=flagA,flagB
3+
APP_API_KEY=abc123secret
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
parameters:
2-
env(APP_CACHE_ROOT): ''
3-
app.some_other_param: '%env(SITE_FETCH_EGRESS_CHANNELS)%'
2+
env(APP_CACHE_DIR): ''
3+
app.some_other_param: '%env(APP_FEATURE_FLAGS)%'
44

55
services:
6-
App\Service\Egress\ProxyClient:
6+
App\Service\SomeClient:
77
arguments:
8-
$proxy: '%env(APP_EGRESS_PROXY)%'
9-
$cacheRoot: '%env(string:APP_CACHE_ROOT)%'
10-
$channels: '%env(csv:SITE_FETCH_EGRESS_CHANNELS)%'
8+
$apiKey: '%env(APP_API_KEY)%'
9+
$cacheDir: '%env(string:APP_CACHE_DIR)%'
10+
$featureFlags: '%env(csv:APP_FEATURE_FLAGS)%'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Deliberately offending fixture — do NOT copy this pattern.
22
APP_ENV=dev
3-
SITE_FETCH_EGRESS_CHANNELS=proxyA,proxyB
4-
HTTP_EGRESS_PROXY=http://nordegress:8888
3+
APP_FEATURE_FLAGS=flagA,flagB
4+
HTTP_API_KEY=abc123secret
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
parameters:
2-
env(HTTP_EGRESS_PROXY): ''
3-
app.some_other_param: '%env(SITE_FETCH_EGRESS_CHANNELS)%'
2+
env(HTTP_API_KEY): ''
3+
app.some_other_param: '%env(APP_FEATURE_FLAGS)%'
44

55
services:
6-
App\Service\Egress\ProxyClient:
6+
App\Service\SomeClient:
77
arguments:
8-
$proxy: '%env(HTTP_EGRESS_PROXY)%'
9-
$cacheRoot: '%env(string:HTTP_CACHE_ROOT)%'
10-
$channels: '%env(csv:SITE_FETCH_EGRESS_CHANNELS)%'
8+
$apiKey: '%env(HTTP_API_KEY)%'
9+
$cacheDir: '%env(string:HTTP_CACHE_DIR)%'
10+
$featureFlags: '%env(csv:APP_FEATURE_FLAGS)%'

0 commit comments

Comments
 (0)