diff --git a/src/Filesystem.php b/src/Filesystem.php index 4422045..f7bf20b 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -80,20 +80,15 @@ final class Filesystem extends AbstractAdapter implements /** * An identity for the last filespec * (cache directory + namespace prefix + key + directory level) - * - * @var string */ - private $lastFileSpecId = ''; + private string $lastFileSpecId = ''; /** * The last used filespec - * - * @var string */ - private $lastFileSpec = ''; + private string $lastFileSpec = ''; - /** @var FilesystemInteractionInterface */ - private $filesystem; + private FilesystemInteractionInterface $filesystem; /** * @param null|array|Traversable|AdapterOptions $options @@ -106,10 +101,10 @@ public function __construct($options = null, ?FilesystemInteractionInterface $fi // clean total space buffer on change cache_dir $events = $this->getEventManager(); - $handle = function (): void { + $handle = static function (): void { }; $totalSpace = &$this->totalSpace; - $callback = function ($event) use (&$events, &$handle, &$totalSpace) { + $callback = static function ($event) use (&$events, &$handle, &$totalSpace): void { $params = $event->getParams(); if (isset($params['cache_dir'])) { $totalSpace = null; @@ -1298,7 +1293,7 @@ protected function internalGetCapabilities() ); // update capabilities on change options - $this->getEventManager()->attach('option', function ($event) use ($capabilities, $marker) { + $this->getEventManager()->attach('option', static function ($event) use ($capabilities, $marker): void { $params = $event->getParams(); if (isset($params['namespace_separator'])) { diff --git a/src/Filesystem/Exception/MetadataException.php b/src/Filesystem/Exception/MetadataException.php index abbfd07..b3d06ed 100644 --- a/src/Filesystem/Exception/MetadataException.php +++ b/src/Filesystem/Exception/MetadataException.php @@ -17,8 +17,7 @@ final class MetadataException extends RuntimeException public const METADATA_MTIME = Filesystem::METADATA_MTIME; public const METADATA_FILESIZE = Filesystem::METADATA_FILESIZE; - /** @var ErrorException */ - private $error; + private ErrorException $error; /** * @psalm-param MetadataException::METADATA_* $metadata diff --git a/src/Filesystem/Exception/UnlinkException.php b/src/Filesystem/Exception/UnlinkException.php index 633d123..cc228fd 100644 --- a/src/Filesystem/Exception/UnlinkException.php +++ b/src/Filesystem/Exception/UnlinkException.php @@ -11,8 +11,7 @@ final class UnlinkException extends RuntimeException { - /** @var ErrorException */ - private $error; + private ErrorException $error; public function __construct(string $path, ErrorException $error) { diff --git a/src/FilesystemIterator.php b/src/FilesystemIterator.php index a37e872..ddb8388 100644 --- a/src/FilesystemIterator.php +++ b/src/FilesystemIterator.php @@ -5,6 +5,7 @@ namespace Laminas\Cache\Storage\Adapter; use GlobIterator; +use Laminas\Cache\Storage\Adapter\Filesystem; use Laminas\Cache\Storage\IteratorInterface; use ReturnTypeWillChange; @@ -15,38 +16,28 @@ final class FilesystemIterator implements IteratorInterface { /** * The Filesystem storage instance - * - * @var Filesystem */ - protected $storage; + private Filesystem $storage; /** * The iterator mode - * - * @var int */ - protected $mode = IteratorInterface::CURRENT_AS_KEY; + private int $mode = IteratorInterface::CURRENT_AS_KEY; /** * The GlobIterator instance - * - * @var GlobIterator */ - protected $globIterator; + private GlobIterator $globIterator; /** * The namespace sprefix - * - * @var string */ - protected $prefix; + private string $prefix; /** * String length of namespace prefix - * - * @var int */ - protected $prefixLength; + private int $prefixLength; /** * Constructor diff --git a/src/FilesystemOptions.php b/src/FilesystemOptions.php index eab90dd..e849b8d 100644 --- a/src/FilesystemOptions.php +++ b/src/FilesystemOptions.php @@ -7,6 +7,7 @@ use Laminas\Cache\Exception; use Traversable; +use function assert; use function is_dir; use function is_readable; use function is_string; @@ -28,23 +29,19 @@ final class FilesystemOptions extends AdapterOptions /** * Directory to store cache files * - * @var string The cache directory + * @var string|null The cache directory */ - private $cacheDir; + private ?string $cacheDir = null; /** * Call clearstatcache enabled? - * - * @var bool */ - private $clearStatCache = true; + private bool $clearStatCache = true; /** * How much sub-directaries should be created? - * - * @var int */ - private $dirLevel = 1; + private int $dirLevel = 1; /** * Permission creating new directories @@ -55,10 +52,8 @@ final class FilesystemOptions extends AdapterOptions /** * Lock files on writing - * - * @var bool */ - private $fileLocking = true; + private bool $fileLocking = true; /** * Permission creating new files @@ -76,24 +71,18 @@ final class FilesystemOptions extends AdapterOptions /** * Namespace separator - * - * @var string */ - private $namespaceSeparator = '-'; + private string $namespaceSeparator = '-'; /** * Don't get 'fileatime' as 'atime' on metadata - * - * @var bool */ - private $noAtime = true; + private bool $noAtime = true; /** * Don't get 'filectime' as 'ctime' on metadata - * - * @var bool */ - private $noCtime = true; + private bool $noCtime = true; /** * Umask to create files and directories @@ -104,17 +93,13 @@ final class FilesystemOptions extends AdapterOptions /** * Suffix for cache files - * - * @var string */ - private $suffix = 'dat'; + private string $suffix = 'dat'; /** * Suffix for tag files - * - * @var string */ - private $tagSuffix = 'tag'; + private string $tagSuffix = 'tag'; /** * @param array|Traversable|null $options @@ -137,8 +122,8 @@ public function __construct($options = null) */ public function setCacheDir(?string $cacheDir): self { - $cacheDir = $cacheDir ?? sys_get_temp_dir(); - $cacheDir = $this->normalizeCacheDirectory($cacheDir); + $cacheDir ??= sys_get_temp_dir(); + $cacheDir = $this->normalizeCacheDirectory($cacheDir); if ($this->cacheDir === $cacheDir) { return $this; @@ -151,6 +136,8 @@ public function setCacheDir(?string $cacheDir): self public function getCacheDir(): string { + assert(is_string($this->cacheDir)); + return $this->cacheDir; } diff --git a/test/integration/Psr/SimpleCache/FilesystemIntegrationTest.php b/test/integration/Psr/SimpleCache/FilesystemIntegrationTest.php index 4531843..46b66c3 100644 --- a/test/integration/Psr/SimpleCache/FilesystemIntegrationTest.php +++ b/test/integration/Psr/SimpleCache/FilesystemIntegrationTest.php @@ -10,6 +10,7 @@ use Laminas\Cache\Storage\StorageInterface; use LaminasTest\Cache\Storage\Adapter\AbstractSimpleCacheIntegrationTest; +use function assert; use function getenv; use function mkdir; use function sys_get_temp_dir; @@ -25,8 +26,7 @@ class FilesystemIntegrationTest extends AbstractSimpleCacheIntegrationTest /** @var int */ protected $umask; - /** @var FilesystemOptions */ - private $options; + private ?FilesystemOptions $options = null; protected function setUp(): void { @@ -52,6 +52,8 @@ protected function tearDown(): void $this->fail('Umask was not reset'); } + assert($this->options instanceof FilesystemOptions); + if ($this->options->getCacheDir() !== $this->tmpCacheDir) { $this->options->setCacheDir($this->tmpCacheDir); } diff --git a/test/unit/Filesystem/AdapterPluginManagerDelegatorFactoryTest.php b/test/unit/Filesystem/AdapterPluginManagerDelegatorFactoryTest.php index 1f4307d..07c55ae 100644 --- a/test/unit/Filesystem/AdapterPluginManagerDelegatorFactoryTest.php +++ b/test/unit/Filesystem/AdapterPluginManagerDelegatorFactoryTest.php @@ -13,8 +13,7 @@ final class AdapterPluginManagerDelegatorFactoryTest extends TestCase { use PluginManagerDelegatorFactoryTestTrait; - /** @var AdapterPluginManagerDelegatorFactory */ - private $delegator; + private AdapterPluginManagerDelegatorFactory $delegator; public function getCommonAdapterNamesProvider(): iterable { diff --git a/test/unit/Filesystem/ConfigProviderTest.php b/test/unit/Filesystem/ConfigProviderTest.php index 3ec874a..fd11473 100644 --- a/test/unit/Filesystem/ConfigProviderTest.php +++ b/test/unit/Filesystem/ConfigProviderTest.php @@ -11,8 +11,7 @@ final class ConfigProviderTest extends TestCase { - /** @var ConfigProvider */ - private $provider; + private ConfigProvider $provider; protected function setUp(): void { diff --git a/test/unit/Filesystem/ModuleTest.php b/test/unit/Filesystem/ModuleTest.php index 38848e2..ca40eda 100644 --- a/test/unit/Filesystem/ModuleTest.php +++ b/test/unit/Filesystem/ModuleTest.php @@ -10,8 +10,7 @@ final class ModuleTest extends TestCase { - /** @var Module */ - private $module; + private Module $module; protected function setUp(): void { diff --git a/test/unit/Filesystem/TestAsset/DelayedFilesystemInteraction.php b/test/unit/Filesystem/TestAsset/DelayedFilesystemInteraction.php index 0d8acbe..e007845 100644 --- a/test/unit/Filesystem/TestAsset/DelayedFilesystemInteraction.php +++ b/test/unit/Filesystem/TestAsset/DelayedFilesystemInteraction.php @@ -11,14 +11,10 @@ final class DelayedFilesystemInteraction implements FilesystemInteractionInterface { - /** @var FilesystemInteractionInterface */ - private $filesystem; - - /** - * @var int - * @psalm-var positive-int - */ - private $delay; + private FilesystemInteractionInterface $filesystem; + + /** @psalm-var positive-int */ + private int $delay; /** @psalm-param positive-int $delay */ public function __construct(int $delay) diff --git a/test/unit/FilesystemTest.php b/test/unit/FilesystemTest.php index e9346cd..59b3da4 100644 --- a/test/unit/FilesystemTest.php +++ b/test/unit/FilesystemTest.php @@ -39,11 +39,9 @@ */ final class FilesystemTest extends AbstractCommonAdapterTest { - /** @var string */ - protected $tmpCacheDir; + protected string $tmpCacheDir; - /** @var int */ - protected $umask; + protected int $umask; protected function setUp(): void {