Skip to content
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
16 changes: 16 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ on:
branches:
tags:

env:
default_php: 8.2

jobs:
ci:
uses: laminas/workflow-continuous-integration/.github/workflows/[email protected]

rector:
runs-on: ubuntu-latest
name: Run Rector on PHP
steps:
- uses: actions/[email protected]
- uses: shivammathur/[email protected]
with:
php-version: ${{ env.default_php }}
extensions: swoole
tools: composer
- uses: ramsey/composer-install@v3
- run: composer rector
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"laminas/laminas-servicemanager": "^4.0",
"phpunit/phpunit": "^10.5",
"psalm/plugin-phpunit": "^0.19.5",
"rector/rector": "^2.1",
"swoole/ide-helper": "^6.0",
"vimeo/psalm": "^6.13"
},
Expand All @@ -77,11 +78,16 @@
"scripts": {
"check": [
"@cs-check",
"@rector",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"rector": "rector -n -vv",
"rector:fix": "rector -vv",
"static-analysis": "psalm --shepherd --stats",
"static-analysis:b": "psalm --update-baseline",
"static-analysis:clear": "psalm --clear-cache",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
},
Expand Down
681 changes: 403 additions & 278 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<!-- Paths to check -->
<file>src</file>
<file>test</file>
<file>rector.php</file>

<!-- Include all rules from Laminas Coding Standard -->
<rule ref="LaminasCodingStandard" />
Expand Down
113 changes: 0 additions & 113 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
<MixedArrayOffset>
<code><![CDATA[$cacheControlDirectives[$regex]]]></code>
</MixedArrayOffset>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$clearStatCacheInterval]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Command/IsRunningTrait.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$managerPid]]></code>
<code><![CDATA[$masterPid]]></code>
<code><![CDATA[$masterPid]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Command/ReloadCommand.php">
<DeprecatedMethod>
Expand Down Expand Up @@ -64,14 +54,6 @@
<PossiblyFalseIterator>
<code><![CDATA[scandir($path)]]></code>
</PossiblyFalseIterator>
<RedundantCondition>
<code><![CDATA[isArray]]></code>
</RedundantCondition>
</file>
<file src="src/HttpServerFactory.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$enableCoroutine]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Log/AccessLogDataMap.php">
<FalsableReturnStatement>
Expand Down Expand Up @@ -99,64 +81,6 @@
<PossiblyNullReference>
<code><![CDATA[getHeaderSize]]></code>
</PossiblyNullReference>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$port]]></code>
<code><![CDATA[(string) $this->psrResponse->getBody()->getSize()]]></code>
<code><![CDATA[getenv($name)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Log/AccessLogFormatter.php">
<InvalidNullableReturnType>
<code><![CDATA[string]]></code>
<code><![CDATA[string]]></code>
</InvalidNullableReturnType>
<NullableReturnStatement>
<code><![CDATA[preg_replace_callback(
'#%(?:[<>])?([%aABbDfhHklLmpPqrRstTuUvVXIOS])#',
static fn(array $matches) => match ($matches[1]) {
'%' => '%',
'a' => $map->getClientIp(),
'A' => $map->getLocalIp(),
'B' => $map->getBodySize('0'),
'b' => $map->getBodySize('-'),
'D' => $map->getRequestDuration('ms'),
'f' => $map->getFilename(),
'h' => $map->getRemoteHostname(),
'H' => $map->getProtocol(),
'm' => $map->getMethod(),
'p' => $map->getPort('canonical'),
'q' => $map->getQuery(),
'r' => $map->getRequestLine(),
's' => $map->getStatus(),
't' => $map->getRequestTime('begin:%d/%b/%Y:%H:%M:%S %z'),
'T' => $map->getRequestDuration('s'),
'u' => $map->getRemoteUser(),
'U' => $map->getPath(),
'v' => $map->getHost(),
'V' => $map->getServerName(),
'I' => (string) ($map->getRequestMessageSize() ?? '-'),
'O' => (string) ($map->getResponseMessageSize() ?? '-'),
'S' => $map->getTransferredSize(),
default => '-',
},
$format
)]]></code>
<code><![CDATA[preg_replace_callback(
'#%(?:[<>])?{([^}]+)}([aCeinopPtT])#',
static fn(array $matches) => match ($matches[2]) {
'a' => $map->getClientIp(),
'C' => $map->getCookie($matches[1]),
'e' => $map->getEnv($matches[1]),
'i' => $map->getRequestHeader($matches[1]),
'o' => $map->getResponseHeader($matches[1]),
'p' => $map->getPort($matches[1]),
't' => $map->getRequestTime($matches[1]),
'T' => $map->getRequestDuration($matches[1]),
default => '-',
},
$format
)]]></code>
</NullableReturnStatement>
</file>
<file src="src/Log/Psr3AccessLogDecorator.php">
<MissingParamType>
Expand Down Expand Up @@ -191,14 +115,6 @@
<code><![CDATA[bool]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/StaticMappedResourceHandler.php">
<MixedPropertyTypeCoercion>
<code><![CDATA[$middleware]]></code>
</MixedPropertyTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! $filename]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/StaticResourceHandler.php">
<MixedOperand>
<code><![CDATA[$request->server['request_uri']]]></code>
Expand All @@ -214,9 +130,6 @@
<MixedPropertyTypeCoercion>
<code><![CDATA[$cacheControlDirectives]]></code>
</MixedPropertyTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$cacheControl]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/StaticResourceHandler/ETagMiddleware.php">
<ArgumentTypeCoercion>
Expand All @@ -228,11 +141,6 @@
<PossiblyFalseArgument>
<code><![CDATA[$etag]]></code>
</PossiblyFalseArgument>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$ifMatch]]></code>
<code><![CDATA[filemtime($filename)]]></code>
<code><![CDATA[filesize($filename)]]></code>
</RiskyTruthyFalsyComparison>
<UnusedProperty>
<code><![CDATA[$allowedETagValidationTypes]]></code>
</UnusedProperty>
Expand Down Expand Up @@ -269,17 +177,11 @@
<ArgumentTypeCoercion>
<code><![CDATA[$regexp]]></code>
</ArgumentTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[filemtime($filename)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/StaticResourceHandler/StaticResourceResponse.php">
<PossiblyFalsePropertyAssignmentValue>
<code><![CDATA[filesize($filename)]]></code>
</PossiblyFalsePropertyAssignmentValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$responseContentCallback]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/StaticResourceHandler/ValidateRegexTrait.php">
<ArgumentTypeCoercion>
Expand All @@ -295,10 +197,6 @@
<PossiblyNullReference>
<code><![CDATA[asString]]></code>
</PossiblyNullReference>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$cookie->getDomain()]]></code>
<code><![CDATA[$cookie->getPath()]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/SwooleRequestHandlerRunner.php">
<PossiblyUnusedReturnValue>
Expand All @@ -319,11 +217,6 @@
<PossiblyUnusedReturnValue>
<code><![CDATA[int]]></code>
</PossiblyUnusedReturnValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$key]]></code>
<code><![CDATA[$this->body]]></code>
<code><![CDATA[$this->request->rawContent()]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Task/DeferredListenerDelegator.php">
<UnusedParam>
Expand Down Expand Up @@ -360,12 +253,6 @@
<code><![CDATA[assertAttributeEmpty]]></code>
<code><![CDATA[assertAttributeEmpty]]></code>
</PossiblyUnusedMethod>
<PossiblyUnusedParam>
<code><![CDATA[$canonicalize]]></code>
<code><![CDATA[$delta]]></code>
<code><![CDATA[$ignoreCase]]></code>
<code><![CDATA[$maxDepth]]></code>
</PossiblyUnusedParam>
</file>
<file src="test/Command/ReloadCommandTest.php">
<DeprecatedMethod>
Expand Down
36 changes: 36 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;

return RectorConfig::configure()
->withPhpSets(php82: true)
->withPaths([
__DIR__ . '/src',
__DIR__ . '/test',
])
->withPreparedSets(
typeDeclarations: true,
)
->withSkip([
__DIR__ . '/test/TestAsset',
// $this->httpServer->on('managerstart', [$this, 'onManagerStart']);
// vs
// $this->httpServer->on('managerstart', $this->onManagerStart(...)
// is not the same
FirstClassCallableRector::class => [
__DIR__ . '/src/SwooleRequestHandlerRunner.php',
__DIR__ . '/test/SwooleRequestHandlerRunnerTest.php',
__DIR__ . '/test/Task/TaskTest.php',
],
// Rector try to set callable as Closure. These are not the same — Closure is a subtype of callable.
TypedPropertyFromStrictSetUpRector::class => [
__DIR__ . '/test/StaticResourceHandler/LastModifiedMiddlewareTest.php',
__DIR__ . '/test/StaticResourceHandler/HeadMiddlewareTest.php',
__DIR__ . '/test/StaticResourceHandler/GzipMiddlewareTest.php',
__DIR__ . '/test/StaticResourceHandler/ETagMiddlewareTest.php',
],
]);
5 changes: 2 additions & 3 deletions src/AbstractStaticResourceHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

abstract class AbstractStaticResourceHandlerFactory
{
/** @return StaticResourceHandlerInterface */
abstract public function __invoke(ContainerInterface $container);
abstract public function __invoke(ContainerInterface $container): StaticResourceHandlerInterface;

/**
* Prepare the list of middleware based on configuration provided.
Expand Down Expand Up @@ -70,7 +69,7 @@ protected function configureMiddleware(array $config): array
}

$clearStatCacheInterval = $config['clearstatcache-interval'] ?? false;
if ($clearStatCacheInterval) {
if ($clearStatCacheInterval !== false) {
$middleware[] = new ClearStatCacheMiddleware((int) $clearStatCacheInterval);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Command/IsRunningTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function isRunning(): bool

[$masterPid, $managerPid] = array_pad($pids, 2, null);

if ($managerPid) {
if ($managerPid !== null) {
// Swoole process mode
return $masterPid && SwooleProcess::kill((int) $managerPid, 0);
return $masterPid !== null && SwooleProcess::kill((int) $managerPid, 0);
}

// Swoole base mode, no manager process
return $masterPid && SwooleProcess::kill((int) $masterPid, 0);
return $masterPid !== null && SwooleProcess::kill((int) $masterPid, 0);
}
}
2 changes: 1 addition & 1 deletion src/Command/ReloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ReloadCommand extends Command
*/
public static $defaultName = 'mezzio:swoole:reload';

public function __construct(private int $serverMode)
public function __construct(private readonly int $serverMode)
{
parent::__construct();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/StopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StopCommand extends Command

public function __construct(private PidManager $pidManager)
{
$this->killProcess = Closure::fromCallable([SwooleProcess::class, 'kill']);
$this->killProcess = SwooleProcess::kill(...);
parent::__construct();
}

Expand Down
6 changes: 2 additions & 4 deletions src/Event/AbstractTaskEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

abstract class AbstractTaskEvent extends AbstractServerAwareEvent
{
/** @var mixed */
protected $data;
protected mixed $data;

protected int $taskId;

Expand All @@ -20,8 +19,7 @@ public function getTaskId(): int
return $this->taskId;
}

/** @return mixed */
public function getData()
public function getData(): mixed
{
return $this->data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Event/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

class EventDispatcher implements EventDispatcherInterface
{
public function __construct(private ListenerProviderInterface $listenerProvider)
public function __construct(private readonly ListenerProviderInterface $listenerProvider)
{
}

/**
* @return object Returns the event passed to the method.
*/
public function dispatch(object $event)
public function dispatch(object $event): object
{
$stoppable = $event instanceof StoppableEventInterface;

Expand Down
6 changes: 3 additions & 3 deletions src/Event/HotCodeReloaderWorkerStartListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function __construct(
/**
* A file watcher to monitor changes in files.
*/
private FileWatcherInterface $fileWatcher,
private LoggerInterface $logger,
private int $interval
private readonly FileWatcherInterface $fileWatcher,
private readonly LoggerInterface $logger,
private readonly int $interval
) {
}

Expand Down
6 changes: 4 additions & 2 deletions src/Event/RequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class RequestEvent implements StoppableEventInterface
{
private bool $responseSent = false;

public function __construct(private SwooleHttpRequest $request, private SwooleHttpResponse $response)
{
public function __construct(
private readonly SwooleHttpRequest $request,
private readonly SwooleHttpResponse $response
) {
}

public function isPropagationStopped(): bool
Expand Down
Loading