Add rules for new cs-fixer

This commit is contained in:
Arkadiusz Kondas 2017-01-31 20:33:08 +01:00
parent 87396ebe58
commit c3686358b3
12 changed files with 38 additions and 16 deletions

16
.php_cs Normal file
View File

@ -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);

View File

@ -160,7 +160,7 @@ class Apriori implements Associator
$results = [[]]; $results = [[]];
foreach ($sample as $item) { foreach ($sample as $item) {
foreach ($results as $combination) { foreach ($results as $combination) {
$results[] = array_merge(array($item), $combination); $results[] = array_merge([$item], $combination);
} }
} }

View File

@ -19,20 +19,23 @@ class DecisionTree implements Classifier
/** /**
* @var array * @var array
*/ */
private $samples = array(); private $samples = [];
/** /**
* @var array * @var array
*/ */
private $columnTypes; private $columnTypes;
/** /**
* @var array * @var array
*/ */
private $labels = array(); private $labels = [];
/** /**
* @var int * @var int
*/ */
private $featureCount = 0; private $featureCount = 0;
/** /**
* @var DecisionTreeLeaf * @var DecisionTreeLeaf
*/ */
@ -201,7 +204,7 @@ class DecisionTree implements Classifier
{ {
// Detect and convert continuous data column values into // Detect and convert continuous data column values into
// discrete values by using the median as a threshold value // discrete values by using the median as a threshold value
$columns = array(); $columns = [];
for ($i=0; $i<$this->featureCount; $i++) { for ($i=0; $i<$this->featureCount; $i++) {
$values = array_column($samples, $i); $values = array_column($samples, $i);
if ($this->columnTypes[$i] == self::CONTINUOS) { if ($this->columnTypes[$i] == self::CONTINUOS) {

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Phpml\Classification\DecisionTree; namespace Phpml\Classification\DecisionTree;

View File

@ -150,7 +150,7 @@ class NaiveBayes implements Classifier
*/ */
private function getSamplesByLabel($label) private function getSamplesByLabel($label)
{ {
$samples = array(); $samples = [];
for ($i=0; $i<$this->sampleCount; $i++) { for ($i=0; $i<$this->sampleCount; $i++) {
if ($this->targets[$i] == $label) { if ($this->targets[$i] == $label) {
$samples[] = $this->samples[$i]; $samples[] = $this->samples[$i];
@ -168,7 +168,7 @@ class NaiveBayes implements Classifier
// Use NaiveBayes assumption for each label using: // Use NaiveBayes assumption for each label using:
// P(label|features) = P(label) * P(feature0|label) * P(feature1|label) .... P(featureN|label) // 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 // Then compare probability for each class to determine which label is most likely
$predictions = array(); $predictions = [];
foreach ($this->labels as $label) { foreach ($this->labels as $label) {
$p = $this->p[$label]; $p = $this->p[$label];
for ($i=0; $i<$this->featureCount; $i++) { for ($i=0; $i<$this->featureCount; $i++) {

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Phpml\Clustering; namespace Phpml\Clustering;

View File

@ -50,10 +50,10 @@ class Cluster extends Point implements IteratorAggregate, Countable
*/ */
public function toArray() public function toArray()
{ {
return array( return [
'centroid' => parent::toArray(), 'centroid' => parent::toArray(),
'points' => $this->getPoints(), 'points' => $this->getPoints(),
); ];
} }
/** /**

View File

@ -104,7 +104,7 @@ class Space extends SplObjectStorage
} }
} }
return array($min, $max); return [$min, $max];
} }
/** /**

View File

@ -212,7 +212,7 @@ class Matrix
*/ */
public function divideByScalar($value) public function divideByScalar($value)
{ {
$newMatrix = array(); $newMatrix = [];
for ($i = 0; $i < $this->rows; ++$i) { for ($i = 0; $i < $this->rows; ++$i) {
for ($j = 0; $j < $this->columns; ++$j) { for ($j = 0; $j < $this->columns; ++$j) {
$newMatrix[$i][$j] = $this->matrix[$i][$j] / $value; $newMatrix[$i][$j] = $this->matrix[$i][$j] / $value;
@ -233,7 +233,7 @@ class Matrix
throw MatrixException::notSquareMatrix(); throw MatrixException::notSquareMatrix();
} }
$newMatrix = array(); $newMatrix = [];
for ($i = 0; $i < $this->rows; ++$i) { for ($i = 0; $i < $this->rows; ++$i) {
for ($j = 0; $j < $this->columns; ++$j) { for ($j = 0; $j < $this->columns; ++$j) {
$minor = $this->crossOut($i, $j)->getDeterminant(); $minor = $this->crossOut($i, $j)->getDeterminant();

View File

@ -176,7 +176,7 @@ class AprioriTest extends \PHPUnit_Framework_TestCase
* *
* @return mixed * @return mixed
*/ */
public function invoke(&$object, $method, array $params = array()) public function invoke(&$object, $method, array $params = [])
{ {
$reflection = new \ReflectionClass(get_class($object)); $reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($method); $method = $reflection->getMethod($method);

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace tests\Clustering; namespace tests\Clustering;

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
namespace tests\Phpml\Math; namespace tests\Phpml\Math;