Skip to content

Commit

Permalink
Update phpstan to 0.10.5 (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
marmichalski authored and akondas committed Oct 28, 2018
1 parent d9b85e8 commit 53c5a6b
Show file tree
Hide file tree
Showing 131 changed files with 1,011 additions and 975 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This changelog references the relevant changes done in PHP-ML library.
* fix SVM locale (non-locale aware) (#288)
* typo, tests, code styles and documentation fixes (#265, #261, #254, #253, #251, #250, #248, #245, #243)
* change [MLPClassifier] return labels in output (#315)
* enhancement Update phpstan to 0.10.5 (#320)

* 0.6.2 (2018-02-22)
* Fix Apriori array keys (#238)
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
},
"require-dev": {
"phpbench/phpbench": "^0.14.0",
"phpstan/phpstan-phpunit": "^0.9.4",
"phpstan/phpstan-shim": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9.0",
"phpstan/phpstan-phpunit": "^0.10",
"phpstan/phpstan-shim": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"phpunit/phpunit": "^7.0.0",
"symplify/coding-standard": "^5.1",
"symplify/easy-coding-standard": "^5.1"
Expand Down
128 changes: 48 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-phpunit/strictRules.neon

parameters:
ignoreErrors:
- '#Property Phpml\\Clustering\\KMeans\\Cluster\:\:\$points \(iterable\<Phpml\\Clustering\\KMeans\\Point\>\&SplObjectStorage\) does not accept SplObjectStorage#'
- '#Phpml\\Dataset\\FilesDataset::__construct\(\) does not call parent constructor from Phpml\\Dataset\\ArrayDataset#'

# wide range cases
- '#Call to function count\(\) with argument type array<int>\|Phpml\\Clustering\\KMeans\\Point will always result in number 1#'
- '#Parameter \#1 \$coordinates of class Phpml\\Clustering\\KMeans\\Point constructor expects array, array<int>\|Phpml\\Clustering\\KMeans\\Point given#'

# probably known value
Expand Down
12 changes: 6 additions & 6 deletions src/Association/Apriori.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public function __construct(float $support = 0.0, float $confidence = 0.0)
*/
public function getRules(): array
{
if (empty($this->large)) {
if (count($this->large) === 0) {
$this->large = $this->apriori();
}

if (!empty($this->rules)) {
if (count($this->rules) > 0) {
return $this->rules;
}

Expand All @@ -89,7 +89,7 @@ public function apriori(): array
$L = [];

$items = $this->frequent($this->items());
for ($k = 1; !empty($items); ++$k) {
for ($k = 1; isset($items[0]); ++$k) {
$L[$k] = $items;
$items = $this->frequent($this->candidates($items));
}
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function predictSample(array $sample): array
*/
private function generateAllRules(): void
{
for ($k = 2; !empty($this->large[$k]); ++$k) {
for ($k = 2; isset($this->large[$k]); ++$k) {
foreach ($this->large[$k] as $frequent) {
$this->generateRules($frequent);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ private function candidates(array $samples): array
continue;
}

foreach ((array) $this->samples as $sample) {
foreach ($this->samples as $sample) {
if ($this->subset($sample, $candidate)) {
$candidates[] = $candidate;

Expand Down Expand Up @@ -316,7 +316,7 @@ private function contains(array $system, array $set): bool
*/
private function subset(array $set, array $subset): bool
{
return !array_diff($subset, array_intersect($subset, $set));
return count(array_diff($subset, array_intersect($subset, $set))) === 0;
}

/**
Expand Down
28 changes: 17 additions & 11 deletions src/Classification/DecisionTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected function getSplitLeaf(array $records, int $depth = 0): DecisionTreeLea
foreach ($records as $recordNo) {
// Check if the previous record is the same with the current one
$record = $this->samples[$recordNo];
if ($prevRecord && $prevRecord != $record) {
if ($prevRecord !== null && $prevRecord != $record) {
$allSame = false;
}

Expand All @@ -275,13 +275,13 @@ protected function getSplitLeaf(array $records, int $depth = 0): DecisionTreeLea
if ($allSame || $depth >= $this->maxDepth || count($remainingTargets) === 1) {
$split->isTerminal = true;
arsort($remainingTargets);
$split->classValue = key($remainingTargets);
$split->classValue = (string) key($remainingTargets);
} else {
if (!empty($leftRecords)) {
if (isset($leftRecords[0])) {
$split->leftLeaf = $this->getSplitLeaf($leftRecords, $depth + 1);
}

if (!empty($rightRecords)) {
if (isset($rightRecords[0])) {
$split->rightLeaf = $this->getSplitLeaf($rightRecords, $depth + 1);
}
}
Expand All @@ -292,8 +292,10 @@ protected function getSplitLeaf(array $records, int $depth = 0): DecisionTreeLea
protected function getBestSplit(array $records): DecisionTreeLeaf
{
$targets = array_intersect_key($this->targets, array_flip($records));
$samples = array_intersect_key($this->samples, array_flip($records));
$samples = array_combine($records, $this->preprocess($samples));
$samples = (array) array_combine(
$records,
$this->preprocess(array_intersect_key($this->samples, array_flip($records)))
);
$bestGiniVal = 1;
$bestSplit = null;
$features = $this->getSelectedFeatures();
Expand All @@ -306,6 +308,10 @@ protected function getBestSplit(array $records): DecisionTreeLeaf
$counts = array_count_values($colValues);
arsort($counts);
$baseValue = key($counts);
if ($baseValue === null) {
continue;
}

$gini = $this->getGiniIndex($baseValue, $colValues, $targets);
if ($bestSplit === null || $bestGiniVal > $gini) {
$split = new DecisionTreeLeaf();
Expand Down Expand Up @@ -349,11 +355,11 @@ protected function getBestSplit(array $records): DecisionTreeLeaf
protected function getSelectedFeatures(): array
{
$allFeatures = range(0, $this->featureCount - 1);
if ($this->numUsableFeatures === 0 && empty($this->selectedFeatures)) {
if ($this->numUsableFeatures === 0 && count($this->selectedFeatures) === 0) {
return $allFeatures;
}

if (!empty($this->selectedFeatures)) {
if (count($this->selectedFeatures) > 0) {
return $this->selectedFeatures;
}

Expand Down Expand Up @@ -406,7 +412,7 @@ protected static function isCategoricalColumn(array $columnValues): bool
// all values in that column (Lower than or equal to %20 of all values)
$numericValues = array_filter($columnValues, 'is_numeric');
$floatValues = array_filter($columnValues, 'is_float');
if (!empty($floatValues)) {
if (count($floatValues) > 0) {
return false;
}

Expand Down Expand Up @@ -463,7 +469,7 @@ protected function predictSample(array $sample)
$node = $this->tree;
do {
if ($node->isTerminal) {
break;
return $node->classValue;
}

if ($node->evaluate($sample)) {
Expand All @@ -473,6 +479,6 @@ protected function predictSample(array $sample)
}
} while ($node);

return $node !== null ? $node->classValue : $this->labels[0];
return $this->labels[0];
}
}
Loading

0 comments on commit 53c5a6b

Please sign in to comment.