Types   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verifyAbspath() 0 5 2
A verifyInput() 0 9 3
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Utility\Option;
6
7
use Ktomk\Pipelines\LibFsPath;
8
9
/**
10
 * Types
11
 *
12
 * Defines which types there are and knows how to
13
 * verify them.
14
 *
15
 * CLI options context
16
 */
17
final class Types
18
{
19
    const ABSPATH = 1;
20
21
    /**
22
     * CLI input (e.g. -c <name>=<value>) verification
23
     *
24
     * @param string $value
25
     * @param null|int $type
26
     *
27
     * @return null|string if input could not be verified, string otherwise
28
     */
29 1
    public function verifyInput($value, $type)
30
    {
31 1
        switch ($type) {
32
            case null:
33 1
                return $value;
34 1
            case self::ABSPATH:
35 1
                return $this->verifyAbspath($value);
36
            default:
37 1
                throw new \LogicException(sprintf('not a type: %s', $type));
38
        }
39
    }
40
41
    /**
42
     * verify a path is an absolute path without
43
     * any dot and dot-dot parts.
44
     *
45
     * @param string $value
46
     *
47
     * @return null|string string if input $value is already the abspath, null otherwise
48
     */
49 1
    public function verifyAbspath($value)
50
    {
51 1
        $buffer = '/' . ltrim(LibFsPath::normalizeSegments($value), '/.');
52
53 1
        return $buffer === $value ? $buffer : null;
54
    }
55
}
56