Task::getIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of PHPProject - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPProject is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPProject
14
 * @copyright   2009-2014 PHPProject contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpProject;
19
20
/**
21
 * PHPProject_Task
22
 *
23
 * @category    PHPProject
24
 * @package        PHPProject
25
 * @copyright    Copyright (c) 2012 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject)
26
 */
27
class Task
28
{
29
    /**
30
     * Name
31
     * 
32
     * @var string
33
     */
34
    private $name;
35
    
36
    /**
37
     * Duration
38
     * 
39
     * @var string
40
     */
41
    private $duration;
42
    
43
    /**
44
     * Start Date
45
     *
46
     * @var int
47
     */
48
    private $startDate;
49
    
50
    /**
51
     * End Date
52
     *
53
     * @var int
54
     */
55
    private $endDate;
56
    
57
    /**
58
     * Progress
59
     *
60
     * @var    float
61
     */
62
    private $progress;
63
    
64
    /**
65
     * Index
66
     *
67
     * @var integer
68
     */
69
    private $index;
70
    
71
    /**
72
     * Collection of PHPProject_Resource index
73
     * 
74
     * @var integer[]
75
     */
76
    private $resourceCollection = array();
77
    
78
    /**
79
     * Collection of task objects
80
     *
81
     * @var PHPProject_Task[]
82
     */
83
    private $taskCollection = array();
84
    
85
    /**
86
     * Index of Resource
87
     * @var integer
88
     */
89
    public static $lastIndex = 0;
90
    
91 18
    public function __construct()
92
    {
93 18
        $this->index = self::$lastIndex;
94 18
        self::$lastIndex++;
95 18
    }
96
97
    /**
98
     * Get name
99
     *
100
     * @return string
101
     */
102 5
    public function getName()
103
    {
104 5
        return $this->name;
105
    }
106
    
107
    /**
108
     * Set name
109
     *
110
     * @param string $pValue Name of the task
111
     * @return PHPProject_Task
112
     */
113 8
    public function setName($pValue)
114
    {
115 8
        $this->name = $pValue;
116 8
        return $this;
117
    }
118
    
119
    /**
120
     * Get duration
121
     *
122
     * @return string
123
     */
124 5
    public function getDuration()
125
    {
126 5
        return $this->duration;
127
    }
128
    
129
    /**
130
     * Set duration (in days)
131
     *
132
     * @param string $pValue Duration of the resource
133
     * @return PHPProject_Task
134
     */
135 6
    public function setDuration($pValue)
136
    {
137 6
        $this->duration = $pValue;
138 6
        return $this;
139
    }
140
    
141
    /**
142
     * Get Start Date
143
     *
144
     * @return    datetime
145
     */
146 5
    public function getStartDate()
147
    {
148 5
        return $this->startDate;
149
    }
150
151
    /**
152
     * Set Start Date
153
     *
154
     * @param int $pValue
155
     * @return DocumentInformations
156
     */
157 6
    public function setStartDate($pValue = null)
158
    {
159 6
        if ($pValue === null) {
160 1
            $pValue = time();
161 6
        } elseif (is_string($pValue)) {
162 6
            if (is_numeric($pValue)) {
163 1
                $pValue = intval($pValue);
164 1
            } else {
165 6
                $pValue = strtotime($pValue);
166
            }
167 6
        }
168
169 6
        $this->startDate = $pValue;
170 6
        return $this;
171
    }
172
173
    /**
174
     * Get End Date
175
     *
176
     * @return    datetime
177
     */
178 5
    public function getEndDate()
179
    {
180 5
        return $this->endDate;
181
    }
182
183
    /**
184
     * Set End Date
185
     *
186
     * @param int $pValue
187
     * @return DocumentInformations
188
     */
189 3
    public function setEndDate($pValue = null)
190
    {
191 3
        if ($pValue === null) {
192 1
            $pValue = time();
193 3
        } elseif (is_string($pValue)) {
194 3
            if (is_numeric($pValue)) {
195 1
                $pValue = intval($pValue);
196 1
            } else {
197 3
                $pValue = strtotime($pValue);
198
            }
199 3
        }
200
201 3
        $this->endDate = $pValue;
202 3
        return $this;
203
    }
204
    
205
    /**
206
     * Get Progress
207
     *
208
     * @return float
209
     */
210 5
    public function getProgress()
211
    {
212 5
        return $this->progress;
213
    }
214
    
215
    /**
216
     * Set progress
217
     *
218
     * @param float $pValue Progress of the task
219
     * @return PHPProject_Task
220
     */
221 6
    public function setProgress($pValue = 0)
222
    {
223 6
        if ($pValue > 1) {
224 2
            $this->progress = (double)1;
225 6
        } elseif ($pValue < 0) {
226 1
            $this->progress = (double)0;
227 1
        } else {
228 5
            $this->progress = (double)$pValue;
229
        }
230 6
        return $this;
231
    }
232
    
233
    /**
234
     * Get index
235
     */
236 9
    public function getIndex()
237
    {
238 9
        return $this->index;
239
    }
240
    
241
    /**
242
     * Set index
243
     * @param integer $value
244
     */
245 5
    public function setIndex($value)
246
    {
247 5
        if (is_numeric($value)) {
248 5
            $this->index = (int)$value;
249 5
        }
250 5
        return $this;
251
    }
252
    
253
    //===============================================
254
    // Resources
255
    //===============================================
256
    /**
257
     * Add a resource used by the current task
258
     * @param PHPProject_Resource $pResource
0 ignored issues
show
Bug introduced by
There is no parameter named $pResource. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
259
     */
260 6
    public function addResource(Resource $oResource)
261
    {
262 6
        if (!in_array($oResource, $this->resourceCollection)) {
263 6
            $this->resourceCollection[] = &$oResource;
264 6
        }
265 6
        return $this;
266
    }
267
268
    /**
269
     * Returns a collection of all resources used by the task
270
     * 
271
     * @return Resource[]
272
     */
273 5
    public function getResources()
274
    {
275 5
        return $this->resourceCollection;
276
    }
277
278 4
    public function getResourceCount()
279
    {
280 4
        return count($this->resourceCollection);
281
    }
282
    
283
    //===============================================
284
    // Tasks
285
    //===============================================
286 7
    public function createTask()
287
    {
288 7
        $newTask = new self();
289 7
        $this->taskCollection[] = $newTask;
290 7
        return $newTask;
291
    }
292
    
293
    /**
294
     * Returns a collection of all subtasks created in the task
295
     *
296
     * @return PHPProject_Task[]
297
     */
298 9
    public function getTasks()
299
    {
300 9
        return $this->taskCollection;
301
    }
302
303 10
    public function getTaskCount()
304
    {
305 10
        return count($this->taskCollection);
306
    }
307
}
308