UrlFixer::fixPackage()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
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