StringLiteral::fromNative()   A
last analyzed

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 1
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
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
namespace Cubiche\Domain\System;
13
14
use Cubiche\Domain\Model\NativeValueObject;
15
16
/**
17
 * String Literal Class.
18
 *
19
 * @author Karel Osorio Ramírez <[email protected]>
20
 */
21
class StringLiteral extends NativeValueObject
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $value;
27
28
    /**
29
     * @param string $value
30
     *
31
     * @return static
32
     */
33
    public static function fromNative($value)
34
    {
35
        return new static($value);
36
    }
37
38
    /**
39
     * @param string $value
40
     *
41
     * @throws \InvalidArgumentException
42
     */
43
    public function __construct($value)
44
    {
45
        if (\is_string($value) === false) {
46
            throw new \InvalidArgumentException(sprintf(
47
                'Argument "%s" is invalid. Allowed types for argument are "string".',
48
                $value
49
            ));
50
        }
51
52
        $this->value = $value;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function toNative()
59
    {
60
        return $this->value;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isEmpty()
67
    {
68
        return \strlen($this->toNative()) === 0;
69
    }
70
}
71