Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
SharedStimulusResourceSpecification
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 isSatisfiedBy
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
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) 2020 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\taoMediaManager\model\sharedStimulus\specification;
24
25use common_Exception;
26use core_kernel_classes_EmptyProperty;
27use core_kernel_classes_Literal;
28use core_kernel_classes_Resource;
29use oat\generis\model\OntologyAwareTrait;
30use oat\oatbox\service\ConfigurableService;
31use oat\taoMediaManager\model\MediaService;
32use oat\taoMediaManager\model\TaoMediaOntology;
33
34class SharedStimulusResourceSpecification extends ConfigurableService
35{
36    use OntologyAwareTrait;
37
38    /**
39     * @throws common_Exception
40     */
41    public function isSatisfiedBy(core_kernel_classes_Resource $resource): bool
42    {
43        try {
44            $propertyValue = $resource->getUniquePropertyValue(
45                $this->getProperty(TaoMediaOntology::PROPERTY_MIME_TYPE)
46            );
47
48            if ($propertyValue instanceof core_kernel_classes_Literal) {
49                return $propertyValue->literal === MediaService::SHARED_STIMULUS_MIME_TYPE;
50            }
51        } catch (core_kernel_classes_EmptyProperty $exception) {
52        }
53
54        return false;
55    }
56}