Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

PHPString   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toTexts() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Source;
6
7
use PhpSpellcheck\Exception\RuntimeException;
8
use PhpSpellcheck\Text;
9
use PhpSpellcheck\TextInterface;
10
11
class PHPString implements SourceInterface
12
{
13
    /**
14
     * @var string
15
     */
16 4
    private $string;
17
18 4
    public function __construct(string $string)
19 4
    {
20
        $this->string = $string;
21
    }
22
23
    /**
24
     * @param array $context
25
     *
26 4
     * @return TextInterface[]
27
     */
28 4
    public function toTexts(array $context): iterable
29 4
    {
30
        $encoding = mb_detect_encoding($this->string, null, true);
31
32
        if ($encoding === false) {
33
            throw new RuntimeException(
34
                \Safe\sprintf(
35
                    'Coulnd\'t detect enconding of string:' . PHP_EOL . '%s',
36
                    $this->string
37
                )
38
            );
39
        }
40
41
        yield new Text($this->string, $encoding, $context);
0 ignored issues
show
Bug Best Practice introduced by
The expression yield new PhpSpellcheck\...g, $encoding, $context) returns the type Generator which is incompatible with the documented return type PhpSpellcheck\TextInterface[].
Loading history...
42
    }
43
}
44