Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
DeliveryRepository | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
findOrFail | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 |
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) 2022 (original work) Open Assessment Technologies SA; |
19 | * |
20 | * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com> |
21 | */ |
22 | |
23 | declare(strict_types=1); |
24 | |
25 | namespace oat\taoDeliveryRdf\model\Delivery\DataAccess; |
26 | |
27 | use common_exception_ResourceNotFound as ResourceNotFoundException; |
28 | use core_kernel_classes_Resource as KernelResource; |
29 | use oat\generis\model\OntologyAwareTrait; |
30 | use oat\taoDeliveryRdf\model\Delivery\Business\Domain\DeliverySearchRequest; |
31 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
32 | |
33 | class DeliveryRepository |
34 | { |
35 | use OntologyAwareTrait; |
36 | |
37 | /** |
38 | * @throws ResourceNotFoundException |
39 | */ |
40 | public function findOrFail(DeliverySearchRequest $searchRequest): KernelResource |
41 | { |
42 | $deliveryClass = $this->getClass(DeliveryAssemblyService::CLASS_URI); |
43 | $delivery = $deliveryClass->getResource($searchRequest->getId()); |
44 | |
45 | if ($delivery->isClass() || !$delivery->exists() || !$delivery->isInstanceOf($deliveryClass)) { |
46 | throw new ResourceNotFoundException(); |
47 | } |
48 | |
49 | return $delivery; |
50 | } |
51 | } |