UrlFixer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10
wmc 6

3 Methods

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