Skip to content

Commit

Permalink
remove a lot of psalm error
Browse files Browse the repository at this point in the history
  • Loading branch information
fezfez committed Nov 8, 2023
1 parent 80763ac commit c02f326
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 122 deletions.
133 changes: 20 additions & 113 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,142 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Filesystem.php">
<ImplementedReturnTypeMismatch occurrences="2">
<code>bool</code>
<code>bool</code>
</ImplementedReturnTypeMismatch>
<ImplicitToStringCast occurrences="3">
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
</ImplicitToStringCast>
<InvalidReturnStatement occurrences="2">
<code>parent::addItems($keyValuePairs)</code>
<code>parent::replaceItems($keyValuePairs)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="2">
<code>bool</code>
<code>bool</code>
</InvalidReturnType>
<LessSpecificReturnStatement occurrences="1">
<code>parent::setOptions($options)</code>
</LessSpecificReturnStatement>
<MissingClosureParamType occurrences="3">
<code>$dir</code>
<code>$event</code>
<code>$event</code>
</MissingClosureParamType>
<MixedArgument occurrences="2">
<MixedArgument>
<code>$key</code>
<code>$params['namespace_separator']</code>
<code><![CDATA[$params['namespace_separator']]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="1">
<code>$metadata</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="1">
<code>$params['namespace_separator']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="6">
<MixedAssignment>
<code>$content</code>
<code>$contents[$this-&gt;formatFilename($filespec)]</code>
<code><![CDATA[$contents[$this->formatFilename($filespec)]]]></code>
<code>$key</code>
<code>$params</code>
<code>$params</code>
<code>$value</code>
</MixedAssignment>
<MixedFunctionCall occurrences="1">
<code>$clearFolder($pathname)</code>
</MixedFunctionCall>
<MixedInferredReturnType occurrences="4">
<MixedInferredReturnType>
<code>FilesystemOptions</code>
<code>bool</code>
<code>bool</code>
<code>bool</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="4">
<code>attach</code>
<code>detach</code>
<code>getParams</code>
<code>getParams</code>
</MixedMethodCall>
<MixedOperand occurrences="1">
<code>$dir</code>
</MixedOperand>
<MixedReturnStatement occurrences="4">
<code>$this-&gt;options</code>
<MixedReturnStatement>
<code><![CDATA[$this->options]]></code>
</MixedReturnStatement>
<MoreSpecificImplementedParamType occurrences="1">
<PossiblyInvalidArgument>
<code>$options</code>
</MoreSpecificImplementedParamType>
<MoreSpecificReturnType occurrences="1">
<code>Filesystem</code>
</MoreSpecificReturnType>
<PossiblyInvalidArgument occurrences="7">
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
<code>$pathname</code>
</PossiblyInvalidArgument>
<PossiblyUndefinedVariable occurrences="2">
<code>$diff</code>
<code>$diff</code>
</PossiblyUndefinedVariable>
<PropertyNotSetInConstructor occurrences="1">
<code>Filesystem</code>
</PropertyNotSetInConstructor>
<RedundantCastGivenDocblockType occurrences="2">
<RedundantCastGivenDocblockType>
<code>(string) $namespace</code>
<code>(string) $prefix</code>
</RedundantCastGivenDocblockType>
<UnusedVariable occurrences="1">
<code>$clearFolder</code>
</UnusedVariable>
</file>
<file src="src/Filesystem/AdapterPluginManagerDelegatorFactory.php">
<InvalidArgument occurrences="1"/>
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$totalSpace = &$this->totalSpace]]></code>
</UnsupportedPropertyReferenceUsage>
<UnsupportedReferenceUsage>
<code><![CDATA[$contents[$this->formatFilename($filespec)] = &$value]]></code>
</UnsupportedReferenceUsage>
</file>
<file src="src/FilesystemIterator.php">
<RedundantCastGivenDocblockType occurrences="1">
<RedundantCastGivenDocblockType>
<code>(int) $mode</code>
</RedundantCastGivenDocblockType>
</file>
<file src="src/FilesystemOptions.php">
<PossiblyInvalidArgument occurrences="1">
<MixedArgumentTypeCoercion>
<code>$options</code>
</PossiblyInvalidArgument>
<PossiblyInvalidPropertyAssignmentValue occurrences="3">
<code>$dirPermission</code>
<code>$filePermission</code>
<code>$umask</code>
</PossiblyInvalidPropertyAssignmentValue>
<RedundantCastGivenDocblockType occurrences="3">
</MixedArgumentTypeCoercion>
<RedundantCastGivenDocblockType>
<code>(int) $dirPermission</code>
<code>(int) $filePermission</code>
<code>(int) $umask</code>
</RedundantCastGivenDocblockType>
</file>
<file src="test/integration/Psr/SimpleCache/FilesystemIntegrationTest.php">
<PossiblyFalseArgument occurrences="1">
<code>$cacheDir</code>
</PossiblyFalseArgument>
</file>
<file src="test/unit/FilesystemTest.php">
<MixedOperand occurrences="2">
<code>$meta['filespec']</code>
<code>$meta['filespec']</code>
</MixedOperand>
<PossiblyFalseArgument occurrences="1">
<code>$cacheDir</code>
</PossiblyFalseArgument>
<PossiblyNullArrayAccess occurrences="2">
<code>$err['message']</code>
<code>$err['message']</code>
</PossiblyNullArrayAccess>
<UnusedVariable occurrences="1">
<code>$glob</code>
</UnusedVariable>
</file>
</files>
7 changes: 5 additions & 2 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Laminas\EventManager\EventInterface;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Stdlib\ErrorHandler;
use SplObjectStorage;
use stdClass;
use Traversable;

