Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
21.43% |
3 / 14 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
LtiException | |
21.43% |
3 / 14 |
|
16.67% |
1 / 6 |
48.29 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getLtiMessage | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
setLaunchData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLaunchData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getKey | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
__toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoLti\models\classes; |
23 | |
24 | use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage; |
25 | |
26 | class LtiException extends \common_Exception |
27 | { |
28 | /** |
29 | * @var LtiErrorMessage |
30 | */ |
31 | protected $ltiMessage; |
32 | /** |
33 | * @var string Unique key to determine error in log |
34 | */ |
35 | private $key; |
36 | |
37 | /** |
38 | * @var LtiLaunchData |
39 | */ |
40 | protected $launchData = null; |
41 | |
42 | /** |
43 | * LtiException constructor. |
44 | * @param null $message |
45 | * @param int $code |
46 | * @param \Exception|null $previous |
47 | */ |
48 | public function __construct($message = null, $code = 0, \Exception $previous = null) |
49 | { |
50 | if (!is_null($previous)) { |
51 | $message .= ' ' . $previous->getMessage(); |
52 | } |
53 | parent::__construct($message, $code, $previous); |
54 | } |
55 | |
56 | /** |
57 | * @return LtiErrorMessage |
58 | */ |
59 | public function getLtiMessage() |
60 | { |
61 | if ($this->ltiMessage === null) { |
62 | $message = __('Error (%s): ', $this->getCode()) . $this->getMessage(); |
63 | // phpcs:disable Generic.Files.LineLength |
64 | $log = __('Error(%s): [key %s] %s "%s"', $this->getCode(), $this->getKey(), get_class($this), $this->getMessage()); |
65 | // phpcs:enable Generic.Files.LineLength |
66 | $this->ltiMessage = new LtiErrorMessage($message, $log); |
67 | } |
68 | return $this->ltiMessage; |
69 | } |
70 | |
71 | public function setLaunchData(LtiLaunchData $data) |
72 | { |
73 | $this->launchData = $data; |
74 | } |
75 | |
76 | public function getLaunchData() |
77 | { |
78 | return $this->launchData; |
79 | } |
80 | |
81 | /** |
82 | * @return string |
83 | */ |
84 | public function getKey() |
85 | { |
86 | if (!isset($this->key)) { |
87 | $this->key = uniqid(); |
88 | } |
89 | |
90 | return $this->key; |
91 | } |
92 | |
93 | /** |
94 | * @return string |
95 | */ |
96 | public function __toString() |
97 | { |
98 | return '[key ' . $this->getKey() . '] ' . parent::__toString(); |
99 | } |
100 | } |