Completed
Pull Request — 2.0 (#1059)
by Nick
02:24
created

AbstractWebPathResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Liip\ImagineBundle\Imagine\Cache\Resolver;
4
5
use Liip\ImagineBundle\Binary\BinaryInterface;
6
use Liip\ImagineBundle\Utility\Path\PathResolverInterface;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
abstract class AbstractWebPathResolver implements ResolverInterface
10
{
11
    /**
12
     * @var Filesystem
13
     */
14
    protected $filesystem;
15
    
16
    /**
17
     * @var PathResolverInterface
18
     */
19
    protected $pathResolver;
20
    
21
    /**
22
     * @param Filesystem     $filesystem
23
     * @param PathResolverInterface $pathResolver
24
     */
25
    public function __construct(
26
        Filesystem $filesystem,
27
        PathResolverInterface $pathResolver
28
    ) {
29
        $this->filesystem = $filesystem;
30
        $this->pathResolver = $pathResolver;
31
    }
32
    
33
    /**
34
     * Checks whether the given path is stored within this Resolver.
35
     *
36
     * @param string $path
37
     * @param string $filter
38
     *
39
     * @return bool
40
     */
41
    public function isStored($path, $filter)
42
    {
43
        return is_file($this->pathResolver->getFilePath($path, $filter));
44
    }
45
    
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function store(BinaryInterface $binary, $path, $filter)
50
    {
51
        $this->filesystem->dumpFile(
52
            $this->pathResolver->getFilePath($path, $filter),
53
            $binary->getContent()
54
        );
55
    }
56
    
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function remove(array $paths, array $filters)
61
    {
62
        if (empty($paths) && empty($filters)) {
63
            return;
64
        }
65
        
66
        if (empty($paths)) {
67
            $filtersCacheDir = [];
68
            foreach ($filters as $filter) {
69
                $filtersCacheDir[] = $this->pathResolver->getCacheRoot().'/'.$filter;
70
            }
71
            
72
            $this->filesystem->remove($filtersCacheDir);
0 ignored issues
show
Documentation introduced by
$filtersCacheDir is of type array, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
            
74
            return;
75
        }
76
        
77
        foreach ($paths as $path) {
78
            foreach ($filters as $filter) {
79
                $this->filesystem->remove($this->pathResolver->getFilePath($path, $filter));
80
            }
81
        }
82
    }
83
    
84
    /**
85
     * @return PathResolverInterface
86
     */
87
    protected function getPathResolver()
88
    {
89
        return $this->pathResolver;
90
    }
91
}
92