Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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) |
|
51 | } |
||
52 | 4 | } |
|
53 | } |
||
54 |