Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
26.67% |
4 / 15 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PortableElementException | |
26.67% |
4 / 15 |
|
50.00% |
2 / 4 |
26.32 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setReport | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReportMessages | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
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) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\portableElement\exception; |
| 23 | |
| 24 | class PortableElementException extends \common_Exception |
| 25 | { |
| 26 | protected $report; |
| 27 | |
| 28 | /** |
| 29 | * PortableElementInvalidModelException constructor. |
| 30 | * Set default message is $message is null |
| 31 | * |
| 32 | * @param null $message |
| 33 | * @param int $code |
| 34 | * @param \Exception|null $previous |
| 35 | */ |
| 36 | public function __construct($message = null, $code = 0, \Exception $previous = null) |
| 37 | { |
| 38 | if (is_null($message)) { |
| 39 | $message = 'Portable element validation failed'; |
| 40 | } |
| 41 | parent::__construct($message, $code, $previous); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Set report |
| 46 | * |
| 47 | * @param $report |
| 48 | */ |
| 49 | public function setReport(\common_report_Report $report) |
| 50 | { |
| 51 | $this->report = $report; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Return the report |
| 56 | * |
| 57 | * @return \common_report_Report |
| 58 | */ |
| 59 | public function getReport() |
| 60 | { |
| 61 | return $this->report; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Extract all report messages to simple array |
| 66 | * |
| 67 | * @return array |
| 68 | */ |
| 69 | public function getReportMessages() |
| 70 | { |
| 71 | $messages = []; |
| 72 | /** @var \common_report_Report $subReport */ |
| 73 | foreach ($this->report as $subReport) { |
| 74 | $errors = []; |
| 75 | if ($subReport->containsError()) { |
| 76 | $errors = $subReport->getErrors(); |
| 77 | } |
| 78 | $messages[] = [ |
| 79 | 'message' => $subReport->getMessage(), |
| 80 | 'details' => $errors |
| 81 | ]; |
| 82 | } |
| 83 | return $messages; |
| 84 | } |
| 85 | } |