Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the documentation. #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ interface Collection extends \Traversable, \Countable, \JsonSerializable
/**
* Removes all values from the collection.
*/
function clear();
public function clear();

/**
* Returns the size of the collection.
*
* @return int
*/
function count(): int;
public function count(): int;

/**
* Returns a shallow copy of the collection.
*
* @return Collection a copy of the collection.
*/
function copy(): Collection;
public function copy(): Collection;

/**
* Returns whether the collection is empty.
Expand All @@ -37,7 +37,7 @@ function copy(): Collection;
*
* @return bool
*/
function isEmpty(): bool;
public function isEmpty(): bool;

/**
* Returns an array representation of the collection.
Expand All @@ -48,5 +48,5 @@ function isEmpty(): bool;
*
* @return array
*/
function toArray(): array;
public function toArray(): array;
}
6 changes: 3 additions & 3 deletions src/Hashable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ interface Hashable
*
* @return mixed
*/
function hash();
public function hash();
hopeseekr marked this conversation as resolved.
Show resolved Hide resolved

/**
* Determines if two objects should be considered equal. Both objects will
* be instances of the same class but may not be the same instance.
*
* @param $obj An instance of the same class to compare to.
* @param $obj self An instance of the same class to compare to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct - it could be anything at all. See php-ds/ext-ds#140

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, I am so confused.

I go down the same path as many of the commenters in that thread... First, I thought self is correct, then object, then, certainly ?object, but then you're all saying that strings, ints, floats, what else? resources, arrays and callables should also be accepted?? I'm assuming Exceptions, too? lol.

I can understand ?object, but just passing anything seems like a clear design flaw to me. But I'm very very unfamiliar w/ this project. I just wanted to do some good will and that conversation happened after I did the bulk of the changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, I am so confused.

😁 no problem, I was for a while too. The thing here is that equals is used to determine equality when an object is used as a key in a hash-based structure. ie. Map will internally call an object's equals method when looking up that object in the hash table.

The issue is that you can of course call equals directly, ie. $map->equals(null). You can pass anything you want to that method, which means it is responsible for checking that the given arg is an instance of the same class etc. The doc comment should reflect that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the correct type, it should precede the parameter name, not come after it.

*
* @return bool
*/
function equals($obj): bool;
public function equals($obj): bool;
}
8 changes: 5 additions & 3 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ public function reduce(callable $callback, $initial = null)
/**
* Completely removes a pair from the internal array by position. It is
* important to remove it from the array and not just use 'unset'.
*
* @param int $position
*
* @return mixed
*/
private function delete(int $position)
{
Expand Down Expand Up @@ -434,9 +438,7 @@ public function remove($key, $default = null)
}

/**
* Returns a reversed copy of the map.
*
* @return Map
* Sorts the map into the reversed order.
*/
public function reverse()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public function jsonSerialize()

