Completed
Push — master ( 9c1f83...0c1135 )
by Paulo Rodrigues
10:00
created

Package/FallbackPackage.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Rj\FrontendBundle\Package;
4
5
class FallbackPackage
6
{
7
    private $patterns;
8
    private $package;
9
    private $fallback;
10
11 23
    public function __construct($patterns, $package)
12
    {
13 23
        $this->patterns = $patterns;
14 23
        $this->package = $package;
15 23
    }
16
17 23
    public function setFallback($fallback)
18
    {
19 23
        $this->fallback = $fallback;
20
21 23
        return $this;
22
    }
23
24 2
    public function getVersion($path)
25
    {
26 2
        if ($this->mustFallback($path)) {
27 2
            return $this->fallback->getVersion($path);
28
        }
29
30 2
        return $this->package->getVersion($path);
31
    }
32
33 11
    public function getUrl($path, $version = null)
34
    {
35 11
        if ($this->mustFallback($path)) {
36 4
            return $this->fallback->getUrl($path, $version);
37
        }
38
39 9
        return $this->package->getUrl($path);
40
    }
41
42 13
    protected function mustFallback($path)
43
    {
44 13
        foreach ($this->patterns as $pattern) {
45 13
            if (1 === preg_match("/$pattern/", $path)) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $pattern instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
46 13
                return true;
47
            }
48
        }
49
50 11
        return false;
51
    }
52
}
53