Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.15% covered (success)
98.15%
53 / 54
94.74% covered (success)
94.74%
18 / 19
CRAP
0.00% covered (danger)
0.00%
0 / 1
Task
98.15% covered (success)
98.15%
53 / 54
94.74% covered (success)
94.74%
18 / 19
32
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDuration
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDuration
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getStartDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStartDate
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
 getEndDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEndDate
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
5.03
 getProgress
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setProgress
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 getIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIndex
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 addResource
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getResources
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResourceCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createTask
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getTasks
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTaskCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This file is part of PHPProject - A pure PHP library for reading and writing
5 * presentations documents.
6 *
7 * PHPProject is free software distributed under the terms of the GNU Lesser
8 * General Public License version 3 as published by the Free Software Foundation.
9 *
10 * For the full copyright and license information, please read the LICENSE
11 * file that was distributed with this source code. For the full list of
12 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13 *
14 * @link        https://github.com/PHPOffice/PHPProject
15 * @copyright   2009-2014 PHPProject contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpProject;
22
23/**
24 * PHPProject_Task
25 *
26 * @category    PHPProject
27 * @package        PHPProject
28 * @copyright    Copyright (c) 2012 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject)
29 */
30class Task
31{
32    /**
33     * Name
34     * 
35     * @var string
36     */
37    private $name = '';
38
39    /**
40     * Duration
41     * 
42     * @var string
43     */
44    private $duration;
45    
46    /**
47     * Start Date
48     *
49     * @var int
50     */
51    private $startDate;
52    
53    /**
54     * End Date
55     *
56     * @var int
57     */
58    private $endDate;
59    
60    /**
61     * Progress
62     *
63     * @var    float
64     */
65    private $progress;
66    
67    /**
68     * Index
69     *
70     * @var integer
71     */
72    private $index;
73    
74    /**
75     * Collection of Resource
76     * 
77     * @var Resource[]
78     */
79    private $resourceCollection = array();
80    
81    /**
82     * Collection of task objects
83     *
84     * @var self[]
85     */
86    private $taskCollection = array();
87    
88    /**
89     * Index of Resource
90     * @var integer
91     */
92    public static $lastIndex = 0;
93    
94    public function __construct()
95    {
96        $this->index = self::$lastIndex;
97        self::$lastIndex++;
98    }
99
100    /**
101     * Get name
102     *
103     * @return string
104     */
105    public function getName(): string
106    {
107        return $this->name;
108    }
109    
110    /**
111     * Set name
112     *
113     * @param string $pValue Name of the task
114     * @return self
115     */
116    public function setName(string $pValue): self
117    {
118        $this->name = $pValue;
119        return $this;
120    }
121    
122    /**
123     * Get duration
124     *
125     * @return string|null
126     */
127    public function getDuration()
128    {
129        return $this->duration;
130    }
131    
132    /**
133     * Set duration (in days)
134     *
135     * @param int|float|string $pValue Duration of the resource
136     * @return self
137     */
138    public function setDuration($pValue): self
139    {
140        $this->duration = $pValue;
141        return $this;
142    }
143    
144    /**
145     * Get Start Date
146     *
147     * @return int|null
148     */
149    public function getStartDate(): ?int
150    {
151        return $this->startDate;
152    }
153
154    /**
155     * Set Start Date
156     *
157     * @param int|string|null $pValue
158     * @return self
159     */
160    public function setStartDate($pValue = null): self
161    {
162        if ($pValue === null) {
163            $pValue = time();
164        } elseif (is_string($pValue)) {
165            if (is_numeric($pValue)) {
166                $pValue = intval($pValue);
167            } else {
168                $pValue = strtotime($pValue);
169                if ($pValue === false) {
170                    $pValue = null;
171                }
172            }
173        }
174
175        $this->startDate = $pValue;
176        return $this;
177    }
178
179    /**
180     * Get End Date
181     *
182     * @return int|null
183     */
184    public function getEndDate(): ?int
185    {
186        return $this->endDate;
187    }
188
189    /**
190     * Set End Date
191     *
192     * @param int|string|null $pValue
193     * @return self
194     */
195    public function setEndDate($pValue = null): self
196    {
197        if ($pValue === null) {
198            $pValue = time();
199        } elseif (is_string($pValue)) {
200            if (is_numeric($pValue)) {
201                $pValue = intval($pValue);
202            } else {
203                $pValue = strtotime($pValue);
204                if ($pValue === false) {
205                    $pValue = null;
206                }
207            }
208        }
209
210        $this->endDate = $pValue;
211        return $this;
212    }
213    
214    /**
215     * Get Progress
216     *
217     * @return float|null
218     */
219    public function getProgress(): ?float
220    {
221        return $this->progress;
222    }
223    
224    /**
225     * Set progress
226     *
227     * @param int|float|string $pValue Progress of the task
228     * @return self
229     */
230    public function setProgress($pValue = 0): self
231    {
232        if (!is_numeric($pValue)) {
233            $this->progress = 0;
234            return $this;
235        }
236        if ($pValue > 1) {
237            $this->progress = (double)1;
238        } elseif ($pValue < 0) {
239            $this->progress = (double)0;
240        } else {
241            $this->progress = (double)$pValue;
242        }
243        return $this;
244    }
245    
246    /**
247     * Get index
248     */
249    public function getIndex(): int
250    {
251        return $this->index;
252    }
253    
254    /**
255     * Set index
256     * @param int|string $value
257     */
258    public function setIndex($value): self
259    {
260        if (is_numeric($value)) {
261            $this->index = (int)$value;
262        }
263        return $this;
264    }
265    
266    //===============================================
267    // Resources
268    //===============================================
269    /**
270     * Add a resource used by the current task
271     * @param Resource $oResource
272     */
273    public function addResource(Resource $oResource): self
274    {
275        if (!in_array($oResource, $this->resourceCollection)) {
276            $this->resourceCollection[] = &$oResource;
277        }
278        return $this;
279    }
280
281    /**
282     * Returns a collection of all resources used by the task
283     * 
284     * @return Resource[]
285     */
286    public function getResources(): array
287    {
288        return $this->resourceCollection;
289    }
290
291    public function getResourceCount(): int
292    {
293        return count($this->resourceCollection);
294    }
295    
296    //===============================================
297    // Tasks
298    //===============================================
299    public function createTask(): self
300    {
301        $newTask = new self();
302        $this->taskCollection[] = $newTask;
303        return $newTask;
304    }
305    
306    /**
307     * Returns a collection of all subtasks created in the task
308     *
309     * @return self[]
310     */
311    public function getTasks(): array
312    {
313        return $this->taskCollection;
314    }
315
316    public function getTaskCount(): int
317    {
318        return count($this->taskCollection);
319    }
320}