Skip to content

Commit

Permalink
Update Psalm and bump errorLevel to 6 (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidz committed Nov 17, 2021
1 parent 847f05d commit 735cd3b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PHP_CS_FIXER_CACHE=.php_cs.cache
PHPSTAN=./vendor/bin/phpstan

PSALM=./.tools/psalm
PSALM_URL="https://github.com/vimeo/psalm/releases/download/4.1.1/psalm.phar"
PSALM_URL="https://github.com/vimeo/psalm/releases/download/4.12.0/psalm.phar"

PHPUNIT=vendor/phpunit/phpunit/phpunit
PARATEST=vendor/bin/paratest --runner=WrapperRunner
Expand Down Expand Up @@ -87,6 +87,10 @@ phpstan-baseline: vendor $(PHPSTAN)
$(PHPSTAN) analyse --configuration devTools/phpstan-src.neon --no-interaction --no-progress --generate-baseline devTools/phpstan-src-baseline.neon || true
$(PHPSTAN) analyse --configuration devTools/phpstan-tests.neon --no-interaction --no-progress --generate-baseline devTools/phpstan-tests-baseline.neon || true

.PHONY: psalm-baseline
psalm-baseline: vendor
$(PSALM) --threads=4 --set-baseline=psalm-baseline.xml

.PHONY: psalm
psalm: vendor $(PSALM)
$(PSALM) --threads=4
Expand Down
34 changes: 21 additions & 13 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.1.1@16bfbd9224698bd738c665f33039fade2a1a3977">
<file src="src/Mutator/Regex/PregMatchRemoveCaret.php">
<ImpureFunctionCall occurrences="1">
<code>preg_match</code>
</ImpureFunctionCall>
<files psalm-version="4.x-dev@">
<file src="src/Mutator/IgnoreMutator.php">
<InvalidArgument occurrences="1">
<code>$node</code>
</InvalidArgument>
</file>
<file src="src/Mutator/Regex/PregMatchRemoveDollar.php">
<ImpureFunctionCall occurrences="1">
<code>preg_match</code>
</ImpureFunctionCall>
<file src="src/TestFramework/Coverage/JUnit/JUnitTestFileDataProvider.php">
<InvalidReturnType occurrences="1">
<code>iterable&lt;string, string&gt;</code>
</InvalidReturnType>
</file>
<file src="src/Mutator/Regex/PregMatchRemoveFlags.php">
<ImpureFunctionCall occurrences="1">
<code>preg_match</code>
</ImpureFunctionCall>
<file src="src/TestFramework/Factory.php">
<InvalidArgument occurrences="1">
<code>$this-&gt;sourceFileFilter-&gt;filter($this-&gt;infectionConfig-&gt;getSourceFiles())</code>
</InvalidArgument>
</file>
<file src="src/TestFramework/TestFrameworkExtraOptionsFilter.php">
<InvalidReturnStatement occurrences="1">
<code>preg_replace('/\s+/', ' ', trim($actualExtraOptions))</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>string</code>
</InvalidReturnType>
</file>
</files>
14 changes: 10 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?xml version="1.0"?>
<psalm
errorLevel="8"
errorLevel="6"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src/Mutator" />
<directory name="src" />
<ignoreFiles>
<directory name="src/PhpParser" />
<directory name="vendor" />
<directory name="src/PhpParser" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<ImpureMethodCall>
<errorLevel type="suppress">
<file name="src/Mutator/Operator/Concat.php"/>
<directory name="src/Mutator"/>
</errorLevel>
</ImpureMethodCall>

<ImpureFunctionCall>
<errorLevel type="suppress">
<directory name="src/Mutator/Regex"/>
</errorLevel>
</ImpureFunctionCall>
</issueHandlers>
</psalm>
6 changes: 2 additions & 4 deletions src/Mutator/MutatorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,15 @@ private static function resolveSettings($settings, array $globalSettings)
}

/**
* @param array<string, mixed[]>|bool $settings
* @param array<string, array<string, string>> $mutators
* @param array<string, mixed>|bool $settings
* @param array<string, array<array-key, string>> $mutators
*/
private static function registerFromProfile(
string $profile,
$settings,
array &$mutators
): void {
foreach (ProfileList::ALL_PROFILES[$profile] as $mutatorOrProfile) {
/** @var string $mutatorOrProfile */

// A profile may refer to another collection of profiles
if (array_key_exists($mutatorOrProfile, ProfileList::ALL_PROFILES)) {
self::registerFromProfile(
Expand Down
2 changes: 1 addition & 1 deletion src/Mutator/ProfileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ final class ProfileList
'SyntaxError' => Mutator\SyntaxError::class,
];

/** @var array<int, string>|null */
/** @var array<string, string>|null */
private static ?array $defaultProfileMutators = null;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Mutator/Removal/ArrayItemRemoval.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public static function getDefinition(): ?Definition
*
* @return iterable<Node\Expr\Array_>
*/
public function mutate(Node $arrayNode): iterable
public function mutate(Node $node): iterable
{
Assert::allNotNull($arrayNode->items);
Assert::allNotNull($node->items);

foreach ($this->getItemsIndexes($arrayNode->items) as $indexToRemove) {
$newArrayNode = clone $arrayNode;
foreach ($this->getItemsIndexes($node->items) as $indexToRemove) {
$newArrayNode = clone $node;
unset($newArrayNode->items[$indexToRemove]);

yield $newArrayNode;
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Memory/MemoryFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function toHumanReadableString(float $bytes): string
'Expected a positive or null amount of bytes. Got: %s'
);

$power = $bytes > 0 ? round(log($bytes, 1023)) : 0;
$power = $bytes > 0 ? (int) round(log($bytes, 1023)) : 0;

return sprintf(
'%s%s',
Expand Down
12 changes: 6 additions & 6 deletions src/TestFramework/AbstractTestFrameworkAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public function getInitialTestRunCommandLine(
/**
* Returns array of arguments to pass them into the Mutant Process
*
* @param TestLocation[] $tests
* @param TestLocation[] $coverageTests
*
* @return string[]
*/
public function getMutantCommandLine(
array $tests,
string $mutantFilePath,
array $coverageTests,
string $mutatedFilePath,
string $mutationHash,
string $mutationOriginalFilePath,
string $extraOptions
Expand All @@ -115,13 +115,13 @@ public function getMutantCommandLine(
[],
$this->argumentsAndOptionsBuilder->buildForMutant(
$this->buildMutationConfigFile(
$tests,
$mutantFilePath,
$coverageTests,
$mutatedFilePath,
$mutationHash,
$mutationOriginalFilePath
),
$extraOptions,
$tests
$coverageTests
)
);
}
Expand Down

0 comments on commit 735cd3b

Please sign in to comment.