Completed
Push — master ( 463d73...47ba96 )
by Gerrit
02:04
created

LiteralArgumentFactory::understandsString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\SymfonyGenerics\Arguments\ArgumentFactory;
14
15
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactory;
16
use Addiks\SymfonyGenerics\Arguments\Argument;
17
use Addiks\SymfonyGenerics\Arguments\LiteralArgument;
18
19
final class LiteralArgumentFactory implements ArgumentFactory
20
{
21
22
    public function understandsString(string $source): bool
23
    {
24
        return true;
25
    }
26
27
    public function understandsArray(array $source): bool
28
    {
29
        return true;
30
    }
31
32
    public function createArgumentFromString(string $source): Argument
33
    {
34
        if ($source[0] === '"') {
35
            $source = substr($source, 1, strlen($source) - 2);
36
37
        } elseif ($source[0] === "'") {
38
            $source = substr($source, 1, strlen($source) - 2);
39
        }
40
41
        return new LiteralArgument($source);
42
    }
43
44
    public function createArgumentFromArray(array $source): Argument
45
    {
46
        return new LiteralArgument($source);
47
    }
48
49
}
50