Skip to content

Commit 9e9d961

Browse files
committed
Run PHPStan on latest and prefer-lowest Symfony dependencies.
Restore Symfony 5 compatibility in safeAddCommand via InstalledVersions and fix PHPStan issues exposed by older dependency resolution.
1 parent 34a2182 commit 9e9d961

5 files changed

Lines changed: 47 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,35 @@ on:
77

88
jobs:
99
phpstan:
10-
name: PHPStan
10+
name: PHPStan - PHP ${{ matrix.php }} ${{ matrix.dependency-version }}
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php: [ '8.1', '8.2', '8.3', '8.4' ]
15+
dependency-version: [ '' ]
16+
include:
17+
- php: '8.1'
18+
dependency-version: '--prefer-lowest'
1219
steps:
1320
- name: Checkout
1421
uses: actions/checkout@v6
1522

1623
- name: Setup PHP
1724
uses: shivammathur/setup-php@v2
1825
with:
19-
php-version: '8.3'
26+
php-version: ${{ matrix.php }}
2027
tools: composer:v2
2128
coverage: none
2229

2330
- name: Cache Composer dependencies
2431
uses: actions/cache@v5
2532
with:
2633
path: ~/.composer/cache
27-
key: php-composer-locked-${{ hashFiles('composer.lock') }}
28-
restore-keys: php-composer-locked-
34+
key: php-${{ matrix.php }}-composer-${{ matrix.dependency-version }}-${{ hashFiles('composer.json') }}
35+
restore-keys: php-${{ matrix.php }}-composer-${{ matrix.dependency-version }}-
2936

3037
- name: Install dependencies
31-
run: composer update --no-interaction --prefer-dist --no-progress
38+
run: composer update ${{ matrix.dependency-version }} --no-interaction --prefer-dist --no-progress
3239

3340
- name: PHPStan
3441
run: vendor/bin/phpstan analyse --no-progress

src/Application.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Aws\Exception\CredentialsException;
66
use Bref\Cli\Cli\IO;
77
use Bref\Cli\Cli\Styles;
8+
use Composer\InstalledVersions;
89
use ErrorException;
910
use Exception;
1011
use Symfony\Component\Console\Command\Command;
@@ -37,7 +38,26 @@ public function __construct()
3738

3839
public function safeAddCommand(Command $command): ?Command
3940
{
40-
return $this->addCommand($command);
41+
// addCommand() exists since Symfony Console 7.4; add() was removed in Symfony 8.
42+
$usesAddCommand = self::usesAddCommand();
43+
44+
$method = $usesAddCommand ? 'addCommand' : 'add';
45+
46+
/** @var callable(Command): ?Command $register */
47+
$register = [$this, $method];
48+
49+
return $register($command);
50+
}
51+
52+
private static function usesAddCommand(): bool
53+
{
54+
if (! class_exists(InstalledVersions::class) || ! InstalledVersions::isInstalled('symfony/console')) {
55+
throw new Exception('symfony/console is not installed');
56+
}
57+
58+
$version = InstalledVersions::getVersion('symfony/console');
59+
60+
return $version !== null && version_compare($version, '7.4.0', '>=');
4161
}
4262

4363
public function doRun(InputInterface $input, OutputInterface $output): int

src/Commands/SecretCreate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3131
{
3232
// If --app and --team are provided, we can skip loading the config file
3333
if ($input->getOption('app') && $input->getOption('team')) {
34-
/** @var string $appName */
3534
$appName = $input->getOption('app');
36-
/** @var string $team */
3735
$team = $input->getOption('team');
38-
/** @var string $environment */
3936
$environment = $input->getOption('env');
37+
if (! is_string($appName) || ! is_string($team) || ! is_string($environment)) {
38+
throw new Exception('Invalid app, team, or environment option');
39+
}
4040
} else {
4141
[
4242
'appName' => $appName,

src/Components/ServerlessFramework.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,14 @@ private function serverlessExec(string $oslsPackage, string $command, string $en
244244
}
245245

246246
/**
247-
* @param array<mixed, mixed> $outputs
248247
* @return array<string, string>
249248
*/
250-
private function cleanupCfOutputs(array $outputs): array
249+
private function cleanupCfOutputs(mixed $outputs): array
251250
{
251+
if (! is_array($outputs)) {
252+
return [];
253+
}
254+
252255
$result = [];
253256
foreach ($outputs as $name => $value) {
254257
if (! is_string($name) || ! is_string($value)) {

src/Token.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ private static function saveConfig(array $config): void
7373
private static function getConfigPath(): string
7474
{
7575
$home = $_SERVER['HOME'] ?? null;
76-
if ($home === null && isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
77-
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
76+
if ($home === null) {
77+
$homeDrive = $_SERVER['HOMEDRIVE'] ?? null;
78+
$homePath = $_SERVER['HOMEPATH'] ?? null;
79+
if (is_string($homeDrive) && is_string($homePath)) {
80+
$home = $homeDrive . $homePath;
81+
}
7882
}
7983
if (! is_string($home) || $home === '') {
8084
throw new Exception('Cannot determine home directory');

0 commit comments

Comments
 (0)