Skip to content

Commit

Permalink
Merge pull request #3 from WebFiori/dev
Browse files Browse the repository at this point in the history
Code Quality Updates
  • Loading branch information
usernane committed Feb 14, 2023
2 parents 5309b7c + b1a8cdb commit f2ba3f6
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/nbproject
.phpunit.result.cache
clover.xml
composer.lock
vendor/*
8 changes: 4 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<file>./src/LinkedList.php</file>
<file>./src/Node.php</file>
<file>./src/Stack.php</file>
<file>./src/Queue.php</file>
<file>./webfiori/collections/LinkedList.php</file>
<file>./webfiori/collections/Node.php</file>
<file>./webfiori/collections/Stack.php</file>
<file>./webfiori/collections/Queue.php</file>
</whitelist>
</filter>
<logging>
Expand Down
11 changes: 1 addition & 10 deletions tests/data-structures/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,13 @@ public function test09() {
$this->assertEquals(0,$queue->size());
$this->assertEquals(1,$queue->max());
}
/**
* @test
*/
public function test10() {
$queue = new Queue('Random Str');
$this->assertEquals(0,$queue->size());
$this->assertEquals(-1,$queue->max());
$this->assertNull($queue->peek());
}
/**
* @test
*/
public function test11() {
$queue = new Queue('11');
$this->assertEquals(0,$queue->size());
$this->assertEquals(-1,$queue->max());
$this->assertEquals(11,$queue->max());
$this->assertNull($queue->peek());
}
/**
Expand Down
11 changes: 1 addition & 10 deletions tests/data-structures/StackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,13 @@ public function test09() {
$this->assertEquals(0,$stack->size());
$this->assertEquals(1,$stack->max());
}
/**
* @test
*/
public function test10() {
$stack = new Stack('Random Str');
$this->assertEquals(0,$stack->size());
$this->assertEquals(-1,$stack->max());
$this->assertNull($stack->peek());
}
/**
* @test
*/
public function test11() {
$stack = new Stack('11');
$this->assertEquals(0,$stack->size());
$this->assertEquals(-1,$stack->max());
$this->assertEquals(11,$stack->max());
$this->assertNull($stack->peek());
}
/**
Expand Down
26 changes: 6 additions & 20 deletions webfiori/collections/AbstractCollection.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<?php
/*
* The MIT License
*
* Copyright (c) 2020 Ibrahim BinAlshikh, WebFiori Collections.
/**
* This file is licensed under MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Copyright (c) 2020 Ibrahim BinAlshikh
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace webfiori\collections;

Expand Down Expand Up @@ -66,7 +52,7 @@ public function __toString() {
* @param mixed $el The element that will be added. It can be of any type. Note
* that the value is passed by reference.
*
* @return boolean The method should be implemented in a way that it returns
* @return bool The method should be implemented in a way that it returns
* true if the element is added and returns false otherwise.
*
* @since 1.0
Expand Down
24 changes: 5 additions & 19 deletions webfiori/collections/Comparable.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<?php
/*
* The MIT License
*
* Copyright (c) 2020 Ibrahim BinAlshikh, WebFiori Collections.
/**
* This file is licensed under MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Copyright (c) 2020 Ibrahim BinAlshikh
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace webfiori\collections;

Expand Down
60 changes: 23 additions & 37 deletions webfiori/collections/LinkedList.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<?php
/*
* The MIT License
*
* Copyright (c) 2020 Ibrahim BinAlshikh, WebFiori Collections.
/**
* This file is licensed under MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Copyright (c) 2020 Ibrahim BinAlshikh
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace webfiori\collections;
Expand Down Expand Up @@ -334,7 +320,7 @@ public function add(&$el) : bool {
return false;
}
/**
* Removes all of the elements from the list.
* Removes all the elements from the list.
*
* @since 1.1
*/
Expand All @@ -351,7 +337,7 @@ public function clear() {
*
* @param mixed $el The element that will be checked.
*
* @return boolean true if the element is on the list. Other than that,
* @return bool true if the element is on the list. Other than that,
* the method will return false.
*
* @since 1.0
Expand All @@ -364,8 +350,8 @@ public function contains(&$el) : bool {
} else {
$node = $this->head;

while ($node != null) {
if ($node != null && $node->data() === $el) {
while ($node !== null) {
if ($node !== null && $node->data() === $el) {
return true;
}
$node = $node->next();
Expand All @@ -392,7 +378,7 @@ public function countElement(&$el) : int {
} else {
$node = $this->head;

while ($node != null) {
while ($node !== null) {
if ($node->data() === $el) {
$count++;
}
Expand Down Expand Up @@ -444,7 +430,7 @@ public function indexOf($el) : int {
$tmpIndex = 0;
$node = $this->head;

while ($node->next() != null) {
while ($node->next() !== null) {
if ($node->data() === $el) {
return $tmpIndex;
}
Expand Down Expand Up @@ -479,7 +465,7 @@ public function indexOf($el) : int {
*
* @param int $position The index at which the element will be inserted in.
*
* @return boolean If the element is inserted, the method will return true.
* @return bool If the element is inserted, the method will return true.
* If not, the method will return false.
*/
public function insert(&$el,$position) : bool {
Expand Down Expand Up @@ -532,12 +518,12 @@ public function insert(&$el,$position) : bool {
* <li>Objects that implements the interface 'webfiori\collections\Comparable'</li>
* </ul>
*
* @param boolean $ascending If set to true, list elements
* @param bool $ascending If set to true, list elements
* will be sorted in ascending order (From lower to higher). Else,
* they will be sorted in descending order (From higher to lower). Default is
* true.
*
* @return boolean The method will return true if list
* @return bool The method will return true if list
* elements have been sorted. The only cases that the method
* will return false is when the list has an object which does
* not implement the interface Comparable or it has a mix of objects
Expand All @@ -546,7 +532,7 @@ public function insert(&$el,$position) : bool {
*
* @since 1.3
*/
public function insertionSort($ascending = true) {
public function insertionSort(bool $ascending = true) : bool {
$array = $this->toArray();
$count = count($array);
$hasObject = false;
Expand Down Expand Up @@ -672,7 +658,7 @@ public function next() {
*
* @param mixed $newEl The element that will replace the old one.
*
* @return boolean The method will return true if replaced.
* @return bool The method will return true if replaced.
* if the element is not replaced, the method will return false.
*
* @since 1.2
Expand All @@ -687,7 +673,7 @@ public function replace(&$oldEl,&$newEl) : bool {
} else {
$nextNode = &$this->head->next();

while ($nextNode != null) {
while ($nextNode !== null) {
$data = &$nextNode->data();

if ($data === $oldEl) {
Expand Down Expand Up @@ -739,7 +725,7 @@ public function toArray() : array {
} else if ($this->size() != 0) {
$node = $this->head;

while ($node->next() != null) {
while ($node->next() !== null) {
$array[] = $node->data();
$node = $node->next();
}
Expand All @@ -755,7 +741,7 @@ public function toArray() : array {
* The developer should not call it manually unless he knows what he
* is doing.
*
* @return boolean If there is a next element, the method
* @return bool If there is a next element, the method
* will return true. False otherwise.
*
* @since 1.4.3
Expand All @@ -767,7 +753,7 @@ private function &_removeElementHelper(&$val) {
$node = $this->head;
$nextNode = &$this->head->next();

while ($nextNode != null) {
while ($nextNode !== null) {
$data = &$nextNode->data();

if ($data === $val) {
Expand All @@ -788,7 +774,7 @@ private function _insertMiddle(&$el,&$position) {
$nextToCurrent = $currentNode->next();
$retVal = false;

while ($currentNode != null) {
while ($currentNode !== null) {
if ($pointer == $position) {
$newNode = new Node($el,$nextToCurrent);
$currentNode->setNext($newNode);
Expand Down Expand Up @@ -831,11 +817,11 @@ private function _reduceSize() {
/**
* Checks if the list can hold more elements or not.
*
* @return boolean true if the list can hold more elements.
* @return bool true if the list can hold more elements.
*
* @since 1.4.1
*/
private function validateSize() {
private function validateSize() : bool {
$max = $this->max();

if ($max == -1) {
Expand Down
25 changes: 6 additions & 19 deletions webfiori/collections/Node.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
<?php
/*
* The MIT License
*
* Copyright (c) 2020 Ibrahim BinAlshikh, WebFiori Collections.
/**
* This file is licensed under MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Copyright (c) 2020 Ibrahim BinAlshikh
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* For more information on the license, please visit:
* https://github.com/WebFiori/.github/blob/main/LICENSE
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


namespace webfiori\collections;

/**
Expand Down
Loading

0 comments on commit f2ba3f6

Please sign in to comment.