Passed
Push — test ( 7ccca4...667a52 )
by Tom
02:31
created

Project::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines;
6
7
use InvalidArgumentException;
8
9
/**
10
 * Class Project
11
 *
12
 * Represents the project pipelines is running/operating on
13
 *
14
 * @package Ktomk\Pipelines
15
 */
16
class Project
17
{
18
    /**
19
     * @var string path to the project directory on user/host system
20
     */
21
    private $path;
22
23
    /**
24
     * @var string prefix ('pipelines' by default)
25
     */
26
    private $prefix;
27
28
    /**
29
     * Project constructor.
30
     *
31
     * @param string $path
32
     */
33 5
    public function __construct($path)
34
    {
35 5
        $buffer = LibFsPath::normalize($path);
36 5
        if (!basename($buffer)) {
37 1
            throw new InvalidArgumentException(sprintf('Invalid project directory: "%s"', $path));
38
        }
39 4
        $this->path = $buffer;
40 4
    }
41
42
    /**
43
     *
44
     */
45 1
    public function __toString()
46
    {
47 1
        return $this->getName();
48
    }
49
50 2
    public function getName()
51
    {
52 2
        return basename($this->path);
53
    }
54
55
    /**
56
     * @return string
57
     */
58 1
    public function getPath()
59
    {
60 1
        return $this->path;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 1
    public function getPrefix()
67
    {
68 1
        return $this->prefix;
69
    }
70
71
    /**
72
     * @param string $prefix
73
     *
74
     * @throws InvalidArgumentException
75
     */
76 1
    public function setPrefix($prefix)
77
    {
78 1
        if (!preg_match('~^[a-z]{3,}$~', $prefix)) {
79 1
            throw new InvalidArgumentException(sprintf("invalid prefix: '%s'", $prefix));
80
        }
81
82 1
        $this->prefix = $prefix;
83 1
    }
84
}
85