Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
14 / 28 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ResourceTransferCommand | |
50.00% |
14 / 28 |
|
85.71% |
6 / 7 |
19.12 | |
0.00% |
0 / 1 |
| __construct | |
36.36% |
8 / 22 |
|
0.00% |
0 / 1 |
5.32 | |||
| getFrom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| keepOriginalAcl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| useDestinationAcl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isCopyTo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isMoveTo | |
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) 2023 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\resources\Command; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | |
| 27 | class ResourceTransferCommand |
| 28 | { |
| 29 | public const ACL_KEEP_ORIGINAL = 'acl.keep.original'; |
| 30 | public const ACL_USE_DESTINATION = 'acl.use.destination'; |
| 31 | public const TRANSFER_MODE_COPY = 'copy'; |
| 32 | public const TRANSFER_MODE_MOVE = 'move'; |
| 33 | private const ACL_OPTIONS = [ |
| 34 | self::ACL_KEEP_ORIGINAL, |
| 35 | self::ACL_USE_DESTINATION, |
| 36 | ]; |
| 37 | private const TRANSFER_MODE_OPTIONS = [ |
| 38 | self::TRANSFER_MODE_COPY, |
| 39 | self::TRANSFER_MODE_MOVE, |
| 40 | ]; |
| 41 | |
| 42 | private string $from; |
| 43 | private string $to; |
| 44 | private string $aclMode; |
| 45 | private string $transferMode; |
| 46 | |
| 47 | public function __construct(string $from, string $to, ?string $aclMode, ?string $transferMode) |
| 48 | { |
| 49 | $aclMode = $aclMode ?? self::ACL_USE_DESTINATION; |
| 50 | $transferMode = $transferMode ?? self::TRANSFER_MODE_COPY; |
| 51 | |
| 52 | if (!in_array($aclMode, self::ACL_OPTIONS, true)) { |
| 53 | throw new InvalidArgumentException( |
| 54 | sprintf( |
| 55 | 'ACL mode %s not supported. Only supported %s', |
| 56 | $aclMode, |
| 57 | implode(',', self::ACL_OPTIONS) |
| 58 | ) |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | if (!in_array($transferMode, self::TRANSFER_MODE_OPTIONS, true)) { |
| 63 | throw new InvalidArgumentException( |
| 64 | sprintf( |
| 65 | 'Transfer mode %s not supported. Only supported %s', |
| 66 | $transferMode, |
| 67 | implode(',', self::TRANSFER_MODE_OPTIONS) |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | $this->from = $from; |
| 73 | $this->to = $to; |
| 74 | $this->aclMode = $aclMode; |
| 75 | $this->transferMode = $transferMode; |
| 76 | } |
| 77 | |
| 78 | public function getFrom(): string |
| 79 | { |
| 80 | return $this->from; |
| 81 | } |
| 82 | |
| 83 | public function getTo(): string |
| 84 | { |
| 85 | return $this->to; |
| 86 | } |
| 87 | |
| 88 | public function keepOriginalAcl(): bool |
| 89 | { |
| 90 | return $this->aclMode === self::ACL_KEEP_ORIGINAL; |
| 91 | } |
| 92 | |
| 93 | public function useDestinationAcl(): bool |
| 94 | { |
| 95 | return $this->aclMode === self::ACL_USE_DESTINATION; |
| 96 | } |
| 97 | |
| 98 | public function isCopyTo(): bool |
| 99 | { |
| 100 | return $this->transferMode === self::TRANSFER_MODE_COPY; |
| 101 | } |
| 102 | |
| 103 | public function isMoveTo(): bool |
| 104 | { |
| 105 | return $this->transferMode === self::TRANSFER_MODE_MOVE; |
| 106 | } |
| 107 | } |