Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AssemblyFilesReader
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 setCompiledTestConverter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFiles
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 isCompiledTestFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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) 2019  (original work) Open Assessment Technologies SA;
19 */
20
21namespace oat\taoDeliveryRdf\model\assembly;
22
23use Generator;
24use taoQtiTest_models_classes_QtiTestService;
25use oat\oatbox\filesystem\Directory;
26use oat\oatbox\filesystem\File;
27use oat\oatbox\service\ConfigurableService;
28use tao_models_classes_service_StorageDirectory;
29
30class AssemblyFilesReader extends ConfigurableService implements AssemblyFilesReaderInterface
31{
32    /**
33     * @var CompiledTestConverterService
34     */
35    private $compiledTestConverter = null;
36    /**
37         * @param CompiledTestConverterService $compiledTestConverter
38         */
39    public function setCompiledTestConverter(CompiledTestConverterService $compiledTestConverter)
40    {
41        $this->compiledTestConverter = $compiledTestConverter;
42    }
43
44    /**
45     * @param tao_models_classes_service_StorageDirectory $directory
46     * @return Generator In format $filePath => StreamInterface
47     * @throws \common_Exception
48     */
49    public function getFiles(tao_models_classes_service_StorageDirectory $directory)
50    {
51        $iterator = $directory->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE);
52        /* @var $file File */
53        foreach ($iterator as $file) {
54            if ($this->isCompiledTestFile($file) && $this->compiledTestConverter !== null) {
55                $file = $this->compiledTestConverter->convert($file, $directory);
56                $fileStream = $file->readPsrStream();
57                $file->delete();
58            } else {
59                $fileStream = $file->readPsrStream();
60            }
61
62            yield $file->getPrefix() => $fileStream;
63        }
64    }
65
66    /**
67     * @param File $file
68     * @return bool
69     */
70    private function isCompiledTestFile(File $file)
71    {
72        return strpos($file->getBasename(), taoQtiTest_models_classes_QtiTestService::TEST_COMPILED_FILENAME) !== false;
73    }
74}