SpellCheckTrait::spellCheck()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
namespace SoliDry\Extension;
3
4
use SoliDry\Types\ConfigInterface;
5
use SoliDry\Types\PhpInterface;
6
7
/**
8
 * Class SpellCheckTrait
9
 *
10
 * @package SoliDry\Extension
11
 *
12
 * @property ApiController entity
13
 */
14
trait SpellCheckTrait
15
{
16
    /**
17
     * Field spell checker
18
     *
19
     * @param array $jsonProps
20
     *
21
     * @return array
22
     */
23
    protected function spellCheck(array $jsonProps) : array
24
    {
25
        if (extension_loaded(PhpInterface::PHP_EXTENSION_PSPELL) === false) {
26
            return [ConfigInterface::SPELL_CHECK => 'php-pspell library has not been installed on Your system.'];
27
        }
28
29
        $arr        = [];
30
        $spellCheck = new SpellCheck($this->entity);
0 ignored issues
show
Bug introduced by
$this->entity of type SoliDry\Extension\ApiController is incompatible with the type string expected by parameter $entity of SoliDry\Extension\SpellCheck::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $spellCheck = new SpellCheck(/** @scrutinizer ignore-type */ $this->entity);
Loading history...
31
        $field      = $spellCheck->getField();
32
        if ($spellCheck->isEnabled() === true) {
33
            $arr = $spellCheck->check($jsonProps[$field]);
34
        }
35
36
        return [ConfigInterface::SPELL_CHECK => [$field => $arr]];
37
    }
38
}