Skip to content

Commit

Permalink
Add rules for new cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Jan 31, 2017
1 parent 87396eb commit c368635
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 16 deletions.
16 changes: 16 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return PhpCsFixer\Config::create()
->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);
2 changes: 1 addition & 1 deletion src/Phpml/Association/Apriori.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/Phpml/Classification/DecisionTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Phpml\Classification\DecisionTree;
Expand Down
4 changes: 2 additions & 2 deletions src/Phpml/Classification/NaiveBayes.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function sampleProbability($sample, $feature, $label)
*/
private function getSamplesByLabel($label)
{
$samples = array();
$samples = [];
for ($i=0; $i<$this->sampleCount; $i++) {
if ($this->targets[$i] == $label) {
$samples[] = $this->samples[$i];
Expand All @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions src/Phpml/Clustering/FuzzyCMeans.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Phpml\Clustering;
Expand Down
6 changes: 3 additions & 3 deletions src/Phpml/Clustering/KMeans/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function getPoints()
*/
public function toArray()
{
return array(
return [
'centroid' => parent::toArray(),
'points' => $this->getPoints(),
);
];
}

/**
Expand Down Expand Up @@ -143,5 +143,5 @@ public function count()
public function setCoordinates(array $newCoordinates)
{
$this->coordinates = $newCoordinates;
}
}
}
2 changes: 1 addition & 1 deletion src/Phpml/Clustering/KMeans/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getBoundaries()
}
}

return array($min, $max);
return [$min, $max];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Phpml/Math/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/Phpml/Association/AprioriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/Phpml/Clustering/FuzzyCMeansTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace tests\Clustering;
Expand All @@ -10,7 +11,7 @@ class FuzzyCMeansTest extends \PHPUnit_Framework_TestCase
public function testFCMSamplesClustering()
{
$samples = [[1, 1], [8, 7], [1, 2], [7, 8], [2, 1], [8, 9]];
$fcm = new FuzzyCMeans(2);
$fcm = new FuzzyCMeans(2);
$clusters = $fcm->cluster($samples);
$this->assertCount(2, $clusters);
foreach ($samples as $index => $sample) {
Expand Down Expand Up @@ -40,4 +41,4 @@ public function testMembershipMatrix()
$this->assertEquals(1, array_sum($col));
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Phpml/Math/SetTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace tests\Phpml\Math;

Expand Down

0 comments on commit c368635

Please sign in to comment.