Completed
Push — master ( ea568a...e269ab )
by Pol
07:52
created

NGramsTrait::getNGrams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpngrams;
6
7
/**
8
 * Trait NGramsTrait
9
 */
10
trait NGramsTrait
11
{
12
    /**
13
     * @var \drupol\phpngrams\NGramsInterface
14
     */
15
    private $ngrams;
16
17
    /**
18
     * @param \drupol\phpngrams\NGramsInterface $ngrams
19
     */
20
    public function setNgram(NGramsInterface $ngrams)
21
    {
22
        $this->ngrams = $ngrams;
23
    }
24
25
    /**
26
     * @return \drupol\phpngrams\NGramsInterface
27
     */
28
    public function getNGrams(): NGramsInterface
29
    {
30
        return $this->ngrams;
31
    }
32
33
    /**
34
     * @param \Generator $ngrams
35
     * @param string|array $substring
36
     *
37
     * @return float|int
38
     */
39
    public function frequency(\Generator $ngrams, $substring)
40
    {
41
        return $this->getNGrams()->frequency($ngrams, $substring);
0 ignored issues
show
Bug introduced by
It seems like $substring defined by parameter $substring on line 39 can also be of type string; however, drupol\phpngrams\NGramsInterface::frequency() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42
    }
43
44
    /**
45
     * @param string|array $data
46
     * @param int $n
47
     *
48
     * @return bool|\Generator
49
     */
50
    public function ngrams($data, int $n = 1)
51
    {
52
        return $this->getNGrams()->ngrams($data, $n);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 50 can also be of type string; however, drupol\phpngrams\NGramsInterface::ngrams() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
53
    }
54
}
55