Issues (35)

src/Service/Cache.php (6 issues)

1
<?php
2
3
namespace Xima\DepmonBundle\Service;
4
5
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
6
use Symfony\Component\Cache\Simple\FilesystemCache;
7
8
/**
9
 * Class Cache
10
 * @package Xima\DepmonBundle\Service
11
 */
12
class Cache
13
{
14
15
    /**
16
     * @var FilesystemAdapter
17
     */
18
    private $cache;
19
20
    public function __construct($cacheDirectory = null)
21
    {
22
        if (!$cacheDirectory) {
23
            $cacheDirectory = __DIR__ . '/../../../../var/cache/app';
24
        }
25
26
        $this->cache = new FilesystemCache(
0 ignored issues
show
Documentation Bug introduced by
It seems like new Symfony\Component\Ca...n', 0, $cacheDirectory) of type Symfony\Component\Cache\Simple\FilesystemCache is incompatible with the declared type Symfony\Component\Cache\Adapter\FilesystemAdapter of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
            'depmon',
28
            0,
29
            $cacheDirectory
30
        );
31
    }
32
33
    /**
34
     *
35
     */
36
    public function get($key)
37
    {
38
        try {
39
            return $this->cache->get($key);
0 ignored issues
show
The call to Symfony\Component\Cache\...\AbstractAdapter::get() has too few arguments starting with callback. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
            return $this->cache->/** @scrutinizer ignore-call */ get($key);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
40
        } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
41
        }
42
    }
43
44
    /**
45
     *
46
     */
47
    public function set($key, $value): bool
48
    {
49
        try {
50
            return $this->cache->set($key, $value);
0 ignored issues
show
The method set() does not exist on Symfony\Component\Cache\Adapter\FilesystemAdapter. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            return $this->cache->/** @scrutinizer ignore-call */ set($key, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
52
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
53
    }
54
}