tigitz / php-spellchecker

Compare 84b21e5 ... +1 ... 2a98882


@@ -9,6 +9,7 @@
Loading
9 9
use PhpSpellcheck\Misspelling;
10 10
use PhpSpellcheck\Utils\LineAndOffset;
11 11
use Psr\Http\Client\ClientInterface;
12 +
use Webmozart\Assert\Assert;
12 13
13 14
class JamSpell implements SpellcheckerInterface
14 15
{
@@ -34,14 +35,15 @@
Loading
34 35
            ->createRequest('POST', $this->endpoint)
35 36
            ->withBody(Stream::create($text));
36 37
37 -
        $spellcheckResponse = \Safe\json_decode($this->httpClient->sendRequest($request)->getBody()->getContents(), true);
38 +
        $spellcheckResponseAsArray = \Safe\json_decode($spellcheckResponse = $this->httpClient->sendRequest($request)->getBody()->getContents(), true);
39 +
        Assert::isArray($spellcheckResponseAsArray);
38 40
39 41
        // @TODO use json api validation schema
40 -
        if (!isset($spellcheckResponse['results'])) {
42 +
        if (!isset($spellcheckResponseAsArray['results'])) {
41 43
            throw new RuntimeException('Jamspell spellcheck HTTP response must include a "results" key. Response given: "'.$spellcheckResponse.'"');
42 44
        }
43 45
44 -
        foreach ($spellcheckResponse['results'] as $result) {
46 +
        foreach ($spellcheckResponseAsArray['results'] as $result) {
45 47
            [$line, $offset] = LineAndOffset::findFromFirstCharacterOffset($text, $result['pos_from']);
46 48
47 49
            yield new Misspelling(

@@ -21,9 +21,9 @@
Loading
21 21
22 22
    /**
23 23
     * @param array<string> $languages
24 -
     * @param array<array|string|null> $options
24 +
     * @param array<mixed> $options
25 25
     *
26 -
     * @return array<string, array|string>
26 +
     * @return array<string, mixed>
27 27
     */
28 28
    public function spellCheck(string $text, array $languages, array $options): array
29 29
    {
@@ -58,11 +58,11 @@
Loading
58 58
    }
59 59
60 60
    /**
61 -
     * @param array<array|string|null> $queryParams
61 +
     * @param array<mixed> $queryParams
62 62
     *
63 63
     * @throws \RuntimeException
64 64
     *
65 -
     * @return array<array|string>
65 +
     * @return array<mixed>
66 66
     */
67 67
    public function requestAPI(string $endpoint, string $method, string $header, array $queryParams = []): array
68 68
    {
@@ -76,7 +76,9 @@
Loading
76 76
        }
77 77
78 78
        $content = \Safe\file_get_contents($this->baseUrl . $endpoint, false, stream_context_create(['http' => $httpData]));
79 +
        /** @var array<mixed> $contentAsArray */
80 +
        $contentAsArray = \Safe\json_decode($content, true);
79 81
80 -
        return \Safe\json_decode($content, true);
82 +
        return $contentAsArray;
81 83
    }
82 84
}

@@ -35,7 +35,12 @@
Loading
35 35
    ): iterable {
36 36
        Assert::notEmpty($languages, 'LanguageTool requires at least one language to be set to run it\'s spellchecking process');
37 37
38 -
        $check = $this->apiClient->spellCheck($text, $languages, $context[self::class] ?? []);
38 +
        if (isset($context[self::class])) {
39 +
            Assert::isArray($context[self::class]);
40 +
            /** @var array<mixed> $options */
41 +
            $options = $context[self::class];
42 +
        }
43 +
        $check = $this->apiClient->spellCheck($text, $languages, $options ?? []);
39 44
40 45
        if (!\is_array($check['matches'])) {
41 46
            throw new RuntimeException('LanguageTool spellcheck response must contain a "matches" array');

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Complexity Coverage
src ø -0.30% 92.46%
Project Totals (23 files) 166 92.46%
Loading