Helper::padLines()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 3
crap 5
1
<?php
2
3
namespace Swaggest\JsonSchema;
4
5
6
class Helper
7
{
8
    /**
9
     * @param string $jsonPattern
10
     * @return string
11
     */
12 193
    public static function toPregPattern($jsonPattern)
13
    {
14 193
        return '{' . $jsonPattern . '}u';
15
    }
16
17
    /**
18
     * @param string $parent
19
     * @param string $current
20
     * @return string
21
     * @todo getaway from zeroes
22
     */
23 449
    public static function resolveURI($parent, $current)
24
    {
25 449
        if ($current === '') {
26 1
            return $parent;
27
        }
28
29 449
        $parentParts = explode('#', $parent, 2);
30 449
        $currentParts = explode('#', $current, 2);
31
32 449
        $resultParts = array($parentParts[0], '');
33 449
        if (isset($currentParts[1])) {
34 150
            $resultParts[1] = $currentParts[1];
35
        }
36
37 449
        if (isset($currentParts[0]) && $currentParts[0]) {
38 422
            if (strpos($currentParts[0], '://')) {
39 10
                $resultParts[0] = $currentParts[0];
40 418
            } elseif ('/' === substr($currentParts[0], 0, 1)) {
41 5
                $resultParts[0] = $currentParts[0];
42 5
                if (($pos = strpos($parentParts[0], '://'))
43 5
                    && ($len = strpos($parentParts[0], '/', $pos + 3))) {
44
                    $resultParts[0] = substr($parentParts[0], 0, $len) . $resultParts[0];
45 413
                }
46 413
            } elseif (false !== $pos = strrpos($parentParts[0], '/')) {
47
                $resultParts[0] = substr($parentParts[0], 0, $pos + 1) . $currentParts[0];
48 6
            } else {
49
                $resultParts[0] = $currentParts[0];
50
            }
51
        }
52 449
53 449
        $result = $resultParts[0] . '#' . $resultParts[1];
54
        return $result;
55
    }
56
57 104
58
    public static function padLines($with, $text, $skipFirst = true)
59 104
    {
60 104
        $lines = explode("\n", $text);
61 104
        foreach ($lines as $index => $line) {
62 75
            if ($skipFirst && !$index) {
63
                continue;
64 32
            }
65 32
            if ($line) {
66
                $lines[$index] = $with . $line;
67
            }
68 104
        }
69
        return implode("\n", $lines);
70
    }
71
72
}