Passed
Pull Request — 1.x (#99)
by Akihito
10:41
created

ResourceStorageSaver::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 6
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\Resource\AbstractUri;
8
use Psr\Cache\CacheItemPoolInterface;
9
use Symfony\Component\Cache\CacheItem;
10
11
use function assert;
12
13
final class ResourceStorageSaver
14
{
15
    /**
16
     * @param mixed        $value
17
     * @param list<string> $tags
0 ignored issues
show
Bug introduced by
The type BEAR\QueryRepository\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
     */
19
    public function __invoke(string $key, $value, CacheItemPoolInterface $pool, AbstractUri $uri, array $tags, ?int $ttl): bool
20
    {
21
        $cacheItem = $pool->getItem($key);
22
        $cacheItem->set($value);
23
        assert($cacheItem instanceof CacheItem);
24
        $cacheItem->tag($tags);
25
26
        if ($ttl) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $ttl of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
27
            $cacheItem->expiresAfter($ttl);
28
        }
29
30
        return $pool->save($cacheItem);
31
    }
32
}
33