Attribute::isValid()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 4
nc 5
nop 0
crap 20
1
<?php
2
namespace execut\import\components\parser;
3
4
5
use execut\import\components\parser\exception\ColumnIsEmpty;
6
use yii\base\Component;
7
8
class Attribute extends Component
9
{
10
    public $row = null;
11
    public $key = null;
12
    public $column = null;
13
    public $numberDelimiter = null;
14
    public $isRequired = true;
15
    public $isForSearchQuery = true;
16
    protected $value = null;
17 10
    public function getValue() {
18 10
        if ($this->value !== null) {
19 5
            return $this->value;
20
        }
21
22 5
        if (!empty($this->row[$this->column])) {
23 3
            $value = trim($this->row[$this->column]);
24 3
            if ($this->numberDelimiter !== null) {
25 1
                $value = str_replace($this->numberDelimiter, '.', $value);
26
            }
27
28 3
            if ($value) {
29 2
                return $value;
30
            }
31
        }
32 3
    }
33
34
    public function isValid() {
35
        return empty($this->getValue()) && !$this->isRequired || !empty($this->getValue()) && $this->isRequired;
36
    }
37
38 6
    public function setValue($value) {
39 6
        $this->value = $value;
40 6
    }
41
42
    public function __toString()
43
    {
44
        return (string) $this->getValue();
45
    }
46
}