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 = [[]];
foreach ($sample as $item) {
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
*/
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) {

View File

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

View File

@ -150,7 +150,7 @@ class NaiveBayes implements Classifier
*/
private function getSamplesByLabel($label)
{
$samples = array();
$samples = [];
for ($i=0; $i<$this->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++) {

View File

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

View File

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

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)
{
$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();

View File

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

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace tests\Clustering;
@ -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) {
@ -40,4 +41,4 @@ class FuzzyCMeansTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1, array_sum($col));
}
}
}
}

View File

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