Skip to content

Commit 7c9da98

Browse files
committed
refactoring
1 parent 055096b commit 7c9da98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+256
-118
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"phpunit/phpunit": "6.5"
1919
},
2020
"require": {
21-
"doganoo/php-util": "0.0.*"
21+
"doganoo/php-util": "0.0.*",
22+
"zumba/json-serializer": "*"
2223
}
2324
}

src/Algorithm/Search/BidirectionalSearch.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
*/
3939
class BidirectionalSearch {
4040

41-
public function hasPath(Node $start, Node $end) {
41+
/**
42+
* @param Node $start
43+
* @param Node $end
44+
* @return bool
45+
*/
46+
public function hasPath(Node $start, Node $end): bool {
4247
$startList = $this->performSearch($start);
4348
$endList = $this->performSearch($end);
4449

@@ -49,7 +54,7 @@ public function hasPath(Node $start, Node $end) {
4954
$startList->retainAll($endList);
5055
return $startList->length() > 0;
5156
}
52-
57+
return false;
5358
}
5459

5560
/**

src/Algorithm/Search/DepthFirstSearch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public function search(AbstractGraph $graph) {
5353

5454
/**
5555
* @param Node|null $node
56-
* @return mixed
56+
* @return void
5757
*/
58-
public function searchByNode(?Node $node) {
58+
public function searchByNode(?Node $node): void {
5959
if (null === $node) {
6060
return;
6161
}

src/Algorithm/Sorting/QuickSort.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* SOFTWARE.
2424
*/
2525

26-
namespace doganoo\PHPAlgorithms\Sort;
26+
namespace doganoo\PHPAlgorithms\Algorithm\Sorting;
2727

2828

2929
use doganoo\PHPAlgorithms\Common\Interfaces\ISortable;
@@ -32,7 +32,7 @@
3232
/**
3333
* Class QuickSort
3434
*
35-
* @package doganoo\PHPAlgorithms\Sort
35+
* @package doganoo\PHPAlgorithms\Sorting
3636
*/
3737
class QuickSort implements ISortable {
3838
/**

src/Algorithm/Traversal/InOrder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@
2727

2828

2929
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTraverse;
30+
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTree;
3031
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryNode;
31-
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryTree;
3232

3333
/**
3434
* Class InOrder
3535
*
3636
* @package doganoo\PHPAlgorithms\Algorithm\Traversal
3737
*/
3838
class InOrder extends AbstractTraverse {
39-
/** @var IBinaryTree|null */
39+
/** @var AbstractTree|null */
4040
private $binarySearchTree = null;
4141

4242
/**
4343
* InOrder constructor.
4444
*
45-
* @param IBinaryTree $tree
45+
* @param AbstractTree $tree
4646
*/
47-
public function __construct(IBinaryTree $tree) {
47+
public function __construct(AbstractTree $tree) {
4848
$this->binarySearchTree = $tree;
4949
}
5050

src/Algorithm/Traversal/PostOrder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
namespace doganoo\PHPAlgorithms\Algorithm\Traversal;
2727

2828
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTraverse;
29+
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTree;
2930
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryNode;
30-
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryTree;
3131

3232
/**
3333
* Class PostOrder
3434
*
3535
* @package doganoo\PHPAlgorithms\Algorithm\Traversal
3636
*/
3737
class PostOrder extends AbstractTraverse {
38-
/** @var IBinaryTree|null */
38+
/** @var AbstractTree|null */
3939
private $tree = null;
4040

4141
/**
4242
* PostOrder constructor.
4343
*
44-
* @param IBinaryTree $tree
44+
* @param AbstractTree $tree
4545
*/
46-
public function __construct(IBinaryTree $tree) {
46+
public function __construct(AbstractTree $tree) {
4747
$this->tree = $tree;
4848
}
4949

src/Algorithm/Traversal/PreOrder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
namespace doganoo\PHPAlgorithms\Algorithm\Traversal;
2727

2828
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTraverse;
29+
use doganoo\PHPAlgorithms\Common\Abstracts\AbstractTree;
2930
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryNode;
30-
use doganoo\PHPAlgorithms\Common\Interfaces\IBinaryTree;
3131

3232
/**
3333
* Class PreOrder
3434
*
3535
* @package doganoo\PHPAlgorithms\Algorithm\Traversal
3636
*/
3737
class PreOrder extends AbstractTraverse {
38-
/** @var IBinaryTree|null */
38+
/** @var AbstractTree|null */
3939
private $tree = null;
4040

4141
/**
4242
* PreOrder constructor.
4343
*
44-
* @param IBinaryTree $tree
44+
* @param AbstractTree $tree
4545
*/
46-
public function __construct(IBinaryTree $tree) {
46+
public function __construct(AbstractTree $tree) {
4747
$this->tree = $tree;
4848
}
4949

src/Common/Abstracts/AbstractLinkedList.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ public function isEmpty() {
310310
* TODO decide whether using add or append/prepend
311311
*
312312
* @param \doganoo\PHPAlgorithms\Datastructure\Lists\Node $node
313-
* @throws \ReflectionException
314313
*/
315314
public function addNode(Node $node) {
316315
$this->add($node->getKey(), $node->getValue());
@@ -479,21 +478,6 @@ public function replaceValue($key, $value): bool {
479478
return $replaced;
480479
}
481480

482-
/**
483-
* string representation of a LinkedList instance
484-
*
485-
* @return string
486-
*/
487-
public function __toString() {
488-
$head = $this->getHead();
489-
$string = "";
490-
while ($head !== null) {
491-
$string .= $head . "\n";
492-
$head = $head->getNext();
493-
}
494-
return $string;
495-
}
496-
497481
//protected function removeDuplicates() {
498482
// $node = $this->head;
499483
// $previous = $this->head;

src/Common/Interfaces/Comparable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Interface Comparable
3030
*
3131
* @package doganoo\PHPAlgorithms\common\Interfaces
32+
* @deprecated use IComparable instead (due to name conventions)
3233
*/
3334
interface Comparable {
3435
/**

src/Common/Interfaces/IBinaryNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* @package doganoo\PHPAlgorithms\Common\Interfaces
3232
*/
33-
interface IBinaryNode extends INode, Comparable {
33+
interface IBinaryNode extends INode {
3434
/**
3535
* @return mixed
3636
*/

0 commit comments

Comments
 (0)