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

AbstractWebPathResolver::getPathResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Imagine\Cache\Resolver;
13
14
use Liip\ImagineBundle\Binary\BinaryInterface;
15
use Liip\ImagineBundle\Utility\Path\PathResolverInterface;
16
use Symfony\Component\Filesystem\Filesystem;
17
18
abstract class AbstractWebPathResolver implements ResolverInterface
19
{
20
    /**
21
     * @var Filesystem
22
     */
23
    protected $filesystem;
24
25
    /**
26
     * @var PathResolverInterface
27
     */
28
    protected $pathResolver;
29
30
    /**
31
     * @param Filesystem            $filesystem
32
     * @param PathResolverInterface $pathResolver
33
     */
34
    public function __construct(
35
        Filesystem $filesystem,
36
        PathResolverInterface $pathResolver
37
    ) {
38
        $this->filesystem = $filesystem;
39
        $this->pathResolver = $pathResolver;
40
    }
41
42
    /**
43
     * Checks whether the given path is stored within this Resolver.
44
     *
45
     * @param string $path
46
     * @param string $filter
47
     *
48
     * @return bool
49
     */
50
    public function isStored($path, $filter)
51
    {
52
        return is_file($this->pathResolver->getFilePath($path, $filter));
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function store(BinaryInterface $binary, $path, $filter)
59
    {
60
        $this->filesystem->dumpFile(
61
            $this->pathResolver->getFilePath($path, $filter),
62
            $binary->getContent()
63
        );
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function remove(array $paths, array $filters)
70
    {
71
        if (empty($paths) && empty($filters)) {
72
            return;
73
        }
74
75
        if (empty($paths)) {
76
            $filtersCacheDir = [];
77
            foreach ($filters as $filter) {
78
                $filtersCacheDir[] = $this->pathResolver->getCacheRoot().'/'.$filter;
79
            }
80
81
            $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...
82
83
            return;
84
        }
85
86
        foreach ($paths as $path) {
87
            foreach ($filters as $filter) {
88
                $this->filesystem->remove($this->pathResolver->getFilePath($path, $filter));
89
            }
90
        }
91
    }
92
93
    /**
94
     * @return PathResolverInterface
95
     */
96
    protected function getPathResolver()
97
    {
98
        return $this->pathResolver;
99
    }
100
}
101