Skip to content

Commit b7cfb3c

Browse files
committed
fix phpstan findings
1 parent a7dc0d3 commit b7cfb3c

File tree

12 files changed

+50
-51
lines changed

12 files changed

+50
-51
lines changed

src/Algorithm/Sorting/QuickSort.php

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
use doganoo\PHPAlgorithms\Common\Interfaces\ISortable;
3232
use doganoo\PHPAlgorithms\Common\Util\Comparator;
33-
use function array_values;
3433
use function count;
3534

3635
/**

src/Common/Abstracts/AbstractTraverse.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
namespace doganoo\PHPAlgorithms\Common\Abstracts;
2828

29-
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryNode;
3029
use function is_callable;
3130

3231
/**

src/Datastructure/Graph/Tree/RedBlackTree/Node.php

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
namespace doganoo\PHPAlgorithms\Datastructure\Graph\Tree\RedBlackTree;
2828

29-
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryNode;
30-
use doganoo\PHPAlgorithms\Common\Util\Comparator;
3129
use doganoo\PHPAlgorithms\Datastructure\Graph\Tree\BinaryTree\BinarySearchNode;
3230

3331
/**

src/Datastructure/Lists/LinkedList/SinglyLinkedList.php

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractLinkedList;
3232
use doganoo\PHPAlgorithms\Datastructure\Lists\Node;
33-
use Exception;
34-
use Traversable;
3533

3634
/**
3735
* Class SinglyLinkedList

tests/Graph/trees/trie/TrieTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
declare(strict_types=1);
3+
34
/**
45
* MIT License
56
*
@@ -30,10 +31,11 @@
3031
* Class TrieTest
3132
*/
3233
class TrieTest extends \PHPUnit\Framework\TestCase {
34+
3335
/**
3436
* tests inserting and searching
3537
*/
36-
public function testAdd() {
38+
public function testAdd(): void {
3739
$trie = new Trie();
3840
$trie->insert("Test");
3941
$found = $trie->search("Test");
@@ -42,7 +44,7 @@ public function testAdd() {
4244
$this->assertTrue($found === true);
4345
}
4446

45-
public function testWordCount() {
47+
public function testWordCount(): void {
4648
$this->markTestSkipped("need to repair :-(");
4749
$trie = new Trie();
4850
$trie->insert("this");

tests/Map/NodeTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class NodeTest extends TestCase {
3939
/**
4040
* tests node assignments
4141
*/
42-
public function testNodeReference() {
42+
public function testNodeReference(): void {
4343
$a = new Node();
4444
$a->setKey(1);
4545
$a->setValue("1");
@@ -57,8 +57,8 @@ public function testNodeReference() {
5757

5858
$d = $a;
5959
$d = $d->getNext();
60-
$this->assertTrue($d->size() == 2);
61-
$this->assertTrue($a->size() == 3);
60+
$this->assertTrue(null !== $d && $d->size() == 2);
61+
$this->assertTrue(null !== $d && $a->size() == 3);
6262
}
6363

6464
}

tests/Set/HashSetTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class HashSetTest extends TestCase {
4242
* @throws InvalidKeyTypeException
4343
* @throws UnsupportedKeyTypeException
4444
*/
45-
public function testAdd() {
45+
public function testAdd(): void {
4646
$hashSet = new HashSet();
4747
$hashSet->add("test");
4848
$this->assertTrue($hashSet->size() === 1);
@@ -58,7 +58,7 @@ public function testAdd() {
5858
* @throws UnsupportedKeyTypeException
5959
* @throws InvalidKeyTypeException
6060
*/
61-
public function testContains() {
61+
public function testContains(): void {
6262
$hashSet = new HashSet();
6363
$hashSet->add("test");
6464

@@ -82,7 +82,7 @@ public function testContains() {
8282
* @throws InvalidKeyTypeException
8383
* @throws UnsupportedKeyTypeException
8484
*/
85-
public function testClear() {
85+
public function testClear(): void {
8686
$hashSet = new HashSet();
8787
$hashSet->addAll(["one", "two", "three", "four"]);
8888
$this->assertTrue($hashSet->size() === 4);
@@ -95,7 +95,7 @@ public function testClear() {
9595
* @throws UnsupportedKeyTypeException
9696
* @throws InvalidKeyTypeException
9797
*/
98-
public function testRemove() {
98+
public function testRemove(): void {
9999
$hashSet = new HashSet();
100100
$hashSet->addAll(["one", "two", "three", "four"]);
101101
$this->assertTrue($hashSet->contains("one") === true);

tests/Sorting/SortTest.php

+28-26
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
* Class SortTest
4040
*/
4141
class SortTest extends TestCase {
42-
public function testBubbleSort() {
42+
43+
public function testBubbleSort(): void {
4344
$bubbleSort = new BubbleSort();
44-
$result = $bubbleSort->sort([12, 40, 9, 55, 1, 13]);
45+
$result = $bubbleSort->sort([12, 40, 9, 55, 1, 13]);
4546
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
4647

4748
$result = $bubbleSort->sort([]);
@@ -51,9 +52,9 @@ public function testBubbleSort() {
5152
$this->assertTrue($result === [9]);
5253
}
5354

54-
public function testSelectionSort() {
55+
public function testSelectionSort(): void {
5556
$selectionSort = new SelectionSort();
56-
$result = $selectionSort->sort([12, 40, 9, 55, 1, 13]);
57+
$result = $selectionSort->sort([12, 40, 9, 55, 1, 13]);
5758
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
5859

5960
$result = $selectionSort->sort([]);
@@ -63,10 +64,10 @@ public function testSelectionSort() {
6364
$this->assertTrue($result === [9]);
6465
}
6566

66-
public function testMergeSort() {
67+
public function testMergeSort(): void {
6768
$mergeSort = new MergeSort();
68-
$arr = [12, 40, 9, 55, 1, 13];
69-
$result = $mergeSort->sort($arr);
69+
$arr = [12, 40, 9, 55, 1, 13];
70+
$result = $mergeSort->sort($arr);
7071
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
7172

7273
$result = $mergeSort->sort([]);
@@ -76,10 +77,10 @@ public function testMergeSort() {
7677
$this->assertTrue($result === [9]);
7778
}
7879

79-
public function testInsertionSort() {
80+
public function testInsertionSort(): void {
8081
$insertionSort = new InsertionSort();
81-
$arr = [12, 40, 9, 55, 1, 13];
82-
$result = $insertionSort->sort($arr);
82+
$arr = [12, 40, 9, 55, 1, 13];
83+
$result = $insertionSort->sort($arr);
8384
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
8485

8586
$result = $insertionSort->sort([]);
@@ -89,56 +90,56 @@ public function testInsertionSort() {
8990
$this->assertTrue($result === [9]);
9091
}
9192

92-
public function testTimSort() {
93+
public function testTimSort(): void {
9394

9495
$timSort = new TimSort();
95-
$arr = [12, 40, 9, 55, 1, 13];
96-
$result = $timSort->sort($arr);
96+
$arr = [12, 40, 9, 55, 1, 13];
97+
$result = $timSort->sort($arr);
9798
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
9899

99-
$arr = [5, 21, 7, 23, 19];
100+
$arr = [5, 21, 7, 23, 19];
100101
$result = $timSort->sort($arr);
101102
$this->assertTrue($result === [5, 7, 19, 21, 23]);
102103

103-
$arr = [2, 3, 1, 5, 6, 7];
104+
$arr = [2, 3, 1, 5, 6, 7];
104105
$result = $timSort->sort($arr);
105106
$this->assertTrue($result === [1, 2, 3, 5, 6, 7]);
106107

107-
$arr = [];
108+
$arr = [];
108109
$result = $timSort->sort($arr);
109110
$this->assertTrue($result === []);
110111

111-
$arr = [1];
112+
$arr = [1];
112113
$result = $timSort->sort($arr);
113114
$this->assertTrue($result === [1]);
114115
}
115116

116-
public function testQuickSort() {
117+
public function testQuickSort(): void {
117118
$quickSort = new QuickSort();
118-
$arr = [12, 40, 9, 55, 1, 13];
119-
$result = $quickSort->sort($arr);
119+
$arr = [12, 40, 9, 55, 1, 13];
120+
$result = $quickSort->sort($arr);
120121
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
121122

122-
$arr = [5, 21, 7, 23, 19];
123+
$arr = [5, 21, 7, 23, 19];
123124
$result = $quickSort->sort($arr);
124125
$this->assertTrue($result === [5, 7, 19, 21, 23]);
125126

126-
$arr = [2, 3, 1, 5, 6, 7];
127+
$arr = [2, 3, 1, 5, 6, 7];
127128
$result = $quickSort->sort($arr);
128129
$this->assertTrue($result === [1, 2, 3, 5, 6, 7]);
129130

130-
$arr = [];
131+
$arr = [];
131132
$result = $quickSort->sort($arr);
132133
$this->assertTrue($result === []);
133134

134-
$arr = [1];
135+
$arr = [1];
135136
$result = $quickSort->sort($arr);
136137
$this->assertTrue($result === [1]);
137138
}
138139

139-
public function testRadixSort() {
140+
public function testRadixSort(): void {
140141
$radixSort = new RadixSort();
141-
$result = $radixSort->sort([12, 40, 9, 55, 1, 13]);
142+
$result = $radixSort->sort([12, 40, 9, 55, 1, 13]);
142143
$this->assertTrue($result === [1, 9, 12, 13, 40, 55]);
143144

144145
$result = $radixSort->sort([]);
@@ -147,4 +148,5 @@ public function testRadixSort() {
147148
$result = $radixSort->sort([9]);
148149
$this->assertTrue($result === [9]);
149150
}
151+
150152
}

tests/StackQueue/CircularBufferTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
*/
3535
class CircularBufferTest extends TestCase {
3636

37-
public function testMinimalSize() {
37+
public function testMinimalSize(): void {
3838
$buffer = new CircularBuffer(2);
3939
$this->assertTrue($buffer->isEmpty() === true);
4040
$buffer->enqueue("A");
4141
$this->assertTrue($buffer->isEmpty() === false);
4242
$this->assertTrue($buffer->isFull() === true);
4343
}
4444

45-
public function testBigBuffer() {
45+
public function testBigBuffer(): void {
4646
$buffer = new CircularBuffer(8);
4747
$this->assertTrue($buffer->isEmpty() === true);
4848
$buffer->enqueue("A");

tests/StackQueue/FixedStackTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FixedStackTest extends TestCase {
4040
/**
4141
* Stack class test
4242
*/
43-
public function testStack() {
43+
public function testStack(): void {
4444
$stack = new FixedStack(2);
4545
$added = $stack->push(new stdClass());
4646
$this->assertTrue($added === true);
@@ -63,7 +63,7 @@ public function testStack() {
6363
/**
6464
* Queue class test
6565
*/
66-
public function testQueue() {
66+
public function testQueue(): void {
6767
$queue = new FixedQueue(2);
6868
$queue->enqueue(new stdClass());
6969
$queue->enqueue(new Exception());

tests/StackQueue/StackSetTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace doganoo\PHPAlgorithmsTest\StackQueue;
2828

29+
use doganoo\PHPAlgorithms\Common\Exception\IndexOutOfBoundsException;
2930
use doganoo\PHPAlgorithms\Datastructure\Stackqueue\StackSet;
3031
use PHPUnit\Framework\TestCase;
3132

@@ -37,9 +38,9 @@
3738
class StackSetTest extends TestCase {
3839

3940
/**
40-
* @throws \doganoo\PHPAlgorithms\Common\Exception\IndexOutOfBoundsException
41+
* @throws IndexOutOfBoundsException
4142
*/
42-
public function testStackSet() {
43+
public function testStackSet(): void {
4344
$stackSet = new StackSet(2);
4445
$stackSet->push("Hallo");
4546
$stackSet->push("Hallo 2");
@@ -52,9 +53,9 @@ public function testStackSet() {
5253
}
5354

5455
/**
55-
* @throws \doganoo\PHPAlgorithms\Common\Exception\IndexOutOfBoundsException
56+
* @throws IndexOutOfBoundsException
5657
*/
57-
public function testHugeStackSet() {
58+
public function testHugeStackSet(): void {
5859
$setSize = 1024;
5960
$factor = 4;
6061
$stackSet = new StackSet(1024);

tests/StackQueue/StackTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class StackTest extends TestCase {
4040
/**
4141
* Stack class test
4242
*/
43-
public function testStack() {
43+
public function testStack(): void {
4444
$stack = new Stack();
4545
$stack->push(new stdClass());
4646
$stack->push(new Exception());
@@ -58,7 +58,7 @@ public function testStack() {
5858
/**
5959
* Queue class test
6060
*/
61-
public function testQueue() {
61+
public function testQueue(): void {
6262
$queue = new Queue();
6363
$queue->enqueue(new stdClass());
6464
$queue->enqueue(new Exception());

0 commit comments

Comments
 (0)