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

Upgrade psalm #930

Merged
merged 1 commit into from
Sep 24, 2021
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"require": {
"php": "^7.3 || ^8.0",
"ext-json": "*",
"composer-plugin-api": "~1.0 || ~2.0",
"amphp/amp": "^2.4",
"amphp/parallel": "^1.4",
"amphp/parallel-functions": "^1.0",
"composer-plugin-api": "~1.0 || ~2.0",
"doctrine/collections": "^1.6.7",
"gitonomy/gitlib": "^1.0.3",
"monolog/monolog": "~1.16 || ^2.0",
Expand Down
1 change: 1 addition & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ grumphp:
functional: true
psalm:
show_info: true
no_cache: true
testsuites:
git_pre_commit:
tasks: [phpcs, phpspec, phpunit, composer, composer_normalize, yamllint, phplint, phpparser, psalm]
Expand Down
8 changes: 4 additions & 4 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="psalm" version="^3.12.2" installed="3.12.2" location="./tools/psalm" copy="true"/>
<phar name="phpcs" version="^3.5.5" installed="3.5.5" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.5.5" installed="3.5.5" location="./tools/phpcbf" copy="true"/>
<phar name="composer-normalize" version="^2.6.1" installed="2.6.1" location="./tools/composer-normalize" copy="true"/>
<phar name="psalm" version="^4.10.0" installed="4.10.0" location="./tools/psalm" copy="true"/>
<phar name="phpcs" version="^3.5.5" installed="3.6.0" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.5.5" installed="3.6.0" location="./tools/phpcbf" copy="true"/>
<phar name="composer-normalize" version="^2.6.1" installed="2.15.0" location="./tools/composer-normalize" copy="true"/>
</phive>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="3"
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
14 changes: 7 additions & 7 deletions src/Collection/FilesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ public function date(string $date): self
* @see CustomFilterIterator
*
* @psalm-suppress LessSpecificImplementedReturnType
* @psalm-suppress LessSpecificReturnStatement
* @psalm-suppress MoreSpecificReturnType
*/
public function filter(Closure $closure): self
public function filter(Closure $p): self
{
$filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]);
$filter = new Iterator\CustomFilterIterator($this->getIterator(), [$p]);

