Skip to content

Commit f8b4682

Browse files
committed
normalize the semantic syntax of methods and interface names
1 parent 2e47a76 commit f8b4682

File tree

14 files changed

+380
-158
lines changed

14 files changed

+380
-158
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Behavioral;
6+
7+
/**
8+
* Interface Comparable.
9+
*
10+
* Defines the contract for objects that can be compared.
11+
*
12+
* @package KaririCode\Contract\Behavioral
13+
* @category Interfaces
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
* @see https://kariricode.org/
17+
*/
18+
interface Comparable
19+
{
20+
/**
21+
* Compares this object with the specified object for order.
22+
*
23+
* @param mixed $other The object to compare with
24+
* @return int A negative integer, zero, or a positive integer as this object
25+
* is less than, equal to, or greater than the specified object.
26+
*/
27+
public function compareTo(mixed $other): int;
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Behavioral;
6+
7+
/**
8+
* Interface Countable.
9+
*
10+
* Defines the contract for counting elements.
11+
*
12+
* @package KaririCode\Contract\Behavioral
13+
* @category Interfaces
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
* @see https://kariricode.org/
17+
*/
18+
interface Countable
19+
{
20+
/**
21+
* Counts the elements.
22+
*
23+
* @return int The number of elements
24+
*/
25+
public function count(): int;
26+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Behavioral;
6+
7+
/**
8+
* Interface Indexable.
9+
*
10+
* Defines the contract for indexed access to elements.
11+
*
12+
* @package KaririCode\Contract\Behavioral
13+
* @category Interfaces
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
* @see https://kariricode.org/
17+
*/
18+
interface Indexable
19+
{
20+
/**
21+
* Checks if an element exists at the given index.
22+
*
23+
* @param int $index The index to check
24+
* @return bool True if the index exists, false otherwise
25+
*/
26+
public function contains(int $index): bool;
27+
28+
/**
29+
* Gets the element at the specified index.
30+
*
31+
* @param int $index The index of the element
32+
* @return mixed The element at the specified index
33+
*/
34+
public function get(int $index): mixed;
35+
36+
/**
37+
* Sets the element at the specified index.
38+
*
39+
* @param int $index The index at which to set the element
40+
* @param mixed $element The element to set
41+
* @return void
42+
*/
43+
public function set(int $index, mixed $element): void;
44+
45+
/**
46+
* Removes the element at the specified index.
47+
*
48+
* @param int $index The index of the element to remove
49+
* @return bool True if the element was removed, false otherwise
50+
*/
51+
public function remove(int $index): bool;
52+
}

src/DataStructure/IterableCollection.php renamed to src/DataStructure/Behavioral/IterableCollection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44

55
namespace KaririCode\Contract\DataStructure;
66

7+
use KaririCode\Contract\Behavioral\Iterator;
8+
79
/**
810
* Interface IterableCollection.
911
*
1012
* Provides the ability to iterate over a collection.
1113
*
1214
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @author Walmir Silva <walmir.silva@kariricode.org>
1316
* @license MIT
1417
*
1518
* @see https://kariricode.org/
1619
*/
17-
interface IterableCollection extends \IteratorAggregate
20+
interface IterableCollection extends \Traversable
1821
{
1922
/**
2023
* Gets an iterator for the collection.
2124
*
22-
* @return \Traversable an iterator for the collection
25+
* @return Iterator an iterator for the collection
2326
*/
24-
public function getIterator(): \Traversable;
27+
public function getIterator(): Iterator;
2528
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Behavioral;
6+
7+
/**
8+
* Interface Iterator.
9+
*
10+
* Defines the contract for iterating over a collection of elements.
11+
*
12+
* @package KaririCode\Contract\Behavioral
13+
* @category Interfaces
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
* @see https://kariricode.org/
17+
*/
18+
interface Iterator
19+
{
20+
/**
21+
* Returns the next element in the iteration.
22+
*
23+
* @return mixed The next element
24+
*/
25+
public function next(): mixed;
26+
27+
/**
28+
* Checks if the iteration has more elements.
29+
*
30+
* @return bool True if the iteration has more elements, false otherwise
31+
*/
32+
public function hasNext(): bool;
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Behavioral;
6+
7+
/**
8+
* Interface Sortable.
9+
*
10+
* Defines the contract for classes that can be sorted.
11+
* Classes implementing this interface should provide an implementation
12+
* for the sort method to allow sorting of their elements.
13+
*
14+
* @package KaririCode\Contract\Behavioral
15+
* @category Interfaces
16+
* @author Walmir Silva <walmir.silva@kariricode.org>
17+
* @license MIT
18+
* @see https://kariricode.org/
19+
*/
20+
interface Sortable
21+
{
22+
/**
23+
* Sorts the elements of the class.
24+
*
25+
* @return void
26+
*/
27+
public function sort(): void;
28+
}

src/DataStructure/CollectionList.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/DataStructure/Heap.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,54 @@
77
/**
88
* Interface Heap.
99
*
10-
* Defines the contract for a heap data structure.
10+
* Defines the contract for heap data structures.
11+
* A heap is a specialized tree-based data structure that satisfies the heap property.
1112
*
13+
*
14+
* @package KaririCode\Contract\DataStructure
15+
* @category Interfaces
1216
* @author Walmir Silva <walmir.silva@kariricode.org>
1317
* @license MIT
14-
*
15-
* @see https://kariricode.org/
18+
* @see https://kariricode.org/
1619
*/
17-
interface Heap extends \Countable
20+
interface Heap
1821
{
1922
/**
20-
* Inserts a value into the heap.
23+
* Adds an element to the heap.
2124
*
22-
* @param mixed $value the value to insert
25+
* @param mixed $element The element to add.
26+
* @return void
2327
*/
24-
public function insert(mixed $value): void;
28+
public function add(mixed $element): void;
2529

2630
/**
27-
* Extracts the top value from the heap.
31+
* Inserts an element into the heap at the specified position.
2832
*
29-
* @return mixed the extracted value
33+
* @param int $index The index at which to insert the element.
34+
* @param mixed $element The element to insert.
35+
* @return void
3036
*/
31-
public function extract(): mixed;
37+
public function insert(int $index, mixed $element): void;
3238

3339
/**
34-
* Peeks at the top value of the heap without extracting it.
40+
* Removes and returns the root element from the heap.
3541
*
36-
* @return mixed the top value
42+
* @return mixed The removed root element.
3743
*/
38-
public function peek(): mixed;
44+
public function poll(): mixed;
45+
46+
/**
47+
* Removes a specific element from the heap.
48+
*
49+
* @param mixed $element The element to remove.
50+
* @return bool True if the element was removed, false otherwise.
51+
*/
52+
public function remove(mixed $element): bool;
3953

4054
/**
41-
* Checks if the heap is empty.
55+
* Returns the root element without removing it.
4256
*
43-
* @return bool true if the heap is empty, false otherwise
57+
* @return mixed The root element.
4458
*/
45-
public function isEmpty(): bool;
59+
public function peek(): mixed;
4660
}

src/DataStructure/Map.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,38 @@
77
/**
88
* Interface Map.
99
*
10-
* Defines the contract for a map data structure.
10+
* Defines the contract for map data structures, which store key-value pairs.
1111
*
12+
* @package KaririCode\Contract\DataStructure
13+
* @category Interfaces
1214
* @author Walmir Silva <walmir.silva@kariricode.org>
1315
* @license MIT
14-
*
15-
* @see https://kariricode.org/
16+
* @see https://kariricode.org/
1617
*/
17-
interface Map extends \Countable, \ArrayAccess
18+
interface Map
1819
{
1920
/**
2021
* Puts a key-value pair into the map.
2122
*
22-
* @param mixed $key the key
23-
* @param mixed $value the value
23+
* @param mixed $key The key.
24+
* @param mixed $value The value.
25+
* @return void
2426
*/
2527
public function put(mixed $key, mixed $value): void;
2628

2729
/**
2830
* Gets a value by its key.
2931
*
30-
* @param mixed $key the key
31-
*
32-
* @return mixed the value associated with the key
32+
* @param mixed $key The key.
33+
* @return mixed The value associated with the key.
3334
*/
3435
public function get(mixed $key): mixed;
3536

3637
/**
3738
* Removes a key-value pair from the map.
3839
*
39-
* @param mixed $key the key to remove
40-
*
41-
* @return bool true if the pair was successfully removed, false otherwise
40+
* @param mixed $key The key.
41+
* @return bool True if the key-value pair was removed, false otherwise.
4242
*/
4343
public function remove(mixed $key): bool;
44-
45-
/**
46-
* Checks if the map contains a specific key.
47-
*
48-
* @param mixed $key the key to check
49-
*
50-
* @return bool true if the key exists, false otherwise
51-
*/
52-
public function containsKey(mixed $key): bool;
53-
54-
/**
55-
* Gets all keys in the map.
56-
*
57-
* @return array an array of all keys
58-
*/
59-
public function keys(): array;
60-
61-
/**
62-
* Gets all values in the map.
63-
*
64-
* @return array an array of all values
65-
*/
66-
public function values(): array;
6744
}

0 commit comments

Comments
 (0)