ContainsProtocol::containsProtocol()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Aoe\Asdis\System\Uri\Filter;
3
4
use Aoe\Asdis\System\Uri\Filter\FilterInterface;
5
6
/**
7
 * Filters paths that contain "http:" or "https:".
8
 */
9
class ContainsProtocol implements FilterInterface
10
{
11
    /**
12
     * @param array $paths Array of paths.
13
     * @return array Valid paths.
14
     */
15 1
    public function filter(array $paths)
16
    {
17 1
        $filteredPaths = [];
18 1
        foreach($paths as $path) {
19 1
            if ($this->containsProtocol($path) || $this->containsProtocolMarker($path)) {
20 1
                continue;
21
            }
22 1
            $filteredPaths[] = $path;
23
        }
24 1
        return $filteredPaths;
25
    }
26
27
    /**
28
     * @param string $path
29
     * @return boolean
30
     */
31 1
    private function containsProtocol($path)
32
    {
33 1
        return (1 === preg_match('/^(http|https)\:/', $path));
34
    }
35
36
    /**
37
     * @param string $path
38
     * @return boolean
39
     */
40 1
    private function containsProtocolMarker($path)
41
    {
42 1
        return (1 === preg_match('/^(###HTTP###|###HTTP_S###)/', $path));
43
    }
44
}