Test Failed
Push — test ( 0c4d14...2be48d )
by Tom
02:17
created

PackageYamlFileReader::resolveUri()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 9
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 19
rs 9.9666
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner\Docker\Binary;
6
7
use Ktomk\Pipelines\LibFs;
8
use Ktomk\Pipelines\Yaml\Yaml;
9
10
/**
11
 * Class BinaryPackageYmlReader
12
 *
13
 * Read binary package information from a YAML file
14
 */
15
class PackageYamlFileReader implements PackageInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $file;
21
22
    /**
23
     * BinaryPackageYmlReader constructor.
24
     *
25
     * @param string $file
26
     */
27
    public function __construct($file)
28
    {
29
        $this->file = LibFs::normalizePathSegments($file);
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function asPackageArray()
36
    {
37
        $package = Yaml::file($this->file);
38
39
        $this->resolveUri($package['uri']);
40
41
        return $package;
42
    }
43
44
    /**
45
     * resolve local path URI relative to document location
46
     *
47
     * @param string $uri
48
     */
49
    private function resolveUri(&$uri)
50
    {
51
        if (null === $uri) {
0 ignored issues
show
introduced by
The condition null === $uri is always false.
Loading history...
52
            return;
53
        }
54
55
        // http/s is the only remote transport considered to be remote so far
56
        // as it is the only one used
57
        if (1 === preg_match('(^https?://)i', $uri)) {
58
            return;
59
        }
60
61
        if (LibFs::isAbsolutePath($uri)) {
62
            return;
63
        }
64
65
        $baseDir = dirname($this->file);
66
        $buffer = $baseDir . '/' . $uri;
67
        $uri = LibFs::normalizePathSegments($buffer);
68
    }
69
}
70