Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan 2.0 #18

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.28" installed="1.10.28" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.14.1" installed="5.14.1" location="./tools/psalm" copy="false"/>
</phive>
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: '#^Property CakeDumpSql\\Error\\VersionMismatchException\:\:\$message has no type specified\.$#'
identifier: missingType.property
count: 1
path: src/Error/VersionMismatchException.php
10 changes: 8 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
includes:
- phpstan-baseline.neon

parameters:
paths:
- src
- tests/TestCase
level: 5
level: 8
bootstrapFiles:
- tests/bootstrap.php
- tests/bootstrap.php
ignoreErrors:
-
identifier: missingType.iterableValue
9 changes: 3 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@">
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<file src="src/Sql/SqlBase.php">
<ForbiddenCode occurrences="1">
<code>shell_exec("$test $command")</code>
<ForbiddenCode>
<code><![CDATA[shell_exec("$test $command")]]></code>
</ForbiddenCode>
<PossiblyNullArgument occurrences="1">
<code>shell_exec("$test $command")</code>
</PossiblyNullArgument>
</file>
</files>
5 changes: 5 additions & 0 deletions src/Command/DumpSqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function execute(Arguments $args, ConsoleIo $io): int
if ($gzip) {
if (function_exists('gzencode')) {
$result = gzencode($result, 9);
if (!$result) {
$io->err('Failed to gzip the dump!');

return self::CODE_ERROR;
}
} else {
$io->err('Your PHP installation does not have zlib support to create a gzip file!');

Expand Down
2 changes: 1 addition & 1 deletion src/Sql/SqlBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ protected function checkBinary(string $command): bool
$windows = str_starts_with(PHP_OS, 'WIN');
$test = $windows ? 'where' : 'command -v';

return is_executable(trim(shell_exec("$test $command")));
return is_executable(trim(shell_exec("$test $command") ?: ''));
}
}
6 changes: 5 additions & 1 deletion tests/TestCase/Command/DumpSqlCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ public function testCommandGzipped(): void
$postsTable->save($entity);

$this->exec('dump_sql --gzip');
$result = $this->_out->messages();
$result = $this->_out?->messages() ?? [];
$sql = gzdecode($result[0]);
if (!$sql) {
$this->fail('Failed to decode gzipped output');
}

if ($this->isDBType(Sqlite::class)) {
$this->assertStringContainsString('CREATE TABLE IF NOT EXISTS "posts"', $sql);
$this->assertStringContainsString('INSERT INTO posts VALUES(', $sql);
Expand Down