Passed
Pull Request — master (#106)
by Matt
04:21
created

SpellingService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
rs 10
1
<?php
2
3
namespace App\Service;
4
5
use Mekras\Speller\Source\StringSource;
6
use Mekras\Speller\Aspell\Aspell;
7
8
class SpellingService
9
{
10
    // TODO: Dependency injection
11
    /** @var Aspell */
12
    private $aspell;
13
14
    public function __construct()
15
    {
16
        $this->aspell = new Aspell();
17
    }
18
19
    /**
20
     * Returns simple array of potentially-misspelled words, nothing more for now.
21
     * @param string $input
22
     * @return string[]
23
     */
24
    public function checkString(string $input): array
25
    {
26
        $misspelledWords = [];
27
        $results =  $this->aspell->checkText(new StringSource($input), ['en_GB', 'en']);
28
        // TODO: Something functional
29
        foreach ($results as $result) {
30
            $misspelledWords[] = $result->word;
31
        }
32
        return $misspelledWords;
33
    }
34
}
35