Skip to content
Open
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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"psr/cache": "^1.0",
"psr/log": "^1.1",
"psr/simple-cache": "^1.0",
"php": "^8.0",
"psr/cache": "^1 || ^2 || ^3",
"psr/log": "^1 || ^2 || ^3",
"psr/simple-cache": "^1 || ^2 || ^3",
"symfony/contracts": "^1.1.8 || ^2.0 || ^3.0",
"symfony/polyfill-php80": "^1.18"
},
Expand Down
29 changes: 9 additions & 20 deletions src/main/AntiStampedeCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,8 @@ static function ($deferred, $namespace, &$expiredIds) use ($getId, $defaultLifet

/**
* @inheritDoc
*
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function commit()
public function commit(): bool
{
$ok = true;
$byLifetime = $this->mergeByLifetime;
Expand All @@ -140,8 +137,8 @@ public function commit()
if (true === $e) {
continue;
}
if (is_array($e) || 1 === count($values)) {
foreach (is_array($e) ? $e : array_keys($values) as $id) {
if (1 === count($values)) {
foreach (array_keys($values) as $id) {
$ok = false;
$v = $values[$id];
$type = get_debug_type($v);
Expand All @@ -154,7 +151,7 @@ public function commit()
$this->logger,
$message,
[
'key' => substr($id, strlen($this->namespace)),
'key' => substr($id, strlen($this->namespace ?? '')),
'exception' => $e instanceof Exception ? $e : null,
'cache-adapter' => get_debug_type($this),
]
Expand Down Expand Up @@ -209,9 +206,8 @@ public function commit()
* @param array<string, mixed> $values
*
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): bool
{
$result = 1;
foreach ($values as $key => $value) {
Expand All @@ -234,9 +230,8 @@ protected function doSave(array $values, int $lifetime)
* @inheritDoc
*
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
return $this->getCache()->has($id);
}
Expand All @@ -247,9 +242,8 @@ protected function doHave(string $id)
* @param array<string> $ids
*
* @return array<string, mixed>
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): array
{
$result = [];
foreach ($this->getCache()->getMultiple($ids, self::CACHE_MISS_VALUE) as $key => $value) {
Expand All @@ -268,9 +262,8 @@ protected function doFetch(array $ids)
* @param array<string> $ids
*
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
return $this->getCache()->deleteMultiple($ids);
}
Expand All @@ -279,16 +272,12 @@ protected function doDelete(array $ids)
* @inheritDoc
*
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
return $this->getCache()->clear();
}

/**
* @return Cache
*/
protected function getCache(): Cache
{
return Cache::create()
Expand Down
16 changes: 8 additions & 8 deletions src/main/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function callback(callable $callback)
* @return mixed Значение из кеша или $default в случае "промаха".
* @noinspection PhpMissingParamTypeInspection
*/
public function get($key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
$this->setKey($key);
$initCache = $this->getBitrixCache()->initCache(
Expand Down Expand Up @@ -235,7 +235,7 @@ public function get($key, $default = null)
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function set($key, $value, $ttl = null)
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
{
$this->setKey($key)
->setMixedTTL($ttl);
Expand Down Expand Up @@ -270,7 +270,7 @@ public function set($key, $value, $ttl = null)
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function delete($key)
public function delete(string $key): bool
{
$this->setKey($key);
$initCache = $this->getBitrixCache()->initCache(
Expand All @@ -295,7 +295,7 @@ public function delete($key)
* @return bool true при успешной очистке или false при ошибке.
* @noinspection PhpMissingReturnTypeInspection
*/
public function clear()
public function clear(): bool
{
$this->getBitrixCache()
->cleanDir($this->getPath(), $this->getBaseDir());
Expand All @@ -314,7 +314,7 @@ public function clear()
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function getMultiple($keys, $default = null)
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$this->assertKeys($keys, 'Keys');

Expand All @@ -337,7 +337,7 @@ public function getMultiple($keys, $default = null)
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function setMultiple($values, $ttl = null)
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
{
$this->assertKeys($values, 'Values');
$result = 1;
Expand All @@ -358,7 +358,7 @@ public function setMultiple($values, $ttl = null)
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function deleteMultiple($keys)
public function deleteMultiple(iterable $keys): bool
{
$this->assertKeys($keys, 'Keys');
$result = 1;
Expand All @@ -385,7 +385,7 @@ public function deleteMultiple($keys)
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpMissingReturnTypeInspection
*/
public function has($key)
public function has(string $key): bool
{
$this->setKey($key);

Expand Down
28 changes: 6 additions & 22 deletions src/main/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getKey(): string
/**
* {@inheritdoc}
*/
public function get()
public function get(): mixed
{
return $this->value;
}
Expand All @@ -82,7 +82,7 @@ public function isHit(): bool
*
* @return $this
*/
public function set($value): self
public function set(mixed $value): static
{
$this->value = $value;

Expand All @@ -94,20 +94,12 @@ public function set($value): self
*
* @return $this
*/
public function expiresAt($expiration): self
public function expiresAt(?\DateTimeInterface $expiration): static
{
if (null === $expiration) {
$this->expiry = null;
} elseif ($expiration instanceof DateTimeInterface) {
$this->expiry = (float)$expiration->format('U.u');
} else {
throw new InvalidArgumentException(
sprintf(
'Expiration date must implement DateTimeInterface or be null, "%s" given.',
get_debug_type($expiration)
),
ErrorCode::INVALID_EXPIRATION_DATE
);
$this->expiry = (float)$expiration->format('U.u');
}

return $this;
Expand All @@ -118,7 +110,7 @@ public function expiresAt($expiration): self
*
* @return $this
*/
public function expiresAfter($time): self
public function expiresAfter(int|\DateInterval|null $time): static
{
if (null === $time) {
$this->expiry = null;
Expand All @@ -127,14 +119,6 @@ public function expiresAfter($time): self
+ (float)DateTime::createFromFormat('U', '0')->add($time)->format('U.u');
} elseif (is_int($time)) {
$this->expiry = $time + microtime(true);
} else {
throw new InvalidArgumentException(
sprintf(
'Expiration date must be an integer, a DateInterval or null, "%s" given.',
get_debug_type($time)
),
ErrorCode::INVALID_EXPIRATION
);
}

return $this;
Expand All @@ -143,7 +127,7 @@ public function expiresAfter($time): self
/**
* {@inheritdoc}
*/
public function tag($tags): ItemInterface
public function tag($tags): static
{
if (!$this->isTaggable) {
throw new LogicException(
Expand Down
1 change: 0 additions & 1 deletion src/main/LockRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static function setFiles(array $files): array
* @param null|Closure $setMetadata
* @param null|LoggerInterface $logger
*
* @phpstan-ignore-next-line
* @throws PsrCacheInvalidArgumentException
* @throws Exception
* @return null|mixed
Expand Down
19 changes: 9 additions & 10 deletions src/main/Traits/AbstractAdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract protected function doSave(array $values, int $lifetime);
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function hasItem($key)
public function hasItem(string $key): bool
{
$id = $this->getId($key);

Expand All @@ -151,7 +151,7 @@ public function hasItem($key)
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function clear(string $prefix = '')
public function clear(string $prefix = ''): bool
{
$this->deferred = [];
if ($cleared = $this->versioningIsEnabled) {
Expand Down Expand Up @@ -195,7 +195,7 @@ public function clear(string $prefix = '')
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function deleteItem($key)
public function deleteItem(string $key): bool
{
return $this->deleteItems([$key]);
}
Expand All @@ -206,7 +206,7 @@ public function deleteItem($key)
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function deleteItems(array $keys)
public function deleteItems(array $keys): bool
{
$ids = [];

Expand Down Expand Up @@ -248,7 +248,7 @@ public function deleteItems(array $keys)
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(string $key): CacheItemInterface
{
if ($this->deferred) {
$this->commit();
Expand Down Expand Up @@ -279,9 +279,8 @@ public function getItem($key)
/**
* {@inheritdoc}
* @return iterable<string, mixed>
* @noinspection PhpMissingReturnTypeInspection
*/
public function getItems(array $keys = [])
public function getItems(array $keys = []): iterable
{
if ($this->deferred) {
$this->commit();
Expand Down Expand Up @@ -312,7 +311,7 @@ public function getItems(array $keys = [])
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function save(CacheItemInterface $item)
public function save(CacheItemInterface $item): bool
{
if (!$item instanceof CacheItem) {
return false;
Expand Down Expand Up @@ -342,7 +341,7 @@ public function save(CacheItemInterface $item)
* @return bool
* @noinspection PhpMissingReturnTypeInspection
*/
public function saveDeferred(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item): bool
{
if (!$item instanceof CacheItem) {
return false;
Expand Down Expand Up @@ -387,7 +386,7 @@ public function reset(): void
$this->ids = [];
}

public function __sleep()
public function __sleep(): array
{
throw new BadMethodCallException('Cannot serialize ' . __CLASS__);
}
Expand Down
Loading