Avoid variables with short names like $n. Configured minimum length is 3.
Short variable names may make your code harder to understand. Variable names should
be self-descriptive. This check looks for variable names who are shorter than
a configured minimum.
Loading history...
15
{
16
3
return $this->doNgrams($data, $n, $cyclic);
17
}
18
19
/**
20
* @param string $data
21
* @param int $n
22
* @param bool $cyclic
23
*
24
* @return \Generator
25
*/
26
4
public function ngramsString($data, $n = 1, $cyclic = true)
Avoid variables with short names like $n. Configured minimum length is 3.
Short variable names may make your code harder to understand. Variable names should
be self-descriptive. This check looks for variable names who are shorter than
a configured minimum.
Loading history...
27
{
28
4
foreach ($this->doNgrams(str_split($data), $n, $cyclic) as $data) {
29
4
yield implode('', $data);
30
}
31
4
}
32
33
/**
34
* @param \Generator $ngrams
35
* @param string $substring
36
*
37
* @return float|int
38
*/
39
1
public function frequency(\Generator $ngrams, $substring)
Avoid variables with short names like $n. Configured minimum length is 3.
Short variable names may make your code harder to understand. Variable names should
be self-descriptive. This check looks for variable names who are shorter than
a configured minimum.
Loading history...
44
1
return $n === $substring;
45
1
}))/count($ngrams);
46
}
47
48
/**
49
* @param $data
50
* @param $n
51
* @param $cyclic
52
*
53
* @return \Generator
54
*/
55
7
private function doNgrams($data, $n = 1, $cyclic = true)
Avoid variables with short names like $n. Configured minimum length is 3.
Short variable names may make your code harder to understand. Variable names should
be self-descriptive. This check looks for variable names who are shorter than
a configured minimum.
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.