1 | <?php |
||
9 | class TokenCountVectorizer implements Vectorizer |
||
10 | { |
||
11 | /** |
||
12 | * @var Tokenizer |
||
13 | */ |
||
14 | private $tokenizer; |
||
15 | |||
16 | /** |
||
17 | * @var float |
||
18 | */ |
||
19 | private $minDF; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $vocabulary; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private $frequencies; |
||
30 | |||
31 | /** |
||
32 | * @param Tokenizer $tokenizer |
||
33 | * @param float $minDF |
||
34 | */ |
||
35 | public function __construct(Tokenizer $tokenizer, float $minDF = 0) |
||
42 | |||
43 | /** |
||
44 | * @param array $samples |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | public function transform(array $samples): array |
||
58 | |||
59 | /** |
||
60 | * @return array |
||
61 | */ |
||
62 | public function getVocabulary() |
||
66 | |||
67 | /** |
||
68 | * @param string $sample |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | private function transformSample(string $sample) |
||
88 | |||
89 | /** |
||
90 | * @param string $token |
||
91 | * |
||
92 | * @return mixed |
||
93 | */ |
||
94 | private function getTokenIndex(string $token) |
||
102 | |||
103 | /** |
||
104 | * @param string $token |
||
105 | */ |
||
106 | private function updateFrequency(string $token) |
||
114 | |||
115 | /** |
||
116 | * @param array $samples |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | private function checkDocumentFrequency(array $samples) |
||
131 | |||
132 | /** |
||
133 | * @param array $sample |
||
134 | * @param array $beyondMinimum |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | private function unsetBeyondMinimum(array $sample, array $beyondMinimum) |
||
146 | |||
147 | /** |
||
148 | * @param int $samplesCount |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | private function getBeyondMinimumIndexes(int $samplesCount) |
||
163 | } |
||
164 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.