Skip to content

Commit

Permalink
Update PHPStan to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloKowalczyk committed Nov 18, 2024
1 parent 284f265 commit c146974
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 43 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"ext-mbstring": "*",
"ergebnis/composer-normalize": "2.28.3",
"friendsofphp/php-cs-fixer": "3.64",
"phpstan/phpstan": "1.8.6",
"phpstan/phpstan-phpunit": "1.1.1",
"phpstan/phpstan-strict-rules": "1.4.4",
"phpstan/phpstan": "2.0.2",
"phpstan/phpstan-phpunit": "2.0.1",
"phpstan/phpstan-strict-rules": "2.0.0",
"phpunit/phpunit": "10.5.38",
"symfony/error-handler": "^5.4.40 || ^6.4.10 || ^7.1.0",
"symfony/phpunit-bridge": "^5.4.40 || ^6.4.10 || ^7.1.0"
Expand Down
33 changes: 20 additions & 13 deletions src/Console/Command/TaskGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ protected function outputPath()
*/
protected function outputFile()
{
/** @var string $suffix */
$suffix = $this->config
->get('suffix')
;
/** @var string $taskFile */
$taskFile = $this->arguments['taskfile'];

return \preg_replace('/Tasks|\.php$/', '', $this->arguments['taskfile']) . $suffix;
return \preg_replace('/Tasks|\.php$/', '', $taskFile) . $suffix;
}

/**
Expand Down Expand Up @@ -243,33 +246,37 @@ protected function replaceConstraint(): self
return $this;
}

/**
* Replace command.
*/
protected function replaceCommand(): self
{
$this->stub = \str_replace('DummyCommand', $this->options['run'], $this->stub);
$run = $this->optionString('run');
$this->stub = \str_replace('DummyCommand', $run, $this->stub);

return $this;
}

/**
* Replace path.
*/
protected function replacePath(): self
{
$this->stub = \str_replace('DummyPath', $this->options['in'], $this->stub);
$in = $this->optionString('in');
$this->stub = \str_replace('DummyPath', $in, $this->stub);

return $this;
}

/**
* Replace description.
*/
protected function replaceDescription(): self
{
$this->stub = \str_replace('DummyDescription', $this->options['description'], $this->stub);
$description = $this->optionString('description');
$this->stub = \str_replace('DummyDescription', $description, $this->stub);

return $this;
}

private function optionString(string $name): string
{
$option = $this->options[$name] ?? throw new \RuntimeException("Missing option '{$name}'.");
if (false === \is_string($option)) {
throw new \RuntimeException("Option must be of type 'string'.");
}

return $option;
}
}
5 changes: 4 additions & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,16 @@ function ($type, $content): void {
*/
public function cron(string $expression): self
{
/** @var string[] $parts */
$parts = \preg_split(
'/\s/',
$expression,
-1,
PREG_SPLIT_NO_EMPTY
);
$parts = false === $parts
? []
: $parts
;

if (\count($parts) > 5) {
throw new TaskException("Expression '{$expression}' has more than five parts and this is not allowed.");
Expand Down
14 changes: 11 additions & 3 deletions src/EventRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ protected function invoke(array $callbacks = [], array $parameters = [])
{
$output = '';
foreach ($callbacks as $callback) {
/** @var string $callResult */
$callResult = $this->invoker->call($callback, $parameters, true);
// Invoke the callback with buffering enabled
$output .= $this->invoker->call($callback, $parameters, true);
$output .= $callResult;
}

return $output;
Expand Down Expand Up @@ -276,8 +278,11 @@ private function pingBefore(PingableInterface $schedule): void
return;
}

/** @var non-empty-string $pingBeforeUrl */
$pingBeforeUrl = $schedule->getPingBeforeUrl();
$this->httpClient
->ping($schedule->getPingBeforeUrl());
->ping($pingBeforeUrl)
;
}

private function pingAfter(PingableInterface $schedule): void
Expand All @@ -289,8 +294,11 @@ private function pingAfter(PingableInterface $schedule): void
return;
}

/** @var non-empty-string $pingAfterUrl */
$pingAfterUrl = $schedule->getPingAfterUrl();
$this->httpClient
->ping($schedule->getPingAfterUrl());
->ping($pingAfterUrl)
;
}

private function logger(): Logger
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function ping($url): void
\curl_setopt(
$curlResource,
CURLOPT_RETURNTRANSFER,
1
true,
);
\curl_setopt(
$curlResource,
Expand Down
13 changes: 2 additions & 11 deletions src/HttpClient/FallbackHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@ public function __construct(
) {
}

/**
* @param string $url
*
* @throws HttpClientException
*/
public function ping($url): void
{
$httpClient = $this->chooseHttpClient();
$httpClient->ping($url);
}

/**
* @return HttpClientInterface
*
* @throws HttpClientException
*/
private function chooseHttpClient()
/** @throws HttpClientException */
private function chooseHttpClient(): HttpClientInterface
{
if (null !== $this->httpClient) {
return $this->httpClient;
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/HttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
interface HttpClientInterface
{
/**
* @param string $url
* @param non-empty-string $url
*
* @throws HttpClientException
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Logger/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class LoggerFactory
{
private ?LoggerFactoryInterface $loggerFactory = null;

/**
* @throws \Exception if the timezone supplied in configuration is not recognised as a valid timezone
*/
public function __construct(
private readonly ConfigurationInterface $configuration,
private readonly Timezone $timezoneProvider,
Expand Down
7 changes: 6 additions & 1 deletion src/UserInterface/Cli/ClosureRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var string $closure */
$closure = $input->getArgument('closure');
\parse_str($closure, $args);
$serializedClosure = $args[0] ?? '';
if (false === \is_string($serializedClosure)) {
$serializedClosure = '';
}

$closure = $this->closureSerializer
->unserialize($args[0] ?? '')
->unserialize($serializedClosure)
;

\call_user_func_array($closure, []);
Expand Down
4 changes: 2 additions & 2 deletions tests/EndToEnd/DebugTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function extractContentLines(string $output): array
continue;
}

$key = \trim($matches['key'] ?? '');
$key = \trim($matches['key']);
$key = \mb_strtolower($key);
$key = \str_replace(
[
Expand All @@ -81,7 +81,7 @@ private function extractContentLines(string $output): array
$key
);

$contentLines[$key] = \trim($matches['value'] ?? '');
$contentLines[$key] = \trim($matches['value']);
}

return $contentLines;
Expand Down
14 changes: 10 additions & 4 deletions tests/Unit/Console/Command/ScheduleRunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ public static function mockTimezoneProvider(): MockObject&Timezone
$timezoneProviderMock = (new MockGenerator())->testDouble(
Timezone::class,
true,
callOriginalConstructor: false,
callOriginalClone: false,
cloneArguments: false,
allowMockingUnknownTypes: false,
[],
[],
'',
false,
false,
true,
false,
false,
null,
false,
);
$timezoneProviderMock->method('timezoneForComparisons')->willReturn($timeZone);

Expand Down

0 comments on commit c146974

Please sign in to comment.