/**
* Returns a string representation of the pair.
*
* @return string a string representation of the pair.
*/
public function __toString()
public function __toString(): string
{
return 'object(' . get_class($this) . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion src/PriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function clear()
/**
* @inheritDoc
*/
public function copy(): \Ds\Collection
public function copy(): Collection
{
$copy = new PriorityQueue();

Expand Down
4 changes: 2 additions & 2 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function clear()
/**
* @inheritDoc
*/
public function copy(): \Ds\Collection
public function copy(): Collection
{
return new self($this->deque);
}
Expand All @@ -81,7 +81,7 @@ public function count(): int
/**
* Returns the value at the front of the queue without removing it.
*
* @return
* @return mixed
*/
public function peek()
{
Expand Down
54 changes: 27 additions & 27 deletions src/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ interface Sequence extends Collection
* allocated. Capacity will stay the same if this value
* is less than or equal to the current capacity.
*/
function allocate(int $capacity);
public function allocate(int $capacity);

/**
* Updates every value in the sequence by applying a callback, using the
* return value as the new value.
*
* @param callable $callback Accepts the value, returns the new value.
*/
function apply(callable $callback);
public function apply(callable $callback);

/**
* Returns the current capacity of the sequence.
*
* @return int
*/
function capacity(): int;
public function capacity(): int;

/**
* Determines whether the sequence contains all of zero or more values.
Expand All @@ -45,7 +45,7 @@ function capacity(): int;
* @return bool true if at least one value was provided and the sequence
* contains all given values, false otherwise.
*/
function contains(...$values): bool;
public function contains(...$values): bool;

/**
* Returns a new sequence containing only the values for which a callback
Expand All @@ -57,7 +57,7 @@ function contains(...$values): bool;
*
* @return Sequence
*/
function filter(callable $callback = null): Sequence;
public function filter(callable $callback = null): Sequence;

/**
* Returns the index of a given value, or false if it could not be found.
Expand All @@ -66,7 +66,7 @@ function filter(callable $callback = null): Sequence;
*
* @return int|bool
*/
function find($value);
public function find($value);

/**
* Returns the first value in the sequence.
Expand All @@ -75,7 +75,7 @@ function find($value);
*
* @throws \UnderflowException if the sequence is empty.
*/
function first();
public function first();

/**
* Returns the value at a given index (position) in the sequence.
Expand All @@ -86,7 +86,7 @@ function first();
*
* @throws \OutOfRangeException if the index is not in the range [0, size-1]
*/
function get(int $index);
public function get(int $index);

/**
* Inserts zero or more values at a given index.
Expand All @@ -99,7 +99,7 @@ function get(int $index);
*
* @throws \OutOfRangeException if the index is not in the range [0, n]
*/
function insert(int $index, ...$values);
public function insert(int $index, ...$values);

/**
* Joins all values of the sequence into a string, adding an optional 'glue'
Expand All @@ -109,7 +109,7 @@ function insert(int $index, ...$values);
*
* @return string
*/
function join(string $glue = null): string;
public function join(string $glue = null): string;

/**
* Returns the last value in the sequence.
Expand All @@ -118,7 +118,7 @@ function join(string $glue = null): string;
*
* @throws \UnderflowException if the sequence is empty.
*/
function last();
public function last();

/**
* Returns a new sequence using the results of applying a callback to each
Expand All @@ -128,7 +128,7 @@ function last();
*
* @return Sequence
*/
function map(callable $callback): Sequence;
public function map(callable $callback): Sequence;

/**
* Returns the result of adding all given values to the sequence.
Expand All @@ -137,7 +137,7 @@ function map(callable $callback): Sequence;
*
* @return Sequence
*/
function merge($values): Sequence;
public function merge($values): Sequence;

/**
* Removes the last value in the sequence, and returns it.
Expand All @@ -146,14 +146,14 @@ function merge($values): Sequence;
*
* @throws \UnderflowException if the sequence is empty.
*/
function pop();
public function pop();

/**
* Adds zero or more values to the end of the sequence.
*
* @param mixed ...$values
*/
function push(...$values);
public function push(...$values);

/**
* Iteratively reduces the sequence to a single value using a callback.
Expand All @@ -166,7 +166,7 @@ function push(...$values);
* @return mixed The carry value of the final iteration, or the initial
* value if the sequence was empty.
*/
function reduce(callable $callback, $initial = null);
public function reduce(callable $callback, $initial = null);

/**
* Removes and returns the value at a given index in the sequence.
Expand All @@ -177,19 +177,19 @@ function reduce(callable $callback, $initial = null);
*
* @throws \OutOfRangeException if the index is not in the range [0, size-1]
*/
function remove(int $index);
public function remove(int $index);

/**
* Reverses the sequence in-place.
*/
function reverse();
public function reverse();

/**
* Returns a reversed copy of the sequence.
*
* @return Sequence
*/
function reversed();
public function reversed();

/**
* Rotates the sequence by a given number of rotations, which is equivalent
Expand All @@ -198,7 +198,7 @@ function reversed();
*
* @param int $rotations The number of rotations (can be negative).
*/
function rotate(int $rotations);
public function rotate(int $rotations);

/**
* Replaces the value at a given index in the sequence with a new value.
Expand All @@ -208,7 +208,7 @@ function rotate(int $rotations);
*
* @throws \OutOfRangeException if the index is not in the range [0, size-1]
*/
function set(int $index, $value);
public function set(int $index, $value);

/**
* Removes and returns the first value in the sequence.
Expand All @@ -217,7 +217,7 @@ function set(int $index, $value);
*
* @throws \UnderflowException if the sequence was empty.
*/
function shift();
public function shift();

/**
* Returns a sub-sequence of a given length starting at a specified index.
Expand All @@ -240,15 +240,15 @@ function shift();
*
* @return Sequence
*/
function slice(int $index, int $length = null): Sequence;
public function slice(int $index, int $length = null): Sequence;

/**
* Sorts the sequence in-place, based on an optional callable comparator.
*
* @param callable|null $comparator Accepts two values to be compared.
* Should return the result of a <=> b.
*/
function sort(callable $comparator = null);
public function sort(callable $comparator = null);

/**
* Returns a sorted copy of the sequence, based on an optional callable
Expand All @@ -259,19 +259,19 @@ function sort(callable $comparator = null);
*
* @return Sequence
*/
function sorted(callable $comparator = null): Sequence;
public function sorted(callable $comparator = null): Sequence;

/**
* Returns the sum of all values in the sequence.
*
* @return int|float The sum of all the values in the sequence.
*/
function sum();
public function sum();

/**
* Adds zero or more values to the front of the sequence.
*
* @param mixed ...$values
*/
function unshift(...$values);
public function unshift(...$values);
}
2 changes: 1 addition & 1 deletion src/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function contains(...$values): bool
/**
* @inheritDoc
*/
public function copy(): \Ds\Collection
public function copy(): Collection
{
return new self($this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/Capacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function allocate(int $capacity)
}

/**
* @return the structures growth factor.
* @return float the structures growth factor.
*/
protected function getGrowthFactor(): float
{
Expand Down Expand Up @@ -92,15 +92,15 @@ protected function decreaseCapacity()
}

/**
* @return whether capacity should be increased.
* @return bool whether capacity should be increased.
*/
protected function shouldDecreaseCapacity(): bool
{
return count($this) <= $this->capacity * $this->getTruncateThreshold();
}

/**
* @return whether capacity should be increased.
* @return bool whether capacity should be increased.
*/
protected function shouldIncreaseCapacity(): bool
{
Expand Down
Loading