diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..417cafa --- /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 4855691..362f25a 100644 --- a/src/Phpml/Association/Apriori.php +++ b/src/Phpml/Association/Apriori.php @@ -160,7 +160,7 @@ class Apriori implements Associator $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 033b22b..45b6329 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 @@ class DecisionTree implements Classifier { // 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 220f876..d428919 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 @@ class NaiveBayes implements Classifier // 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 ed4fd9e..424f2f1 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 @@ class Cluster extends Point implements IteratorAggregate, Countable 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 c51cc05..5a4d530 100644 --- a/src/Phpml/Clustering/KMeans/Space.php +++ b/src/Phpml/Clustering/KMeans/Space.php @@ -104,7 +104,7 @@ class Space extends SplObjectStorage } } - return array($min, $max); + return [$min, $max]; } /** diff --git a/src/Phpml/Math/Matrix.php b/src/Phpml/Math/Matrix.php index 4e70305..6485a7d 100644 --- a/src/Phpml/Math/Matrix.php +++ b/src/Phpml/Math/Matrix.php @@ -212,7 +212,7 @@ class 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 @@ class Matrix 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 57ef5de..4563108 100644 --- a/tests/Phpml/Association/AprioriTest.php +++ b/tests/Phpml/Association/AprioriTest.php @@ -176,7 +176,7 @@ class AprioriTest extends \PHPUnit_Framework_TestCase * * @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 16d4a97..56d3c63 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 @@ class FuzzyCMeansTest extends \PHPUnit_Framework_TestCase $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 5426764..c6548c7 100644 --- a/tests/Phpml/Math/SetTest.php +++ b/tests/Phpml/Math/SetTest.php @@ -1,4 +1,4 @@ -