Completed
Push — v2 ( 094005...546f8a )
by Joschi
04:35
created

StringValue::getLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\Micrometa
8
 * @subpackage Jkphl\Micrometa\Application\Value
9
 * @author Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\Micrometa\Application\Value;
38
39
use Jkphl\Micrometa\Application\Contract\ValueInterface;
40
41
/**
42
 * String value
43
 *
44
 * @package Jkphl\Micrometa
45
 * @subpackage Jkphl\Micrometa\Application
46
 */
47
class StringValue implements ValueInterface
48
{
49
    /**
50
     * String value
51
     *
52
     * @var string
53
     */
54
    protected $value;
55
    /**
56
     * Language
57
     *
58
     * @var string|null
59
     */
60
    protected $language;
61
62
    /**
63
     * String value constructor
64
     *
65
     * @param string $value String value
66
     * @param string|null $language Language
67
     */
68 25
    public function __construct($value, $language = null)
69
    {
70 25
        $this->value = $value;
71 25
        $this->language = $language;
72 25
    }
73
74
    /**
75
     * Return whether the value should be considered empty
76
     *
77
     * @return boolean Value is empty
78
     */
79 29
    public function isEmpty()
80
    {
81 29
        return !strlen(trim($this->value));
82
    }
83
84
    /**
85
     * String serialization
86
     *
87
     * @return string Value
88
     */
89 11
    public function __toString()
90
    {
91 11
        return strval($this->value);
92
    }
93
94
    /**
95
     * Export the object
96
     *
97
     * @return mixed
98
     */
99 4
    public function export()
100
    {
101 4
        return strval($this);
102
    }
103
104
    /**
105
     * Return the language of this value
106
     *
107
     * @return string Language
108
     */
109 1
    public function getLanguage()
110
    {
111 1
        return $this->language;
112
    }
113
}
114