From c3686358b368aeac9ee61a33e0cc2c83d3873cf0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Tue, 31 Jan 2017 20:33:08 +0100 Subject: [PATCH] Add rules for new cs-fixer --- .php_cs | 16 ++++++++++++++++ src/Phpml/Association/Apriori.php | 2 +- src/Phpml/Classification/DecisionTree.php | 9 ++++++--- .../DecisionTree/DecisionTreeLeaf.php | 1 + src/Phpml/Classification/NaiveBayes.php | 4 ++-- src/Phpml/Clustering/FuzzyCMeans.php | 1 + src/Phpml/Clustering/KMeans/Cluster.php | 6 +++--- src/Phpml/Clustering/KMeans/Space.php | 2 +- src/Phpml/Math/Matrix.php | 4 ++-- tests/Phpml/Association/AprioriTest.php | 2 +- tests/Phpml/Clustering/FuzzyCMeansTest.php | 5 +++-- tests/Phpml/Math/SetTest.php | 2 +- 12 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 .php_cs diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000..417cafa3 --- /dev/null +++ b/.php_cs @@ -0,0 +1,16 @@ +setRules([ + '@PSR2' => true, + 'declare_strict_types' => true, + 'array_syntax' => ['syntax' => 'short'], + 'blank_line_after_opening_tag' => true, + 'single_blank_line_before_namespace' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/tests') + )->setRiskyAllowed(true) + ->setUsingCache(false); \ No newline at end of file diff --git a/src/Phpml/Association/Apriori.php b/src/Phpml/Association/Apriori.php index 48556917..362f25a6 100644 --- a/src/Phpml/Association/Apriori.php +++ b/src/Phpml/Association/Apriori.php @@ -160,7 +160,7 @@ private function powerSet(array $sample) : array $results = [[]]; foreach ($sample as $item) { foreach ($results as $combination) { - $results[] = array_merge(array($item), $combination); + $results[] = array_merge([$item], $combination); } } diff --git a/src/Phpml/Classification/DecisionTree.php b/src/Phpml/Classification/DecisionTree.php index 033b22bf..45b63298 100644 --- a/src/Phpml/Classification/DecisionTree.php +++ b/src/Phpml/Classification/DecisionTree.php @@ -19,20 +19,23 @@ class DecisionTree implements Classifier /** * @var array */ - private $samples = array(); + private $samples = []; /** * @var array */ private $columnTypes; + /** * @var array */ - private $labels = array(); + private $labels = []; + /** * @var int */ private $featureCount = 0; + /** * @var DecisionTreeLeaf */ @@ -201,7 +204,7 @@ protected function preprocess(array $samples) { // Detect and convert continuous data column values into // discrete values by using the median as a threshold value - $columns = array(); + $columns = []; for ($i=0; $i<$this->featureCount; $i++) { $values = array_column($samples, $i); if ($this->columnTypes[$i] == self::CONTINUOS) { diff --git a/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php b/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php index 220f8768..d4289197 100644 --- a/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php +++ b/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php @@ -1,4 +1,5 @@ sampleCount; $i++) { if ($this->targets[$i] == $label) { $samples[] = $this->samples[$i]; @@ -168,7 +168,7 @@ protected function predictSample(array $sample) // Use NaiveBayes assumption for each label using: // P(label|features) = P(label) * P(feature0|label) * P(feature1|label) .... P(featureN|label) // Then compare probability for each class to determine which label is most likely - $predictions = array(); + $predictions = []; foreach ($this->labels as $label) { $p = $this->p[$label]; for ($i=0; $i<$this->featureCount; $i++) { diff --git a/src/Phpml/Clustering/FuzzyCMeans.php b/src/Phpml/Clustering/FuzzyCMeans.php index ed4fd9e3..424f2f15 100644 --- a/src/Phpml/Clustering/FuzzyCMeans.php +++ b/src/Phpml/Clustering/FuzzyCMeans.php @@ -1,4 +1,5 @@ parent::toArray(), 'points' => $this->getPoints(), - ); + ]; } /** @@ -143,5 +143,5 @@ public function count() public function setCoordinates(array $newCoordinates) { $this->coordinates = $newCoordinates; - } + } } diff --git a/src/Phpml/Clustering/KMeans/Space.php b/src/Phpml/Clustering/KMeans/Space.php index c51cc05c..5a4d5305 100644 --- a/src/Phpml/Clustering/KMeans/Space.php +++ b/src/Phpml/Clustering/KMeans/Space.php @@ -104,7 +104,7 @@ public function getBoundaries() } } - return array($min, $max); + return [$min, $max]; } /** diff --git a/src/Phpml/Math/Matrix.php b/src/Phpml/Math/Matrix.php index 4e70305f..6485a7db 100644 --- a/src/Phpml/Math/Matrix.php +++ b/src/Phpml/Math/Matrix.php @@ -212,7 +212,7 @@ public function multiply(Matrix $matrix) */ public function divideByScalar($value) { - $newMatrix = array(); + $newMatrix = []; for ($i = 0; $i < $this->rows; ++$i) { for ($j = 0; $j < $this->columns; ++$j) { $newMatrix[$i][$j] = $this->matrix[$i][$j] / $value; @@ -233,7 +233,7 @@ public function inverse() throw MatrixException::notSquareMatrix(); } - $newMatrix = array(); + $newMatrix = []; for ($i = 0; $i < $this->rows; ++$i) { for ($j = 0; $j < $this->columns; ++$j) { $minor = $this->crossOut($i, $j)->getDeterminant(); diff --git a/tests/Phpml/Association/AprioriTest.php b/tests/Phpml/Association/AprioriTest.php index 57ef5de5..45631086 100644 --- a/tests/Phpml/Association/AprioriTest.php +++ b/tests/Phpml/Association/AprioriTest.php @@ -176,7 +176,7 @@ public function testEquals() * * @return mixed */ - public function invoke(&$object, $method, array $params = array()) + public function invoke(&$object, $method, array $params = []) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($method); diff --git a/tests/Phpml/Clustering/FuzzyCMeansTest.php b/tests/Phpml/Clustering/FuzzyCMeansTest.php index 16d4a976..56d3c63c 100644 --- a/tests/Phpml/Clustering/FuzzyCMeansTest.php +++ b/tests/Phpml/Clustering/FuzzyCMeansTest.php @@ -1,4 +1,5 @@ cluster($samples); $this->assertCount(2, $clusters); foreach ($samples as $index => $sample) { @@ -40,4 +41,4 @@ public function testMembershipMatrix() $this->assertEquals(1, array_sum($col)); } } -} \ No newline at end of file +} diff --git a/tests/Phpml/Math/SetTest.php b/tests/Phpml/Math/SetTest.php index 5426764f..c6548c79 100644 --- a/tests/Phpml/Math/SetTest.php +++ b/tests/Phpml/Math/SetTest.php @@ -1,4 +1,4 @@ -