Completed
Push — feature-20rc1 ( 008ae2 )
by Rob
16:55
created

ExtensionAttribute::hasName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\File\Attributes;
13
14
/**
15
 * @author Rob Frawley 2nd <[email protected]>
16
 */
17
class ExtensionAttribute
18
{
19
    use AttributeTrait;
20
21
    /**
22
     * @var string|null
23
     */
24
    private $name;
25
26
    /**
27
     * @param string|null $name
28
     */
29
    public function __construct(string $name = null)
30
    {
31
        $this->name = self::sanitize($name);
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function stringify(): string
38
    {
39
        return $this->hasName() ? $this->getName() : '';
40
    }
41
42
    /**
43
     * @return null|string
44
     */
45
    public function getName(): ?string
46
    {
47
        return $this->name;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function hasName(): bool
54
    {
55
        return null !== $this->getName();
56
    }
57
58
    /**
59
     * @param string|null $name
60
     *
61
     * @return bool
62
     */
63
    public function isNameMatch(string $name = null): bool
64
    {
65
        return $this->getName() === $name;
66
    }
67
68
    /**
69
     * @param string|null $name
70
     *
71
     * @return bool
72
     */
73
    public function isMatch(string $name = null): bool
74
    {
75
        return true === $this->isNameMatch($name);
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isValid(): bool
82
    {
83
        return true === $this->hasName()
84
            && true === self::isParsable($this->stringify());
85
    }
86
87
    /**
88
     * @param string $string
89
     *
90
     * @return array|null
91
     */
92
    public static function explodeParsable(string $string = null): ?array
93
    {
94
        return [
95
            'name' => self::sanitize($string),
96
        ];
97
    }
98
}
99