Skip to content

Commit

Permalink
#7: Coding standard update to PSR2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pol Dellaiera authored and Pol Dellaiera committed Apr 10, 2017
1 parent 84546e8 commit fa4893c
Show file tree
Hide file tree
Showing 38 changed files with 1,089 additions and 858 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
"satooshi/php-coveralls": "^1.0",
"phpunit/php-code-coverage": "^4.0",
"scrutinizer/ocular": "^1.3",
"drupal/coder": "^8.2",
"phpro/grumphp": "^0.11"
},
"scripts": {
"phpcs": "./vendor/bin/phpcs --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .",
"phpcbf": "./vendor/bin/phpcbf --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .",
"phpcs": "./vendor/bin/phpcs --standard=PSR2 --ignore=vendor .",
"phpcbf": "./vendor/bin/phpcbf --standard=PSR2 --ignore=vendor .",
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests",
"grumphp": "./vendor/bin/grumphp run",
"coveralls": "./vendor/bin/coveralls",
Expand Down
2 changes: 1 addition & 1 deletion grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:
bin_dir: vendor/bin
tasks:
phpcs:
standard: vendor/drupal/coder/coder_sniffer/Drupal/
standard: PSR2
ignore_patterns:
- vendor/
triggered_by:
Expand Down
62 changes: 34 additions & 28 deletions src/Combinatorics.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
*
* @package drupol\phpermutations
*/
abstract class Combinatorics implements \Countable {
abstract class Combinatorics implements \Countable
{

/**
* The dataset.
*
* @var array
*/
protected $dataset;
protected $dataset;

/**
* The number of values in the dataset.
*
* @var int
*/
protected $datasetCount;
protected $datasetCount;

/**
* The length.
*
* @var int
*/
protected $length;
protected $length;

/**
* Combinatorics constructor.
Expand All @@ -38,11 +39,12 @@ abstract class Combinatorics implements \Countable {
* @param int|null $length
* The length.
*/
public function __construct(array $dataset = array(), $length = NULL) {
$this->setDataset($dataset);
$this->datasetCount = count($this->dataset);
$this->setLength($length);
}
public function __construct(array $dataset = array(), $length = null)
{
$this->setDataset($dataset);
$this->datasetCount = count($this->dataset);
$this->setLength($length);
}

/**
* Set the length.
Expand All @@ -52,22 +54,24 @@ public function __construct(array $dataset = array(), $length = NULL) {
*
* @return $this
*/
public function setLength($length = NULL) {
$length = is_null($length) ? $this->datasetCount : $length;
$this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length;
public function setLength($length = null)
{
$length = is_null($length) ? $this->datasetCount : $length;
$this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length;

return $this;
}
return $this;
}

/**
* Get the length.
*
* @return int
* The length.
*/
public function getLength() {
return (int) $this->length;
}
public function getLength()
{
return (int) $this->length;
}

/**
* Set the dataset.
Expand All @@ -77,21 +81,23 @@ public function getLength() {
*
* @return $this
*/
public function setDataset(array $dataset = array()) {
$this->dataset = $dataset;
public function setDataset(array $dataset = array())
{
$this->dataset = $dataset;

return $this;
}
return $this;
}

/**
* Get the dataset.
*
* @return mixed[]
* The dataset.
*/
public function getDataset() {
return $this->dataset;
}
public function getDataset()
{
return $this->dataset;
}

/**
* Compute the factorial of an integer.
Expand All @@ -104,8 +110,8 @@ public function getDataset() {
* @return int
* The factorial of $n.
*/
protected function fact($n, $total = 1) {
return ($n < 2) ? $total : $this->fact($n - 1, $total * $n);
}

protected function fact($n, $total = 1)
{
return ($n < 2) ? $total : $this->fact($n - 1, $total * $n);
}
}
56 changes: 29 additions & 27 deletions src/Generators/Combinations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
*
* @author Mark Wilson <[email protected]>
*/
class Combinations extends CombinationsIterator {
class Combinations extends CombinationsIterator
{

/**
* Alias of the get() method.
*
* @return \Generator
* The prime generator.
*/
public function generator() {
return $this->get($this->getDataset(), $this->getLength());
}
public function generator()
{
return $this->get($this->getDataset(), $this->getLength());
}

/**
* The generator.
Expand All @@ -35,38 +37,38 @@ public function generator() {
* @return \Generator
* @codingStandardsIgnoreEnd
*/
protected function get(array $dataset, $length) {
$originalLength = count($dataset);
$remainingLength = $originalLength - $length + 1;
for ($i = 0; $i < $remainingLength; $i++) {
$current = $dataset[$i];
if ($length === 1) {
yield [$current];
}
else {
$remaining = array_slice($dataset, $i + 1);
foreach ($this->get($remaining, $length - 1) as $permutation) {
array_unshift($permutation, $current);
yield $permutation;
protected function get(array $dataset, $length)
{
$originalLength = count($dataset);
$remainingLength = $originalLength - $length + 1;
for ($i = 0; $i < $remainingLength; $i++) {
$current = $dataset[$i];
if ($length === 1) {
yield [$current];
} else {
$remaining = array_slice($dataset, $i + 1);
foreach ($this->get($remaining, $length - 1) as $permutation) {
array_unshift($permutation, $current);
yield $permutation;
}
}
}
}
}
}

/**
* Convert the generator into an array.
*
* @return array
* The elements.
*/
public function toArray() {
$data = array();

foreach ($this->generator() as $value) {
$data[] = $value;
}
public function toArray()
{
$data = array();

return $data;
}
foreach ($this->generator() as $value) {
$data[] = $value;
}

return $data;
}
}
34 changes: 18 additions & 16 deletions src/Generators/Fibonacci.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@
*
* @package drupol\phpermutations\Generators
*/
class Fibonacci extends FibonacciIterator {
class Fibonacci extends FibonacciIterator
{

/**
* The maximum value.
*
* @var int
*/
protected $max;
protected $max;

/**
* Alias of the get() method.
*
* @return \Generator
* The prime generator.
*/
public function generator() {
return $this->get();
}
public function generator()
{
return $this->get();
}

/**
* The generator.
Expand All @@ -35,16 +37,16 @@ public function generator() {
* @return \Generator
* @codingStandardsIgnoreEnd
*/
protected function get() {
$a = 0;
$b = 1;
$to = $this->getMaxLimit();
while ($to > 0) {
yield $a;

list($a, $b) = array($b, $a + $b);
$to--;
protected function get()
{
$a = 0;
$b = 1;
$to = $this->getMaxLimit();
while ($to > 0) {
yield $a;

list($a, $b) = array($b, $a + $b);
$to--;
}
}
}

}
20 changes: 11 additions & 9 deletions src/Generators/FiniteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
*
* @package drupol\phpermutations\Generators
*/
class FiniteGroup extends FiniteGroupIterator {
class FiniteGroup extends FiniteGroupIterator
{

/**
* Alias of the get() method.
*
* @return \Generator
* The finite group generator.
*/
public function generator() {
return $this->get();
}
public function generator()
{
return $this->get();
}

/**
* The generator.
Expand All @@ -31,10 +33,10 @@ public function generator() {
* The finite group generator.
* @codingStandardsIgnoreEnd
*/
protected function get() {
foreach ($this->group as $number) {
yield $number;
protected function get()
{
foreach ($this->group as $number) {
yield $number;
}
}
}

}
26 changes: 14 additions & 12 deletions src/Generators/Perfect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@
*
* @package drupol\phpermutations\Generators
*/
class Perfect extends PerfectIterator {
class Perfect extends PerfectIterator
{

/**
* The maximum value.
*
* @var int
*/
protected $max;
protected $max;

/**
* Alias of the get() method.
*
* @return \Generator
* The prime generator.
*/
public function generator() {
return $this->get();
}
public function generator()
{
return $this->get();
}

/**
* The generator.
Expand All @@ -35,12 +37,12 @@ public function generator() {
* @return \Generator
* @codingStandardsIgnoreEnd
*/
protected function get() {
for ($j = 2; $j <= $this->getMaxLimit(); $j++) {
if ($this->isPerfectNumber($j)) {
yield $j;
}
protected function get()
{
for ($j = 2; $j <= $this->getMaxLimit(); $j++) {
if ($this->isPerfectNumber($j)) {
yield $j;
}
}
}
}

}
Loading

0 comments on commit fa4893c

Please sign in to comment.