Passed
Push — master ( 379433...409871 )
by Alexey
02:52
created

Answer::getCorrectedArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace CodeblogPro\YandexSpeller\Application\Models;
4
5
use CodeblogPro\YandexSpeller\Application\Contracts\AnswerInterface;
6
7
class Answer implements AnswerInterface
8
{
9
    private string $sourceString;
10
    private array $correctedStringArray = [];
11
12
    // @ToDo: add the ability to set the language for error correction
13 7
    public function __construct(string $string, array $correctedStringArray)
14
    {
15 7
        $this->sourceString = trim($string);
16
17 7
        foreach ($correctedStringArray as $correctedString) {
18 5
            if (empty(trim($correctedString))) {
19
                continue;
20
            }
21
22 5
            $this->correctedStringArray[] = $correctedString;
23
        }
24 7
    }
25
26 1
    public function getSourceString(): string
27
    {
28 1
        return $this->sourceString;
29
    }
30
31 2
    public function getFirstCorrectedString(): string
32
    {
33 2
        return (empty($this->isStringCorrected())) ? '' : reset($this->correctedStringArray);
34
    }
35
36 1
    public function getCorrectedArray(): array
37
    {
38 1
        return $this->correctedStringArray;
39
    }
40
41 4
    public function isStringCorrected(): bool
42
    {
43 4
        return (empty($this->correctedStringArray) === false);
44
    }
45
}
46