Skip to content

Commit 8a2da41

Browse files
committed
Replace Psalm by PHPStan
1 parent 4fc77eb commit 8a2da41

File tree

8 files changed

+48
-61
lines changed

8 files changed

+48
-61
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ jobs:
103103
if: matrix.symfony-version && contains(matrix.symfony-version, '@dev')
104104
run: composer config minimum-stability dev
105105

106-
- name: Remove friendsofphp/php-cs-fixer
107-
if: matrix.coding-standards != true
108-
run: composer remove friendsofphp/php-cs-fixer --dev --no-update
109-
110-
- name: Remove vimeo/psalm
111-
if: matrix.static-analysis != true
112-
run: composer remove vimeo/psalm --dev --no-update
113-
114106
- name: Configure Symfony Flex
115107
if: matrix.symfony-version
116108
run: composer config extra.symfony.require ${{ matrix.symfony-version }}
@@ -136,6 +128,6 @@ jobs:
136128
if: matrix.coding-standards
137129
run: cat LICENSE |grep -E "\(c\) ([0-9]+\-)*`date +%G`"
138130

139-
- name: Run Psalm
131+
- name: Run PHPStan
140132
if: matrix.static-analysis
141-
run: php vendor/bin/psalm --stats --output-format=github
133+
run: php vendor/bin/phpstan --no-progress --error-format=github

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@
3434
"require-dev": {
3535
"dg/bypass-finals": "^1.3",
3636
"friendsofphp/php-cs-fixer": "^3.0",
37-
"phpunit/phpunit": "^9",
38-
"vimeo/psalm": "^5"
37+
"phpstan/extension-installer": "^1.3",
38+
"phpstan/phpstan": "^1.10",
39+
"phpstan/phpstan-symfony": "^1.3",
40+
"phpunit/phpunit": "^9"
3941
},
4042
"config": {
41-
"sort-packages": true
43+
"sort-packages": true,
44+
"allow-plugins": {
45+
"phpstan/extension-installer": true
46+
}
4247
}
4348
}

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#no value type specified in iterable type array#'
5+
path: tests/

phpstan.neon.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
4+
5+
parameters:
6+
level: max
7+
paths:
8+
- src
9+
- tests

psalm.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Command/DeployRsyncCommand.php

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Attribute\AsCommand;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Exception\RuntimeException;
19+
use Symfony\Component\Console\Helper\QuestionHelper;
1920
use Symfony\Component\Console\Input\InputArgument;
2021
use Symfony\Component\Console\Input\InputInterface;
2122
use Symfony\Component\Console\Input\InputOption;
@@ -30,33 +31,14 @@ final class DeployRsyncCommand extends Command
3031
public const TARGET_SSH_REGEX = '/^ssh:\/\/(?<username>.+)@(?<hostname>[^:]+)(:(?<port>\d+)){0,1}:(?<path>.+)$/';
3132

3233
/**
33-
* @var array
34+
* @param array<string, array{target: string, rsync_options?: string[], ignore_file?: string}> $environments
35+
* @param array{rsync_path: string, rsync_options: string[], ignore_file: ?string} $rsyncConfig
3436
*/
35-
protected $environments;
36-
37-
/**
38-
* @var array
39-
*/
40-
protected $rsyncConfig;
41-
42-
/**
43-
* @var string
44-
*/
45-
protected $projetDir;
46-
47-
public function __construct(array $environments, array $rsyncConfig, string $projetDir)
37+
public function __construct(protected array $environments, protected array $rsyncConfig, protected string $projetDir)
4838
{
49-
$this->environments = $environments;
50-
$this->rsyncConfig = $rsyncConfig;
51-
$this->projetDir = $projetDir;
52-
5339
parent::__construct();
5440
}
5541

56-
protected static $defaultName = 'ecommit:deploy-rsync'; // PHP < 8
57-
58-
protected static $defaultDescription = 'Deploy the application with RSYNC and SSH'; // PHP < 8
59-
6042
protected function configure(): void
6143
{
6244
$this
@@ -67,13 +49,16 @@ protected function configure(): void
6749

6850
protected function execute(InputInterface $input, OutputInterface $output): int
6951
{
70-
if (!\array_key_exists($input->getArgument('environment'), $this->environments)) {
71-
throw new RuntimeException('Environment not found: '.$input->getArgument('environment'));
52+
/** @var string $environmentName */
53+
$environmentName = $input->getArgument('environment');
54+
if (!\array_key_exists($environmentName, $this->environments)) {
55+
throw new RuntimeException('Environment not found: '.$environmentName);
7256
}
73-
$environment = $this->environments[$input->getArgument('environment')];
57+
$environment = $this->environments[$environmentName];
7458

7559
$ignoreFile = $environment['ignore_file'] ?? $this->rsyncConfig['ignore_file'];
7660
if (!$ignoreFile) {
61+
/** @var QuestionHelper $helper */
7762
$helper = $this->getHelper('question');
7863
$question = new ConfirmationQuestion('Continue without ignore file? [y/N]', false);
7964

@@ -123,12 +108,18 @@ protected function getDirPath(string $dir): string
123108
return $dir;
124109
}
125110

126-
protected function executeProcess(array $command): \Iterator
111+
/**
112+
* @param string[] $command
113+
*
114+
* @return \Generator<array-key, string>
115+
*/
116+
protected function executeProcess(array $command): \Generator
127117
{
128118
$process = $this->createProcess($command);
129119
$process->start();
130120

131-
foreach ($process as $type => $data) {
121+
/** @var string $data */
122+
foreach ($process as $data) {
132123
yield $data;
133124
}
134125

@@ -137,6 +128,9 @@ protected function executeProcess(array $command): \Iterator
137128
}
138129
}
139130

131+
/**
132+
* @param string[] $command
133+
*/
140134
protected function createProcess(array $command): Process
141135
{
142136
return new Process($command);

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
class Configuration implements ConfigurationInterface
2121
{
22-
/**
23-
* @psalm-suppress UndefinedMethod
24-
*/
2522
public function getConfigTreeBuilder(): TreeBuilder
2623
{
2724
$treeBuilder = new TreeBuilder('ecommit_deploy_rsync');

tests/Command/DeployRsyncCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public function testGetDirPath(string $dir, string $expected): void
413413
$class = new \ReflectionClass(DeployRsyncCommand::class);
414414
$method = $class->getMethod('getDirPath');
415415
$method->setAccessible(true);
416-
$command = new DeployRsyncCommand([], [], '');
416+
$command = new DeployRsyncCommand([], [], ''); // @phpstan-ignore-line
417417

418418
$this->assertSame($expected, $method->invokeArgs($command, [$dir]));
419419
}
@@ -430,9 +430,9 @@ public function getTestGetDirPathProvider(): array
430430
];
431431
}
432432

433-
protected function createCommandTester(array $config, array $expectedCommand, $isSuccessful): CommandTester
433+
protected function createCommandTester(array $config, array $expectedCommand, bool $isSuccessful): CommandTester
434434
{
435-
$command = $this->getMockBuilder(DeployRsyncCommand::class)
435+
$command = $this->getMockBuilder(DeployRsyncCommand::class) // @phpstan-ignore-line
436436
->setConstructorArgs([$config['environments'], $config['rsync'], '/local/path'])
437437
->onlyMethods(['createProcess'])
438438
->getMock();

0 commit comments

Comments
 (0)