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

FallbackPackage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setFallback() 0 6 1
A getVersion() 0 8 2
A getUrl() 0 8 2
A mustFallback() 0 10 3
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