Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
57.69% covered (warning)
57.69%
15 / 26
43.75% covered (danger)
43.75%
7 / 16
CRAP
0.00% covered (danger)
0.00%
0 / 1
TaskLogCategorizedStatus
57.69% covered (warning)
57.69%
15 / 26
43.75% covered (danger)
43.75%
7 / 16
92.69
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFromString
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
10.46
 completed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 archived
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 failed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 created
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 inProgress
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isCreated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInProgress
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isCompleted
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isFailed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isArchived
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 equals
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMappedStatuses
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
8.12
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\taoTaskQueue\model\ValueObjects;
23
24use Exception;
25use oat\taoTaskQueue\model\TaskLogInterface;
26
27/**
28 * @deprecated Use \oat\tao\model\taskQueue\TaskLog\CategorizedStatus
29 */
30class TaskLogCategorizedStatus
31{
32    public const STATUS_CREATED = 'created';
33    public const STATUS_IN_PROGRESS = 'in_progress';
34    public const STATUS_COMPLETED = 'completed';
35    public const STATUS_FAILED = 'failed';
36    public const STATUS_ARCHIVED = 'archived';
37
38    /** @var  string */
39    private $status;
40
41    public static $categorizeMapping = [
42        self::STATUS_CREATED => [
43            TaskLogInterface::STATUS_ENQUEUED
44        ],
45        self::STATUS_IN_PROGRESS => [
46            TaskLogInterface::STATUS_DEQUEUED,
47            TaskLogInterface::STATUS_RUNNING,
48            TaskLogInterface::STATUS_CHILD_RUNNING
49        ],
50        self::STATUS_COMPLETED   => [
51            TaskLogInterface::STATUS_COMPLETED,
52            TaskLogInterface::STATUS_ARCHIVED
53        ],
54        self::STATUS_FAILED      => [
55            TaskLogInterface::STATUS_FAILED,
56            TaskLogInterface::STATUS_UNKNOWN
57        ],
58        self::STATUS_ARCHIVED    => [
59            TaskLogInterface::STATUS_ARCHIVED,
60        ]
61    ];
62
63    /**
64     * @param $status
65     */
66    protected function __construct($status)
67    {
68        $this->status = $status;
69    }
70
71    /**
72     * @param string $status
73     * @return TaskLogCategorizedStatus
74     *
75     * @throws Exception
76     */
77    public static function createFromString($status)
78    {
79        switch ($status) {
80            case TaskLogInterface::STATUS_ENQUEUED:
81                return TaskLogCategorizedStatus::created();
82                break;
83
84            case TaskLogInterface::STATUS_DEQUEUED:
85            case TaskLogInterface::STATUS_RUNNING:
86            case TaskLogInterface::STATUS_CHILD_RUNNING:
87                return TaskLogCategorizedStatus::inProgress();
88                break;
89
90            case TaskLogInterface::STATUS_COMPLETED:
91                return TaskLogCategorizedStatus::completed();
92                break;
93
94            case TaskLogInterface::STATUS_ARCHIVED:
95                return TaskLogCategorizedStatus::archived();
96                break;
97
98            case TaskLogInterface::STATUS_FAILED:
99            case TaskLogInterface::STATUS_UNKNOWN:
100                return TaskLogCategorizedStatus::failed();
101                break;
102
103            default:
104                throw new \Exception('Invalid status provided');
105        }
106    }
107
108    /**
109     * @return TaskLogCategorizedStatus
110     */
111    public static function completed()
112    {
113        return new self(self::STATUS_COMPLETED);
114    }
115
116    /**
117     * @return TaskLogCategorizedStatus
118     */
119    public static function archived()
120    {
121        return new self(self::STATUS_ARCHIVED);
122    }
123
124    /**
125     * @return TaskLogCategorizedStatus
126     */
127    public static function failed()
128    {
129        return new self(self::STATUS_FAILED);
130    }
131
132    /**
133     * @return TaskLogCategorizedStatus
134     */
135    public static function created()
136    {
137        return new self(self::STATUS_CREATED);
138    }
139
140    /**
141     * @return TaskLogCategorizedStatus
142     */
143    public static function inProgress()
144    {
145        return new self(self::STATUS_IN_PROGRESS);
146    }
147
148    /**
149     * @return bool
150     */
151    public function isCreated()
152    {
153        return $this->equals(TaskLogCategorizedStatus::created());
154    }
155
156    /**
157     * @return bool
158     */
159    public function isInProgress()
160    {
161        return $this->equals(TaskLogCategorizedStatus::inProgress());
162    }
163
164    /**
165     * @return bool
166     */
167    public function isCompleted()
168    {
169        return $this->equals(TaskLogCategorizedStatus::completed());
170    }
171
172    /**
173     * @return bool
174     */
175    public function isFailed()
176    {
177        return $this->equals(TaskLogCategorizedStatus::failed());
178    }
179
180    /**
181     * @return bool
182     */
183    public function isArchived()
184    {
185        return $this->equals(TaskLogCategorizedStatus::archived());
186    }
187
188    /**
189     * @param TaskLogCategorizedStatus $logStatus
190     *
191     * @return bool
192     */
193    public function equals(TaskLogCategorizedStatus $logStatus)
194    {
195        return $this->status === $logStatus->status;
196    }
197
198    /**
199     * @param string $status
200     * @return array
201     */
202    public static function getMappedStatuses($status)
203    {
204        return self::$categorizeMapping[$status];
205    }
206
207    /**
208     * @return string
209     */
210    public function __toString()
211    {
212        return (string) $this->status;
213    }
214
215    /**
216     * @return string
217     */
218    public function getLabel()
219    {
220        switch ($this->status) {
221            case self::STATUS_CREATED:
222                return __('Queued');
223                break;
224
225            case self::STATUS_IN_PROGRESS:
226                return __('In Progress');
227                break;
228
229            case self::STATUS_COMPLETED:
230                return __('Completed');
231                break;
232
233            case self::STATUS_FAILED:
234                return __('Failed');
235                break;
236        }
237    }
238}