YesNoType::setValue()   B
last analyzed

Complexity

Conditions 9
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 9

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 9
eloc 13
c 1
b 1
f 0
nc 3
nop 2
dl 0
loc 19
ccs 12
cts 12
cp 1
crap 9
rs 8.0555
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Wszetko Sitemap.
7
 *
8
 * (c) Paweł Kłopotek-Główczewski <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace Wszetko\Sitemap\Items\DataTypes;
15
16
use Wszetko\Sitemap\Interfaces\DataType;
17
18
/**
19
 * Class YesNoType.
20
 *
21
 * @package Wszetko\Sitemap\Items\DataTypes
22
 */
23
class YesNoType extends AbstractDataType
24
{
25
    /**
26
     * @inheritDoc
27
     */
28 98
    public function setValue($value, $parameters = []): DataType
29
    {
30
        if (
31 98
            (is_string($value) === true
32 68
            && preg_grep("/{$value}/i", ['Yes', 'y', '1']) !== [])
33 64
            || true === $value
34 98
            || 1 === $value
35
        ) {
36 50
            $this->value = 'Yes';
37
        } elseif (
38 52
            (is_string($value) === true
39 30
            && preg_grep("/{$value}/i", ['No', 'n', '0']) !== [])
40 22
            || false === $value
41 52
            || 0 === $value
42
        ) {
43 46
            $this->value = 'No';
44
        }
45
46 98
        return $this;
47
    }
48
}
49