Expand All @@ -39,6 +40,7 @@
use function func_num_args;
use function glob;
use function implode;
use function is_callable;
use function is_string;
use function max;
use function md5;
Expand Down Expand Up @@ -102,8 +104,8 @@ final class Filesystem extends AbstractAdapter implements
public function __construct($options = null, ?FilesystemInteractionInterface $filesystem = null)
{
parent::__construct($options);
$this->pluginRegistry = new \SplObjectStorage();
$this->filesystem = $filesystem ?? new LocalFilesystemInteraction();
$this->pluginRegistry = new SplObjectStorage();
$this->filesystem = $filesystem ?? new LocalFilesystemInteraction();

// clean total space buffer on change cache_dir
$events = $this->getEventManager();
Expand Down Expand Up @@ -230,6 +232,7 @@ public function clearExpired()

ErrorHandler::start();
foreach ($glob as $pathname) {
$pathname = (string) $pathname;
// get last modification time of the file but ignore if the file is missing
// to fix a possible race condition if another process removed the file already.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use function assert;
use function getenv;
use function is_string;
use function mkdir;
use function sys_get_temp_dir;
use function tempnam;
Expand Down
27 changes: 20 additions & 7 deletions test/unit/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
use Laminas\Cache\Storage\Plugin\PluginOptions;
use LaminasTest\Cache\Storage\Adapter\Filesystem\TestAsset\DelayedFilesystemInteraction;

use function array_key_exists;
use function chmod;
use function count;
use function error_get_last;
use function fileatime;
use function filectime;
use function getenv;
use function glob;
use function is_array;
use function is_string;
use function md5;
use function mkdir;
use function pcntl_fork;
use function posix_getpid;
use function posix_kill;
use function sleep;
use function sprintf;
use function str_repeat;
use function substr;
use function sys_get_temp_dir;
Expand All @@ -47,21 +51,26 @@ protected function setUp(): void
{
$this->umask = umask();

if (getenv('TESTS_LAMINAS_CACHE_FILESYSTEM_DIR')) {
$cacheDir = getenv('TESTS_LAMINAS_CACHE_FILESYSTEM_DIR');
} else {
$cacheDir = sys_get_temp_dir();
}
$cacheDir = getenv('TESTS_LAMINAS_CACHE_FILESYSTEM_DIR');
$cacheDir = is_string($cacheDir) ? $cacheDir : sys_get_temp_dir();

$getMessage = static function (array|null $value): string {
if (! is_array($value) || ! array_key_exists('message', $value) || ! is_string($value['message'])) {
return 'no information';
}

return $value['message'];
};

$this->tmpCacheDir = tempnam($cacheDir, 'laminas_cache_test_');
if (! $this->tmpCacheDir) {
$this->fail("Can't create temporary cache directory-file.");
} elseif (! @unlink($this->tmpCacheDir)) {
$err = error_get_last();
$this->fail("Can't remove temporary cache directory-file: {$err['message']}");
$this->fail(sprintf("Can't remove temporary cache directory-file: %s", $getMessage($err)));
} elseif (! @mkdir($this->tmpCacheDir, 0777)) {
$err = error_get_last();
$this->fail("Can't create temporary cache directory: {$err['message']}");
$this->fail(sprintf("Can't create temporary cache directory: %s", $getMessage($err)));
}

$this->options = new FilesystemOptions([
Expand Down Expand Up @@ -127,6 +136,8 @@ public function testGetMetadataWithCtime(): void

$meta = $this->storage->getMetadata('test');
$this->assertIsArray($meta);
$this->assertArrayHasKey('filespec', $meta);
$this->assertIsString($meta['filespec']);

$expectedCtime = filectime($meta['filespec'] . '.dat');
$this->assertEquals($expectedCtime, $meta['ctime']);
Expand All @@ -140,6 +151,8 @@ public function testGetMetadataWithAtime(): void

$meta = $this->storage->getMetadata('test');
$this->assertIsArray($meta);
$this->assertArrayHasKey('filespec', $meta);
$this->assertIsString($meta['filespec']);

$expectedAtime = fileatime($meta['filespec'] . '.dat');
$this->assertEquals($expectedAtime, $meta['atime']);
Expand Down

0 comments on commit c02f326

Please sign in to comment.