Passed
Pull Request — master (#106)
by Matt
08:38
created

SpellingService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A checkString() 0 9 2
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
}