return new self(iterator_to_array($filter));
}
Expand Down Expand Up @@ -221,11 +223,9 @@ public function ignoreSymlinks(): FilesCollection
public function serialize(): string
{
return serialize($this->map(function (SplFileInfo $fileInfo): string {
return (string) (
$fileInfo instanceof SymfonySplFileInfo
? $fileInfo->getRelativePathname()
: $fileInfo->getPathname()
);
return $fileInfo instanceof SymfonySplFileInfo
? $fileInfo->getRelativePathname()
: $fileInfo->getPathname();
})->toArray());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Model/FixerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct(
public static function fromArray(array $config): self
{
return new self(
(bool) ($config['enabled'] ?? false),
(bool) ($config['fix_by_default'] ?? false)
($config['enabled'] ?? false),
($config['fix_by_default'] ?? false)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Model/ParallelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct(
public static function fromArray(array $config): self
{
return new self(
(bool) ($config['enabled'] ?? false),
(int) ($config['max_workers'] ?? 1)
($config['enabled'] ?? false),
($config['max_workers'] ?? 1)
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Console/Command/Git/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ private function parseHookVariable(string $key, $value): string
case 'ENV':
return DotEnvSerializer::serialize($value);
default:
/** @var string $value */
/**
* @var string $value
* @psalm-suppress PossiblyInvalidCast, RedundantCastGivenDocblockType
*/
return (string) $value;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Event/Dispatcher/Bridge/SymfonyEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ public function __construct($eventDispatcher)
$this->dispatcher = $eventDispatcher;
}

public function dispatch(Event $event, string $eventName = null): void
public function dispatch(Event $event, string $name = null): void
{
$interfacesImplemented = class_implements($this->dispatcher);
if (in_array(SymfonyEventDispatcherContract::class, $interfacesImplemented, true)) {
/**
* @psalm-suppress InvalidArgument
* @psalm-suppress TooManyArguments
*/
$this->dispatcher->dispatch($event, $eventName);
$this->dispatcher->dispatch($event, $name);
return;
}

/**
* @psalm-suppress InvalidArgument
* @psalm-suppress TooManyArguments
*/
$this->dispatcher->dispatch($eventName, $event);
$this->dispatcher->dispatch($name, $event);
}
}
4 changes: 2 additions & 2 deletions src/Fixer/FixerUpper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static function (TaskResultInterface $result): bool {
$result->ok() ? $this->IO->colorize(['✔'], 'green') : $this->IO->colorize(['✘'], 'red')
);

if ($this->IO->isVerbose() && $result->error()) {
$this->IO->writeError($this->IO->colorize([$result->error()->getMessage()], 'red'));
if ($this->IO->isVerbose() && $error = $result->error()) {
$this->IO->writeError($this->IO->colorize([$error->getMessage()], 'red'));
}

$count++;
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Provider/FixableProcessResultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static function provide(
array $successExitCodes = [0]
): FixableTaskResult {
$fixerProcess = $fixerProcessBuilder();
/** @psalm-suppress RedundantConditionGivenDocblockType */
assert($fixerProcess instanceof Process);

$fixerCommand = $fixerProcess->getCommandLine();
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/GitBlacklistFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function formatOutput(string $output): string
{
$result = static::RESET_COLOR;
foreach (array_filter(explode("\n", $output)) as $lineNumber => $line) {
$result .= preg_match('/^[0-9]+/', $line) ? $this->trimOutputLine($line, (int) $lineNumber) : $line;
$result .= preg_match('/^[0-9]+/', $line) ? $this->trimOutputLine($line, $lineNumber) : $line;
$result .= PHP_EOL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public static function fromArguments(ProcessArgumentsCollection $arguments): Pro
*/
public static function fromScalar($arguments): Process
{
return is_array($arguments) ? new Process($arguments) : Process::fromShellCommandline((string) $arguments);
return is_array($arguments) ? new Process($arguments) : Process::fromShellCommandline($arguments);
}
}
2 changes: 1 addition & 1 deletion src/Process/TmpFileUsingProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function run(callable $processBuilder, callable $writer): Process
}

foreach ($writer() as $entry) {
fwrite($tmp, (string) $entry);
fwrite($tmp, $entry);
}
fseek($tmp, 0);

Expand Down
4 changes: 2 additions & 2 deletions src/Runner/FixableTaskResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public function getContext(): ContextInterface
return $this->result->getContext();
}

public function withAppendedMessage(string $additionalMessage): TaskResultInterface
public function withAppendedMessage(string $message): TaskResultInterface
{
$new = clone $this;
$new->result = $this->result->withAppendedMessage($additionalMessage);
$new->result = $this->result->withAppendedMessage($message);

return $new;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Middleware/HandleRunnerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(TaskHandler $taskHandler, RunnerConfig $config)
public function handle(TaskRunnerContext $context, callable $next): TaskResultCollection
{
return new TaskResultCollection(
(array) wait(
wait(
/**
* @return \Generator<mixed, mixed, mixed, TaskResultInterface[]>
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Runner/MiddlewareStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use GrumPHP\Collection\TaskResultCollection;
use GrumPHP\Runner\Middleware\RunnerMiddlewareInterface;

/**
* @psalm-immutable
*/
class MiddlewareStack
{
/**
Expand All @@ -30,9 +33,6 @@ public static function fromIterable(iterable $middlewares): self
);
}

/**
* @psalm-pure
*/
public function handle(TaskRunnerContext $context): TaskResultCollection
{
return ($this->stack)($context);
Expand Down
43 changes: 24 additions & 19 deletions src/Runner/Promise/MultiPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MultiPromise
* @param array<int, LazyPromise<TValue>> $promises
* @param callable(TValue):bool $shouldCancel
*
* @return Promise<TValue>
* @return Promise<array{0: \Throwable[], 1: TValue[]}>
*/
public static function cancelable(array $promises, callable $shouldCancel): Promise
{
Expand Down Expand Up @@ -50,26 +50,31 @@ static function (CancelledException $error) use ($deferred, $watcherId): void {
});
};

$promise->onResolve(static function (
?\Throwable $error,
$result
) use (
$deferred,
$cancel,
$shouldCancel
): void {
if ($error instanceof \Throwable) {
$cancel($error);
$deferred->fail($error);
return;
}
$promise->onResolve(
/**
* @param TValue $result
*/
static function (
?\Throwable $error,
$result
) use (
$deferred,
$cancel,
$shouldCancel
): void {
if ($error instanceof \Throwable) {
$cancel($error);
$deferred->fail($error);
return;
}

if ($result && $shouldCancel($result)) {
$cancel();
}
if ($result && $shouldCancel($result)) {
$cancel();
}

$deferred->resolve($result);
});
$deferred->resolve($result);
}
);
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/Runner/Reporting/RunnerReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(
public function start(TaskRunnerContext $context): void
{
$this->IO->write($this->IO->colorize(['GrumPHP is sniffing your code!'], 'yellow'));
if ($context->getTestSuite()) {
$this->IO->style()->note('Running testsuite: '.$context->getTestSuite()->getName());
if ($testSuite = $context->getTestSuite()) {
$this->IO->style()->note('Running testsuite: '.$testSuite->getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TaskHandlerMiddlewareInterface
*/
public function handle(
TaskInterface $task,
TaskRunnerContext $runnercontext,
TaskRunnerContext $runnerContext,
callable $next
): Promise;
}
4 changes: 3 additions & 1 deletion src/Runner/TaskHandler/TaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use GrumPHP\Runner\TaskRunnerContext;
use GrumPHP\Task\TaskInterface;

/**
* @psalm-immutable
*/
class TaskHandler
{
/**
Expand All @@ -37,7 +40,6 @@ public static function fromIterable(iterable $handlers): self
}

/**
* @psalm-pure
* @return Promise<TaskResultInterface>
*/
public function handle(TaskInterface $task, TaskRunnerContext $runnerContext): Promise
Expand Down
4 changes: 2 additions & 2 deletions src/Runner/TaskResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public function getContext(): ContextInterface
return $this->context;
}

public function withAppendedMessage(string $additionalMessage): TaskResultInterface
public function withAppendedMessage(string $message): TaskResultInterface
{
$new = clone $this;
$new->message = $this->message . $additionalMessage;
$new->message = $this->message . $message;

return $new;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Task/AbstractExternalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use GrumPHP\Task\Config\EmptyTaskConfig;
use GrumPHP\Task\Config\TaskConfigInterface;

/**
* @template-covariant Formatter extends ProcessFormatterInterface
*/
abstract class AbstractExternalTask implements TaskInterface
{
/**
Expand All @@ -22,10 +25,13 @@ abstract class AbstractExternalTask implements TaskInterface
protected $processBuilder;

/**
* @var ProcessFormatterInterface
* @var Formatter
*/
protected $formatter;

/**
* @param Formatter $formatter
*/
public function __construct(ProcessBuilder $processBuilder, ProcessFormatterInterface $formatter)
{
$this->config = new EmptyTaskConfig();
Expand Down
8 changes: 7 additions & 1 deletion src/Task/AbstractLinterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use GrumPHP\Task\Config\TaskConfigInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @template-covariant Linter extends LinterInterface
*/
abstract class AbstractLinterTask implements TaskInterface
{
/**
Expand All @@ -20,10 +23,13 @@ abstract class AbstractLinterTask implements TaskInterface
protected $config;

/**
* @var LinterInterface
* @var Linter
*/
protected $linter;

/**
* @param Linter $linter
*/
public function __construct(LinterInterface $linter)
{
$this->linter = $linter;
Expand Down
Loading