Passed
Branch master (b0d099)
by Markus
03:49
created

UrlFixer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 21
cts 21
cp 1
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fixPackage() 0 17 3
A fixPackageList() 0 6 2
1
<?php
2
3
namespace SSpkS\Output;
4
5
class UrlFixer
6
{
7
    private $urlPrefix;
8
9
    /**
10
     * Prepends given $urlPrefix to all URLs in Package objects.
11
     *
12
     * @param string $urlPrefix Prefix to put before all URLs to make them absolute.
13
     */
14 4
    public function __construct($urlPrefix)
15
    {
16 4
        $this->urlPrefix = $urlPrefix;
17 4
    }
18
19
    /**
20
     * Prepends given prefix to Package $pkg.
21
     *
22
     * @param \SSpkS\Package\Package $pkg Package to work on.
23
     */
24 4
    public function fixPackage($pkg)
25
    {
26 4
        $pkg->spk_url = $this->urlPrefix . $pkg->spk;
27
28
        // Make absolute URLs from relative ones
29 4
        $thumbnail_url = array();
30 4
        foreach ($pkg->thumbnail as $i => $t) {
31 4
            $thumbnail_url[$i] = $this->urlPrefix . $t;
32 4
        }
33 4
        $pkg->thumbnail_url = $thumbnail_url;
34
35 4
        $snapshot_url = array();
36 4
        foreach ($pkg->snapshot as $i => $s) {
37 4
            $snapshot_url[$i] = $this->urlPrefix . $s;
38 4
        }
39 4
        $pkg->snapshot_url = $snapshot_url;
40 4
    }
41
42
    /**
43
     * Prepends given prefix to all Packages in array $pkgList.
44
     *
45
     * @param \SSpkS\Package\Package[] List of Packages.
46
     */
47 3
    public function fixPackageList($pkgList)
48
    {
49 3
        foreach ($pkgList as $pkg) {
50 3
            $this->fixPackage($pkg);
51 3
        }
52 3
    }
53
}
54