Skip to content

Commit 637bb50

Browse files
committed
chore: add common functions return types
1 parent e11e36c commit 637bb50

22 files changed

+57
-57
lines changed

src/Combinatorics.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(array $dataset = [], $length = null)
5050
* @return int
5151
* The number of element
5252
*/
53-
public function count()
53+
public function count(): int
5454
{
5555
return count($this->toArray());
5656
}
@@ -61,7 +61,7 @@ public function count()
6161
* @return mixed[]
6262
* The dataset
6363
*/
64-
public function getDataset()
64+
public function getDataset(): array
6565
{
6666
return $this->dataset;
6767
}
@@ -72,7 +72,7 @@ public function getDataset()
7272
* @return int
7373
* The length
7474
*/
75-
public function getLength()
75+
public function getLength(): int
7676
{
7777
return (int) $this->length;
7878
}
@@ -85,7 +85,7 @@ public function getLength()
8585
*
8686
* @return $this
8787
*/
88-
public function setDataset(array $dataset = [])
88+
public function setDataset(array $dataset = []): Combinatorics
8989
{
9090
$this->dataset = $dataset;
9191

@@ -100,7 +100,7 @@ public function setDataset(array $dataset = [])
100100
*
101101
* @return $this
102102
*/
103-
public function setLength($length = null)
103+
public function setLength($length = null): Combinatorics
104104
{
105105
$length = $length ?? $this->datasetCount;
106106
$this->length = (abs($length) > $this->datasetCount) ? $this->datasetCount : $length;
@@ -111,7 +111,7 @@ public function setLength($length = null)
111111
/**
112112
* @return array<int, mixed>
113113
*/
114-
public function toArray()
114+
public function toArray(): array
115115
{
116116
return [];
117117
}
@@ -127,7 +127,7 @@ public function toArray()
127127
* @return int
128128
* The factorial of $n
129129
*/
130-
protected function fact($n, $total = 1)
130+
protected function fact($n, $total = 1): int
131131
{
132132
return (2 > $n) ? $total : $this->fact($n - 1, $total * $n);
133133
}

src/GeneratorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ interface GeneratorInterface
1414
* @return Generator<int, mixed>
1515
* The generator
1616
*/
17-
public function generator();
17+
public function generator(): Generator;
1818

1919
/**
2020
* Convert the generator into an array.
2121
*
2222
* @return array<int, mixed>
2323
*/
24-
public function toArray();
24+
public function toArray(): array;
2525
}

src/Generators/Combinations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Combinations extends CombinationsIterator implements GeneratorInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function generator()
24+
public function generator(): Generator
2525
{
2626
return $this->get($this->getDataset(), $this->getLength());
2727
}
@@ -36,7 +36,7 @@ public function generator()
3636
*
3737
* @return Generator<array>
3838
*/
39-
protected function get(array $dataset, $length)
39+
protected function get(array $dataset, $length): Generator
4040
{
4141
$originalLength = count($dataset);
4242
$remainingLength = $originalLength - $length + 1;

src/Generators/Fibonacci.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Fibonacci extends FibonacciIterator implements GeneratorInterface
1313
/**
1414
* {@inheritdoc}
1515
*/
16-
public function generator()
16+
public function generator(): Generator
1717
{
1818
return $this->get();
1919
}
@@ -23,7 +23,7 @@ public function generator()
2323
*
2424
* @return Generator<int>
2525
*/
26-
protected function get()
26+
protected function get(): Generator
2727
{
2828
$a = 0;
2929
$b = 1;

src/Generators/FiniteGroup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FiniteGroup extends FiniteGroupIterator implements GeneratorInterface
1818
/**
1919
* {@inheritdoc}
2020
*/
21-
public function generator()
21+
public function generator(): Generator
2222
{
2323
return $this->get();
2424
}
@@ -29,7 +29,7 @@ public function generator()
2929
* @return Generator<int>
3030
* The finite group generator
3131
*/
32-
protected function get()
32+
protected function get(): Generator
3333
{
3434
foreach ($this->group as $number) {
3535
yield $number;

src/Generators/NGrams.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class NGrams extends NGramsIterator implements GeneratorInterface
1313
/**
1414
* {@inheritdoc}
1515
*/
16-
public function generator()
16+
public function generator(): Generator
1717
{
1818
return $this->get();
1919
}
2020

2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function toArray()
24+
public function toArray(): array
2525
{
2626
return [];
2727
}
@@ -32,7 +32,7 @@ public function toArray()
3232
* @return Generator<int>
3333
* The generator
3434
*/
35-
protected function get()
35+
protected function get(): Generator
3636
{
3737
while (true) {
3838
$this->next();

src/Generators/Perfect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Perfect extends PerfectIterator implements GeneratorInterface
1212
/**
1313
* {@inheritdoc}
1414
*/
15-
public function generator()
15+
public function generator(): \Generator
1616
{
1717
for ($j = 2; $this->getMaxLimit() >= $j; ++$j) {
1818
if ($this->isPerfectNumber($j)) {

src/Generators/Permutations.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public function __construct(array $dataset = [], $length = null)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function count()
39+
public function count(): int
4040
{
4141
return $this->combinations->count() * $this->fact($this->getLength());
4242
}
4343

4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function generator()
47+
public function generator(): Generator
4848
{
4949
foreach ($this->combinations->generator() as $combination) {
5050
foreach ($this->get($combination) as $current) {
@@ -56,7 +56,7 @@ public function generator()
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function toArray()
59+
public function toArray(): array
6060
{
6161
$data = [];
6262

@@ -75,7 +75,7 @@ public function toArray()
7575
*
7676
* @return Generator<array>
7777
*/
78-
protected function get(array $dataset)
78+
protected function get(array $dataset): Generator
7979
{
8080
foreach ($dataset as $key => $firstItem) {
8181
$remaining = $dataset;

src/Generators/Prime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Prime extends PrimeIterator implements GeneratorInterface
1212
/**
1313
* {@inheritdoc}
1414
*/
15-
public function generator()
15+
public function generator(): \Generator
1616
{
1717
for ($j = 2; $this->getMaxLimit() >= $j; ++$j) {
1818
if ($this->isPrimeNumber($j)) {

src/Generators/PrimeFactors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PrimeFactors extends PrimeFactorsIterator implements GeneratorInterface
1212
/**
1313
* {@inheritdoc}
1414
*/
15-
public function generator()
15+
public function generator(): \Generator
1616
{
1717
$number = $this->getNumber();
1818

0 commit comments

Comments
 (0)