Skip to content

Commit

Permalink
Merge pull request #64 from samsonasik/apply-php74
Browse files Browse the repository at this point in the history
Apply PHP 7.4 syntax and typed property
  • Loading branch information
Ocramius committed Sep 16, 2022
2 parents d9712a8 + 3d60942 commit abf1e74
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 78 deletions.
17 changes: 6 additions & 11 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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'])) {
Expand Down
3 changes: 1 addition & 2 deletions src/Filesystem/Exception/MetadataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/Filesystem/Exception/UnlinkException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

final class UnlinkException extends RuntimeException
{
/** @var ErrorException */
private $error;
private ErrorException $error;

public function __construct(string $path, ErrorException $error)
{
Expand Down
21 changes: 6 additions & 15 deletions src/FilesystemIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\Cache\Storage\Adapter;

use GlobIterator;
use Laminas\Cache\Storage\Adapter\Filesystem;
use Laminas\Cache\Storage\IteratorInterface;
use ReturnTypeWillChange;

Expand All @@ -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
Expand Down
43 changes: 15 additions & 28 deletions src/FilesystemOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -151,6 +136,8 @@ public function setCacheDir(?string $cacheDir): self

public function getCacheDir(): string
{
assert(is_string($this->cacheDir));

return $this->cacheDir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,8 +26,7 @@ class FilesystemIntegrationTest extends AbstractSimpleCacheIntegrationTest
/** @var int */
protected $umask;

/** @var FilesystemOptions */
private $options;
private ?FilesystemOptions $options = null;

protected function setUp(): void
{
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class AdapterPluginManagerDelegatorFactoryTest extends TestCase
{
use PluginManagerDelegatorFactoryTestTrait;

/** @var AdapterPluginManagerDelegatorFactory */
private $delegator;
private AdapterPluginManagerDelegatorFactory $delegator;

public function getCommonAdapterNamesProvider(): iterable
{
Expand Down
3 changes: 1 addition & 2 deletions test/unit/Filesystem/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

final class ConfigProviderTest extends TestCase
{
/** @var ConfigProvider */
private $provider;
private ConfigProvider $provider;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/unit/Filesystem/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

final class ModuleTest extends TestCase
{
/** @var Module */
private $module;
private Module $module;

protected function setUp(): void
{
Expand Down
12 changes: 4 additions & 8 deletions test/unit/Filesystem/TestAsset/DelayedFilesystemInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions test/unit/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit abf1e74

Please sign in to comment.