Skip to content

Commit

Permalink
refactor: split phpstan-baseline into smaller files
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 12, 2024
1 parent 9bc61b3 commit ae20571
Show file tree
Hide file tree
Showing 80 changed files with 15,798 additions and 18,073 deletions.
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
"psr/log": "^3.0"
},
"require-dev": {
"codeigniter/phpstan-codeigniter": "^1.4",
"codeigniter/phpstan-codeigniter": "^1.5",
"fakerphp/faker": "^1.9",
"kint-php/kint": "^5.0.4",
"mikey179/vfsstream": "^1.6",
"nexusphp/tachycardia": "^2.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-strict-rules": "^1.6",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpcov": "^9.0.2 || ^10.0",
"phpunit/phpunit": "^10.5.16 || ^11.2",
"predis/predis": "^1.1 || ^2.0",
"rector/rector": "1.2.10"
"rector/rector": "2.0.0-rc3",
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
},
"replace": {
"codeigniter4/framework": "self.version"
Expand Down Expand Up @@ -110,7 +111,12 @@
"utils/vendor/bin/php-cs-fixer fix --ansi --verbose --diff"
],
"metrics": "utils/vendor/bin/phpmetrics --config=phpmetrics.json",
"phpstan:baseline": "vendor/bin/phpstan analyse --ansi --generate-baseline=phpstan-baseline.php",
"phpstan:baseline": [
"bash -c \"rm -rf utils/phpstan-baseline/*.neon\"",
"bash -c \"touch utils/phpstan-baseline/loader.neon\"",
"phpstan analyse --ansi --generate-baseline=utils/phpstan-baseline/loader.neon",
"split-phpstan-baseline utils/phpstan-baseline/loader.neon"
],
"phpstan:check": "vendor/bin/phpstan analyse --verbose --ansi",
"sa": "@analyze",
"style": "@cs-fix",
Expand Down
18,053 changes: 0 additions & 18,053 deletions phpstan-baseline.php

This file was deleted.

9 changes: 7 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- phpstan.rules.rule

includes:
- phpstan-baseline.php
- utils/phpstan-baseline/loader.neon

parameters:
phpVersion: 80100
Expand Down Expand Up @@ -40,5 +40,10 @@ parameters:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedConstructs: true
disallowedBacktick: true
disallowedEmpty: true
disallowedImplicitArrayCreation: true
disallowedShortTernary: true
matchingInheritedMethodNames: true
shipmonkBaselinePerIdentifier:
directory: %currentWorkingDirectory%
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
__DIR__ . '/phpstan.neon.dist',
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
__DIR__ . '/vendor/shipmonk/phpstan-baseline-per-identifier/extension.neon',
])
// is there a file you need to skip?
->withSkip([
Expand Down
10 changes: 4 additions & 6 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,8 @@ public function required_with($str = null, ?string $fields = null, array $data =

foreach (explode(',', $fields) as $field) {
if (
(array_key_exists($field, $data)
&& ! empty($data[$field])) // @phpstan-ignore-line Use empty()
|| (str_contains($field, '.')
&& ! empty(dot_array_search($field, $data))) // @phpstan-ignore-line Use empty()
(array_key_exists($field, $data) && ! empty($data[$field]))
|| (str_contains($field, '.') && ! empty(dot_array_search($field, $data)))
) {
$requiredFields[] = $field;
}
Expand Down Expand Up @@ -409,7 +407,7 @@ public function required_without(
if (
(! str_contains($otherField, '.'))
&& (! array_key_exists($otherField, $data)
|| empty($data[$otherField])) // @phpstan-ignore-line Use empty()
|| empty($data[$otherField]))
) {
return false;
}
Expand All @@ -424,7 +422,7 @@ public function required_without(
$fieldKey = $fieldSplitArray[1];

if (is_array($fieldData)) {
return ! empty(dot_array_search($otherField, $data)[$fieldKey]); // @phpstan-ignore-line Use empty()
return ! empty(dot_array_search($otherField, $data)[$fieldKey]);
}
$nowField = str_replace('*', $fieldKey, $otherField);
$nowFieldVaule = dot_array_search($nowField, $data);
Expand Down
4 changes: 1 addition & 3 deletions system/View/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public static function date_modify($value, string $adjustment)
*/
public static function default($value, string $default): string
{
return empty($value) // @phpstan-ignore-line
? $default
: $value;
return empty($value) ? $default : $value;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/system/Database/Live/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testListTablesUnconstrainedByPrefixReturnsAllTables(): void
$expectedTables[] = 'tmp_widgets';

sort($tables);
$this->assertSame($expectedTables, array_values($tables));
$this->assertSame($expectedTables, $tables);
} finally {
$this->dropExtraneousTable();
}
Expand All @@ -117,7 +117,7 @@ public function testListTablesConstrainedByPrefixReturnsOnlyTablesWithMatchingPr
$this->assertNotSame([], $tables);

sort($tables);
$this->assertSame($this->expectedTables, array_values($tables));
$this->assertSame($this->expectedTables, $tables);
} finally {
$this->dropExtraneousTable();
}
Expand All @@ -138,7 +138,7 @@ public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtrane
$this->assertNotSame([], $tables);

sort($tables);
$this->assertSame(['tmp_widgets'], array_values($tables));
$this->assertSame(['tmp_widgets'], $tables);
} finally {
$this->db->setPrefix($oldPrefix);
$this->dropExtraneousTable();
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testDeprecationsOnPhp81DoNotThrow(): void
// We test DEPRECATED error, so cannot set `declare(strict_types=1)` in this file.
strlen($maybeNull);
$this->assertLogContains('error', '[DEPRECATED] strlen(): ');
} catch (ErrorException) {
} catch (ErrorException $e) {
$this->fail('The catch block should not be reached.');
} finally {
restore_error_handler();
Expand Down
Loading

0 comments on commit ae20571

Please sign in to comment.