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

Refactor StreamWrapper and raise psalm level to 4 #221

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 4 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
errorLevel="4"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -13,4 +13,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
20 changes: 9 additions & 11 deletions src/Collector/Console/CommandCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ public function collect(ConsoleEvent|ConsoleErrorEvent|ConsoleTerminateEvent $ev
return;
}

/** @noinspection PhpConditionAlreadyCheckedInspection */
if ($event instanceof ConsoleEvent) {
$this->commands[$event::class] = [
'name' => $command->getName(),
'command' => $command,
'input' => $this->castInputToString($event->getInput()),
'output' => $this->fetchOutput($event->getOutput()),
'arguments' => $command->getDefinition()->getArguments(),
'options' => $command->getDefinition()->getOptions(),
];
}
// $event instance of ConsoleEvent
$this->commands[$event::class] = [
'name' => $command->getName(),
'command' => $command,
'input' => $this->castInputToString($event->getInput()),
'output' => $this->fetchOutput($event->getOutput()),
'arguments' => $command->getDefinition()->getArguments(),
'options' => $command->getDefinition()->getOptions(),
];
}

public function getSummary(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/Console/ConsoleAppInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getCollected(): array

public function collect(object $event): void
{
if (!is_object($event) || !$this->isActive()) {
if (!$this->isActive()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Collector/Stream/FilesystemStreamProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FilesystemStreamProxy implements StreamWrapperInterface
* @var resource|null
*/
public $context;
public StreamWrapperInterface $decorated;
public StreamWrapper $decorated;
xepozz marked this conversation as resolved.
Show resolved Hide resolved
public bool $ignored = false;

public static ?FilesystemStreamCollector $collector = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/Stream/HttpStreamProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HttpStreamProxy implements StreamWrapperInterface
* @var resource|null
*/
public $context;
public StreamWrapperInterface $decorated;
public StreamWrapper $decorated;
xepozz marked this conversation as resolved.
Show resolved Hide resolved
public bool $ignored = false;

public static ?HttpStreamCollector $collector = null;
Expand Down
4 changes: 1 addition & 3 deletions src/Collector/Web/RequestCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;

use function is_object;

final class RequestCollector implements SummaryCollectorInterface
{
use CollectorTrait;
Expand Down Expand Up @@ -80,7 +78,7 @@ public function getCollected(): array

public function collect(object $event): void
{
if (!is_object($event) || !$this->isActive()) {
if (!$this->isActive()) {
return;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Collector/Web/WebAppInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;

use function is_object;

final class WebAppInfoCollector implements SummaryCollectorInterface
{
use CollectorTrait;
Expand All @@ -39,7 +37,7 @@ public function getCollected(): array

public function collect(object $event): void
{
if (!is_object($event) || !$this->isActive()) {
if (!$this->isActive()) {
return;
}

Expand Down
15 changes: 6 additions & 9 deletions src/Helper/StreamWrapper/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ final class StreamWrapper implements StreamWrapperInterface
public ?string $filename = null;

/**
* @var resource|null
* @var false|resource
*/
public $stream = null;
public $stream = false;

public function dir_closedir(): bool
{
Expand All @@ -49,12 +49,7 @@ public function dir_readdir(): false|string

public function dir_rewinddir(): bool
{
if (!is_resource($this->stream)) {
return false;
}

rewinddir($this->stream);
/** @noinspection PhpConditionAlreadyCheckedInspection */
return is_resource($this->stream);
}

Expand All @@ -76,7 +71,9 @@ public function rmdir(string $path, int $options): bool

public function stream_cast(int $castAs)
{
//????
// ????

return false;
}

public function stream_eof(): bool
Expand Down Expand Up @@ -183,7 +180,7 @@ public function stream_close(): void
* @psalm-suppress InvalidPropertyAssignmentValue
*/
fclose($this->stream);
$this->stream = null;
$this->stream = false;
}

public function stream_lock(int $operation): bool
Expand Down
3 changes: 3 additions & 0 deletions src/Helper/StreamWrapper/StreamWrapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function stream_eof(): bool;

public function stream_seek(int $offset, int $whence = SEEK_SET): bool;

/**
* @return false|resource
*/
public function stream_cast(int $castAs);

public function stream_stat(): array|false;
Expand Down