Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
FilePathFactory | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
getFilePath | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getDirPath | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
buildIdentifier | |
100.00% |
1 / 1 |
|
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 | */ |
21 | |
22 | namespace oat\taoResultServer\models\classes\OutcomeFileSystemStorage; |
23 | |
24 | class FilePathFactory |
25 | { |
26 | /** |
27 | * @param string $deliveryResultIdentifier |
28 | * |
29 | * @return string |
30 | */ |
31 | public function getFilePath($deliveryResultIdentifier) |
32 | { |
33 | return sprintf( |
34 | '%s/%s', |
35 | $this->getDirPath($deliveryResultIdentifier), |
36 | $this->buildIdentifier() |
37 | ); |
38 | } |
39 | |
40 | /** |
41 | * @param string $deliveryResultIdentifier |
42 | * |
43 | * @return string |
44 | */ |
45 | public function getDirPath($deliveryResultIdentifier) |
46 | { |
47 | $path = md5($deliveryResultIdentifier); |
48 | |
49 | $slashPosition = 1; |
50 | for ($i = 1; $i < 4; $i++) { |
51 | $path = substr_replace($path, '/', $slashPosition, 0); |
52 | $slashPosition += 2; |
53 | } |
54 | |
55 | return $path; |
56 | } |
57 | |
58 | private function buildIdentifier() |
59 | { |
60 | return md5(uniqid('', true) . mt_rand(0, 10000)); |
61 | } |
62 | } |