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

Answer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 37
ccs 14
cts 15
cp 0.9333
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceString() 0 3 1
A getCorrectedArray() 0 3 1
A isStringCorrected() 0 3 1
A __construct() 0 10 3
A getFirstCorrectedString() 0 3 2
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