SectionFormOptions::getRedirect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\SectionField\ValueObject;
15
16
use Assert\Assertion;
17
18
final class SectionFormOptions
19
{
20
    /** @var $options */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $options at position 0 could not be parsed: Unknown type name '$options' at position 0 in $options.
Loading history...
21
    private $options;
22
23
    private function __construct(array $options)
24
    {
25
        $this->options = $options;
26
    }
27
28
    public function getId(): Id
29
    {
30
        Assertion::keyIsset($this->options, 'id', 'The id is not set');
31
        Assertion::digit($this->options['id'], 'The id must be a digit');
32
33
        return Id::fromInt((int) $this->options['id']);
34
    }
35
36
    public function getSlug(): Slug
37
    {
38
        Assertion::keyIsset($this->options, 'slug', 'The slug is not set');
39
        Assertion::string($this->options['slug'], 'The slug must be a string');
40
        Assertion::notEmpty($this->options['slug'], 'The slug is empty');
41
42
        return Slug::fromString($this->options['slug']);
43
    }
44
45
    public function getRedirect(): string
46
    {
47
        Assertion::keyIsset($this->options, 'redirect', 'The redirect is not set');
48
        Assertion::string($this->options['redirect'], 'The redirect must be a string');
49
50
        return $this->options['redirect'];
51
    }
52
53
    public static function fromArray(array $options): self
54
    {
55
        return new self($options);
56
    }
57
}
58