Skip to content

Commit fa4893c

Browse files
Pol DellaieraPol Dellaiera
Pol Dellaiera
authored and
Pol Dellaiera
committed
#7: Coding standard update to PSR2.
1 parent 84546e8 commit fa4893c

38 files changed

+1089
-858
lines changed

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
"satooshi/php-coveralls": "^1.0",
2424
"phpunit/php-code-coverage": "^4.0",
2525
"scrutinizer/ocular": "^1.3",
26-
"drupal/coder": "^8.2",
2726
"phpro/grumphp": "^0.11"
2827
},
2928
"scripts": {
30-
"phpcs": "./vendor/bin/phpcs --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .",
31-
"phpcbf": "./vendor/bin/phpcbf --standard=vendor/drupal/coder/coder_sniffer/Drupal --ignore=vendor .",
29+
"phpcs": "./vendor/bin/phpcs --standard=PSR2 --ignore=vendor .",
30+
"phpcbf": "./vendor/bin/phpcbf --standard=PSR2 --ignore=vendor .",
3231
"phpunit": "./vendor/bin/phpunit --coverage-clover build/logs/clover.xml -c tests/phpunit.xml tests",
3332
"grumphp": "./vendor/bin/grumphp run",
3433
"coveralls": "./vendor/bin/coveralls",

grumphp.yml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ parameters:
33
bin_dir: vendor/bin
44
tasks:
55
phpcs:
6-
standard: vendor/drupal/coder/coder_sniffer/Drupal/
6+
standard: PSR2
77
ignore_patterns:
88
- vendor/
99
triggered_by:

src/Combinatorics.php

+34-28
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@
77
*
88
* @package drupol\phpermutations
99
*/
10-
abstract class Combinatorics implements \Countable {
10+
abstract class Combinatorics implements \Countable
11+
{
1112

1213
/**
1314
* The dataset.
1415
*
1516
* @var array
1617
*/
17-
protected $dataset;
18+
protected $dataset;
1819

1920
/**
2021
* The number of values in the dataset.
2122
*
2223
* @var int
2324
*/
24-
protected $datasetCount;
25+
protected $datasetCount;
2526

2627
/**
2728
* The length.
2829
*
2930
* @var int
3031
*/
31-
protected $length;
32+
protected $length;
3233

3334
/**
3435
* Combinatorics constructor.
@@ -38,11 +39,12 @@ abstract class Combinatorics implements \Countable {
3839
* @param int|null $length
3940
* The length.
4041
*/
41-
public function __construct(array $dataset = array(), $length = NULL) {
42-
$this->setDataset($dataset);
43-
$this->datasetCount = count($this->dataset);
44-
$this->setLength($length);
45-
}
42+
public function __construct(array $dataset = array(), $length = null)
43+
{
44+
$this->setDataset($dataset);
45+
$this->datasetCount = count($this->dataset);
46+
$this->setLength($length);
47+
}
4648

4749
/**
4850
* Set the length.
@@ -52,22 +54,24 @@ public function __construct(array $dataset = array(), $length = NULL) {
5254
*
5355
* @return $this
5456
*/
55-
public function setLength($length = NULL) {
56-
$length = is_null($length) ? $this->datasetCount : $length;
57-
$this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length;
57+
public function setLength($length = null)
58+
{
59+
$length = is_null($length) ? $this->datasetCount : $length;
60+
$this->length = ($length > $this->datasetCount) ? $this->datasetCount : $length;
5861

59-
return $this;
60-
}
62+
return $this;
63+
}
6164

6265
/**
6366
* Get the length.
6467
*
6568
* @return int
6669
* The length.
6770
*/
68-
public function getLength() {
69-
return (int) $this->length;
70-
}
71+
public function getLength()
72+
{
73+
return (int) $this->length;
74+
}
7175

7276
/**
7377
* Set the dataset.
@@ -77,21 +81,23 @@ public function getLength() {
7781
*
7882
* @return $this
7983
*/
80-
public function setDataset(array $dataset = array()) {
81-
$this->dataset = $dataset;
84+
public function setDataset(array $dataset = array())
85+
{
86+
$this->dataset = $dataset;
8287

83-
return $this;
84-
}
88+
return $this;
89+
}
8590

8691
/**
8792
* Get the dataset.
8893
*
8994
* @return mixed[]
9095
* The dataset.
9196
*/
92-
public function getDataset() {
93-
return $this->dataset;
94-
}
97+
public function getDataset()
98+
{
99+
return $this->dataset;
100+
}
95101

96102
/**
97103
* Compute the factorial of an integer.
@@ -104,8 +110,8 @@ public function getDataset() {
104110
* @return int
105111
* The factorial of $n.
106112
*/
107-
protected function fact($n, $total = 1) {
108-
return ($n < 2) ? $total : $this->fact($n - 1, $total * $n);
109-
}
110-
113+
protected function fact($n, $total = 1)
114+
{
115+
return ($n < 2) ? $total : $this->fact($n - 1, $total * $n);
116+
}
111117
}

src/Generators/Combinations.php

+29-27
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
*
1212
* @author Mark Wilson <mark@89allport.co.uk>
1313
*/
14-
class Combinations extends CombinationsIterator {
14+
class Combinations extends CombinationsIterator
15+
{
1516

1617
/**
1718
* Alias of the get() method.
1819
*
1920
* @return \Generator
2021
* The prime generator.
2122
*/
22-
public function generator() {
23-
return $this->get($this->getDataset(), $this->getLength());
24-
}
23+
public function generator()
24+
{
25+
return $this->get($this->getDataset(), $this->getLength());
26+
}
2527

2628
/**
2729
* The generator.
@@ -35,38 +37,38 @@ public function generator() {
3537
* @return \Generator
3638
* @codingStandardsIgnoreEnd
3739
*/
38-
protected function get(array $dataset, $length) {
39-
$originalLength = count($dataset);
40-
$remainingLength = $originalLength - $length + 1;
41-
for ($i = 0; $i < $remainingLength; $i++) {
42-
$current = $dataset[$i];
43-
if ($length === 1) {
44-
yield [$current];
45-
}
46-
else {
47-
$remaining = array_slice($dataset, $i + 1);
48-
foreach ($this->get($remaining, $length - 1) as $permutation) {
49-
array_unshift($permutation, $current);
50-
yield $permutation;
40+
protected function get(array $dataset, $length)
41+
{
42+
$originalLength = count($dataset);
43+
$remainingLength = $originalLength - $length + 1;
44+
for ($i = 0; $i < $remainingLength; $i++) {
45+
$current = $dataset[$i];
46+
if ($length === 1) {
47+
yield [$current];
48+
} else {
49+
$remaining = array_slice($dataset, $i + 1);
50+
foreach ($this->get($remaining, $length - 1) as $permutation) {
51+
array_unshift($permutation, $current);
52+
yield $permutation;
53+
}
54+
}
5155
}
52-
}
5356
}
54-
}
5557

5658
/**
5759
* Convert the generator into an array.
5860
*
5961
* @return array
6062
* The elements.
6163
*/
62-
public function toArray() {
63-
$data = array();
64-
65-
foreach ($this->generator() as $value) {
66-
$data[] = $value;
67-
}
64+
public function toArray()
65+
{
66+
$data = array();
6867

69-
return $data;
70-
}
68+
foreach ($this->generator() as $value) {
69+
$data[] = $value;
70+
}
7171

72+
return $data;
73+
}
7274
}

src/Generators/Fibonacci.php

+18-16
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99
*
1010
* @package drupol\phpermutations\Generators
1111
*/
12-
class Fibonacci extends FibonacciIterator {
12+
class Fibonacci extends FibonacciIterator
13+
{
1314

1415
/**
1516
* The maximum value.
1617
*
1718
* @var int
1819
*/
19-
protected $max;
20+
protected $max;
2021

2122
/**
2223
* Alias of the get() method.
2324
*
2425
* @return \Generator
2526
* The prime generator.
2627
*/
27-
public function generator() {
28-
return $this->get();
29-
}
28+
public function generator()
29+
{
30+
return $this->get();
31+
}
3032

3133
/**
3234
* The generator.
@@ -35,16 +37,16 @@ public function generator() {
3537
* @return \Generator
3638
* @codingStandardsIgnoreEnd
3739
*/
38-
protected function get() {
39-
$a = 0;
40-
$b = 1;
41-
$to = $this->getMaxLimit();
42-
while ($to > 0) {
43-
yield $a;
44-
45-
list($a, $b) = array($b, $a + $b);
46-
$to--;
40+
protected function get()
41+
{
42+
$a = 0;
43+
$b = 1;
44+
$to = $this->getMaxLimit();
45+
while ($to > 0) {
46+
yield $a;
47+
48+
list($a, $b) = array($b, $a + $b);
49+
$to--;
50+
}
4751
}
48-
}
49-
5052
}

src/Generators/FiniteGroup.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
*
1212
* @package drupol\phpermutations\Generators
1313
*/
14-
class FiniteGroup extends FiniteGroupIterator {
14+
class FiniteGroup extends FiniteGroupIterator
15+
{
1516

1617
/**
1718
* Alias of the get() method.
1819
*
1920
* @return \Generator
2021
* The finite group generator.
2122
*/
22-
public function generator() {
23-
return $this->get();
24-
}
23+
public function generator()
24+
{
25+
return $this->get();
26+
}
2527

2628
/**
2729
* The generator.
@@ -31,10 +33,10 @@ public function generator() {
3133
* The finite group generator.
3234
* @codingStandardsIgnoreEnd
3335
*/
34-
protected function get() {
35-
foreach ($this->group as $number) {
36-
yield $number;
36+
protected function get()
37+
{
38+
foreach ($this->group as $number) {
39+
yield $number;
40+
}
3741
}
38-
}
39-
4042
}

src/Generators/Perfect.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99
*
1010
* @package drupol\phpermutations\Generators
1111
*/
12-
class Perfect extends PerfectIterator {
12+
class Perfect extends PerfectIterator
13+
{
1314

1415
/**
1516
* The maximum value.
1617
*
1718
* @var int
1819
*/
19-
protected $max;
20+
protected $max;
2021

2122
/**
2223
* Alias of the get() method.
2324
*
2425
* @return \Generator
2526
* The prime generator.
2627
*/
27-
public function generator() {
28-
return $this->get();
29-
}
28+
public function generator()
29+
{
30+
return $this->get();
31+
}
3032

3133
/**
3234
* The generator.
@@ -35,12 +37,12 @@ public function generator() {
3537
* @return \Generator
3638
* @codingStandardsIgnoreEnd
3739
*/
38-
protected function get() {
39-
for ($j = 2; $j <= $this->getMaxLimit(); $j++) {
40-
if ($this->isPerfectNumber($j)) {
41-
yield $j;
42-
}
40+
protected function get()
41+
{
42+
for ($j = 2; $j <= $this->getMaxLimit(); $j++) {
43+
if ($this->isPerfectNumber($j)) {
44+
yield $j;
45+
}
46+
}
4347
}
44-
}
45-
4648
}

0 commit comments

Comments
 (0)