| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class ListCollectionUuid |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $uuid; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * ListCollectionUUId constructor. |
||
| 26 | * |
||
| 27 | * @param null $uuid |
||
|
|
|||
| 28 | */ |
||
| 29 | public function __construct($uuid = null) |
||
| 30 | { |
||
| 31 | $this->setUuid($uuid); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param null $uuid |
||
| 36 | * |
||
| 37 | * @throws ListCollectionNotAllowedUuidException |
||
| 38 | */ |
||
| 39 | public function setUuid($uuid = null) |
||
| 40 | { |
||
| 41 | $notAllowedNames = [ |
||
| 42 | ListRepositoryInterface::CHUNK, |
||
| 43 | ListRepositoryInterface::HEADERS, |
||
| 44 | ListRepositoryInterface::INDEX, |
||
| 45 | ListRepositoryInterface::SEPARATOR, |
||
| 46 | ListRepositoryInterface::STATISTICS, |
||
| 47 | ]; |
||
| 48 | |||
| 49 | foreach ($notAllowedNames as $notAllowedName) { |
||
| 50 | if (strpos($uuid, $notAllowedName) !== false) { |
||
| 51 | throw new ListCollectionNotAllowedUuidException('You can\'t assign "'.$uuid.'" as list uuid.'); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->uuid = str_replace(' ', '-', $uuid) ?: Uuid::uuid4()->toString(); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return mixed |
||
| 60 | */ |
||
| 61 | public function getUuid() |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function __toString() |
||
| 72 | } |
||
| 73 | } |
||
| 74 |