Spec::setRelease()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

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 3
nc 1
nop 1
1
<?php
2
namespace wapmorgan\rpm;
3
4
class Spec {
5
    private $_keys = array(
6
        'Name' => '',
7
        'Version' => '0.1',
8
        'Release' => '1',
9
        'Summary' => '...',
10
        'Group' => '',
11
        'License' => 'free',
12
        'URL' => '',
13
        'BuildRequires' => '',
14
        'BuildArch' => 'noarch',
15
        'Requires' => '',
16
    );
17
18
    private $_blocks = array(
19
        'description' => '',
20
        'prep' => '%autosetup',
21
        'build' => '',
22
        'install' => '',
23
        'files' => '',
24
        'changelog' => '',
25
    );
26
27
    public function setPackageName($name) {
28
        $this->_keys['Name'] = $name;
29
        return $this;
30
    }
31
32
    public function setVersion($version) {
33
        $this->_keys['Version'] = $version;
34
        return $this;
35
    }
36
37
    public function setRelease($release) {
38
        $this->_keys['Release'] = $release;
39
        return $this;
40
    }
41
42
    public function setSummary($summary) {
43
        $this->_keys['Summary'] = $summary;
44
        return $this;
45
    }
46
47
    public function setGroup($group) {
48
        $this->_keys['Group'] = $group;
49
        return $this;
50
    }
51
52
    public function setLicense($license) {
53
        $this->_keys['License'] = $license;
54
        return $this;
55
    }
56
57
    public function setUrl($url) {
58
        $this->_keys['URL'] = $url;
59
        return $this;
60
    }
61
62
    public function setBuildRequires($buildRequires) {
63
        $this->_keys['BuildRequires'] = $buildRequires;
64
        return $this;
65
    }
66
67
    public function setBuildArch($buildArch) {
68
        $this->_keys['BuildArch'] = $buildArch;
69
        return $this;
70
    }
71
72
    public function setRequires($requires) {
73
        $this->_keys['Requires'] = $requires;
74
        return $this;
75
    }
76
77
    public function setDescription($description) {
78
        $this->_blocks['description'] = $description;
79
        return $this;
80
    }
81
82
    public function setPrep($prep) {
83
        $this->_blocks['prep'] = $prep;
84
        return $this;
85
    }
86
87
    public function setBuild($build) {
88
        $this->_blocks['build'] = $build;
89
        return $this;
90
    }
91
92
    public function setInstall($install) {
93
        $this->_blocks['install'] = $install;
94
        return $this;
95
    }
96
97
    public function setFiles($files) {
98
        $this->_blocks['files'] = $files;
99
        return $this;
100
    }
101
102
    public function setChangelog($changelog) {
103
        $this->_blocks['changelog'] = $changelog;
104
        return $this;
105
    }
106
107
    public function __get($prop) {
108
        if (array_key_exists($prop, $this->_keys))
109
            return $this->_keys[$prop];
110
        else if (array_key_exists($prop, $this->_blocks))
111
            return $this->_blocks[$prop];
112
    }
113
114
    public function setKey($prop, $value) {
115
        $this->_keys[$prop] = $value;
116
        return $this;
117
    }
118
119
    public function __toString() {
120
        $spec = '';
121
        foreach ($this->_keys as $key => $value) {
122
            if ($value === '')
123
                continue;
124
            $spec .= sprintf('%s: %s'."\n", $key, $value);
125
        }
126
127
        foreach ($this->_blocks as $block => $value) {
128
            $spec .= "\n".'%'.$block."\n".$value."\n";
129
        }
130
        return $spec;
131
    }
132
}