Completed
Pull Request — master (#38)
by Simon
04:28
created

Script::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
4
namespace Shopware\Psh\Listing;
5
6
/**
7
 * ValueObject containing all information for a single script to be executed
8
 */
9
class Script
10
{
11
    /**
12
     * @var string
13
     */
14
    private $directory;
15
16
    /**
17
     * @var string
18
     */
19
    private $scriptName;
20
21
    /**
22
     * @var string
23
     */
24
    private $environment;
25
26
    /**
27
     * @var string
28
     */
29
    public $description;
30
31
    /**
32
     * @param string $directory
33
     * @param string $scriptName
34
     * @param string $environment
35
     * @param string $description
36
     */
37
    public function __construct(string $directory, string $scriptName, string $environment = null, $description = '')
38
    {
39
        $this->directory = $directory;
40
        $this->scriptName = $scriptName;
41
        $this->environment = $environment;
42
        $this->description = $description;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getPath(): string
49
    {
50
        return $this->directory . '/' . $this->scriptName;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getDirectory(): string
57
    {
58
        return $this->directory;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getName(): string
65
    {
66
        $name = pathinfo($this->scriptName, PATHINFO_FILENAME);
67
68
        if (!$this->environment) {
69
            return $name;
70
        }
71
72
        return $this->environment . ':' . $name;
73
    }
74
75
    /**
76
     * @return string|null
77
     */
78
    public function getEnvironment()
79
    {
80
        return $this->environment;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getDescription(): string
87
    {
88
        return $this->description;
89
    }
90
}
91