Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| RequiresRightTag | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getRightId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParameterName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2014-2022 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\controllerMap; |
| 23 | |
| 24 | use phpDocumentor\Reflection\DocBlock\Description; |
| 25 | use phpDocumentor\Reflection\DocBlock\DescriptionFactory; |
| 26 | use phpDocumentor\Reflection\DocBlock\Tags\BaseTag; |
| 27 | use phpDocumentor\Reflection\Types\Context as TypeContext; |
| 28 | use Webmozart\Assert\Assert; |
| 29 | |
| 30 | /** |
| 31 | * Reflection class for a @requiresRight tag in a Docblock. |
| 32 | * |
| 33 | * To be use with the phpDocumentor |
| 34 | * |
| 35 | * @author Joel Bout <joel@taotesting.com> |
| 36 | */ |
| 37 | class RequiresRightTag extends BaseTag |
| 38 | { |
| 39 | /** @var string */ |
| 40 | protected $parameter = ''; |
| 41 | |
| 42 | /** @var string|null */ |
| 43 | protected $rightId = null; |
| 44 | |
| 45 | public function __construct(string $name, ?Description $description = null) |
| 46 | { |
| 47 | $this->name = $name; |
| 48 | $this->description = $description; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the identifier of the required access right |
| 53 | * |
| 54 | * @return string |
| 55 | */ |
| 56 | public function getRightId() |
| 57 | { |
| 58 | return (string) $this->rightId; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the name of the parameter |
| 63 | * |
| 64 | * @return string |
| 65 | */ |
| 66 | public function getParameterName() |
| 67 | { |
| 68 | return (string) $this->parameter; |
| 69 | } |
| 70 | |
| 71 | public static function create( |
| 72 | string $body, |
| 73 | string $name = '', |
| 74 | ?DescriptionFactory $descriptionFactory = null, |
| 75 | ?TypeContext $context = null |
| 76 | ): self { |
| 77 | Assert::stringNotEmpty($name); |
| 78 | Assert::notNull($descriptionFactory); |
| 79 | |
| 80 | $description = $body !== '' ? $descriptionFactory->create($body, $context) : null; |
| 81 | |
| 82 | $self = new static($name, $description); |
| 83 | |
| 84 | $parts = preg_split('/\s+/Su', $description, 3); |
| 85 | |
| 86 | if (count($parts) >= 2) { |
| 87 | $self->parameter = $parts[0]; |
| 88 | $self->rightId = $parts[1]; |
| 89 | } |
| 90 | |
| 91 | return $self; |
| 92 | } |
| 93 | |
| 94 | public function __toString(): string |
| 95 | { |
| 96 | return $this->description ? $this->description->render() : ''; |
| 97 | } |
| 98 | } |