From 72c6b115138c04925e43b06f3e2c9fc9c1506cf7 Mon Sep 17 00:00:00 2001 From: Max Almonte Date: Thu, 4 Oct 2018 11:50:32 -0400 Subject: [PATCH] Added documentation --- .gitignore | 3 +- README.md | 12 +- composer.json | 3 +- composer.lock | 177 +++++++++++- docs/PHPCollections-Collections-ArrayList.md | 189 +++++++++++++ ...PCollections-Collections-BaseCollection.md | 81 ++++++ docs/PHPCollections-Collections-Dictionary.md | 253 ++++++++++++++++++ .../PHPCollections-Collections-GenericList.md | 244 +++++++++++++++++ docs/PHPCollections-Collections-Pair.md | 81 ++++++ docs/PHPCollections-Collections-Stack.md | 112 ++++++++ docs/PHPCollections-DataHolder.md | 106 ++++++++ ...ns-Exceptions-InvalidOperationException.md | 21 ++ ...lections-Interfaces-CollectionInterface.md | 48 ++++ ...lections-Interfaces-DictionaryInterface.md | 47 ++++ ...ollections-Interfaces-SortableInterface.md | 18 ++ docs/README.md | 19 ++ src/Collections/ArrayList.php | 2 +- src/Collections/BaseCollection.php | 9 +- src/Collections/GenericList.php | 15 +- src/utils.php | 3 +- 20 files changed, 1418 insertions(+), 25 deletions(-) create mode 100644 docs/PHPCollections-Collections-ArrayList.md create mode 100644 docs/PHPCollections-Collections-BaseCollection.md create mode 100644 docs/PHPCollections-Collections-Dictionary.md create mode 100644 docs/PHPCollections-Collections-GenericList.md create mode 100644 docs/PHPCollections-Collections-Pair.md create mode 100644 docs/PHPCollections-Collections-Stack.md create mode 100644 docs/PHPCollections-DataHolder.md create mode 100644 docs/PHPCollections-Exceptions-InvalidOperationException.md create mode 100644 docs/PHPCollections-Interfaces-CollectionInterface.md create mode 100644 docs/PHPCollections-Interfaces-DictionaryInterface.md create mode 100644 docs/PHPCollections-Interfaces-SortableInterface.md create mode 100644 docs/README.md diff --git a/.gitignore b/.gitignore index 211663a..8b8e5ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -.vscode/ \ No newline at end of file +.vscode/ +docs/structure.xml \ No newline at end of file diff --git a/README.md b/README.md index e4daf14..a54de1e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ PHPCollections is a set of data structures that try to make your life easier when you're working with PHP and large sets of data. Inspired by languages like Java or C#, PHPCollections offers data structures like List, Map, Stack and more, check it out! -> **Note**: This package is under actual development, so maybe all the possible features cannot be available at the time you install it. - ## Requirements ``` @@ -13,7 +11,7 @@ PHP >= 7.1 ## Installation ``` -composer require "maxalmonte14/phpcollections dev-master" +composer require "maxalmonte14/phpcollections" ``` ## Examples @@ -61,4 +59,10 @@ $posts = new ArrayList(); $posts->add(new Post(1, 'PHP 7.2 release notes')); $posts->add(new Post(2, 'New Laravel 5.5 LTS make:factory command')); $posts->add(5); // Everything is fine, I need this 5 anyway -``` \ No newline at end of file +``` + +## Features + +- Different types of collections like Dictionariy, Stack and GenericList. +- Simple API. +- Lightweight, no extra packages needed. \ No newline at end of file diff --git a/composer.json b/composer.json index 207ba9d..f830ee3 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ ] }, "require-dev": { - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^6.4", + "evert/phpdoc-md": "^0.2.0" } } diff --git a/composer.lock b/composer.lock index cf25e20..f4a671d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "415b98390a8403871d43872566603ed6", + "content-hash": "f5b9153c6a8b3030bd4c69bedea865d1", "packages": [], "packages-dev": [ { @@ -61,6 +61,58 @@ ], "time": "2015-06-14T21:17:01+00:00" }, + { + "name": "evert/phpdoc-md", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/evert/phpdoc-md.git", + "reference": "afa89bd55de9d27abcfebaf3a3c0097f7590dd11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/evert/phpdoc-md/zipball/afa89bd55de9d27abcfebaf3a3c0097f7590dd11", + "reference": "afa89bd55de9d27abcfebaf3a3c0097f7590dd11", + "shasum": "" + }, + "require": { + "php": ">=5.3.1", + "twig/twig": "~1.2|2.0" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "~2.8.0", + "sabre/cs": "~0.0.5" + }, + "bin": [ + "bin/phpdocmd" + ], + "type": "library", + "autoload": { + "psr-4": { + "PHPDocMD\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "evert@rooftopsolutions.nl", + "homepage": "http://www.rooftopsolutions.nl/", + "role": "Developer" + } + ], + "description": "PHP documentation generator, with markdown output", + "homepage": "https://github.com/evert/phpdoc-md", + "keywords": [ + "markdown", + "php", + "phpdoc" + ], + "time": "2016-02-11T22:08:37+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1374,6 +1426,65 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.9.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-08-06T14:22:27+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.0", @@ -1414,6 +1525,68 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "time": "2017-04-07T12:08:54+00:00" }, + { + "name": "twig/twig", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "2a86dde1288d7270169083d0e078dc7ebe0f48b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/2a86dde1288d7270169083d0e078dc7ebe0f48b6", + "reference": "2a86dde1288d7270169083d0e078dc7ebe0f48b6", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/debug": "~2.7", + "symfony/phpunit-bridge": "~3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2017-01-05T17:12:02+00:00" + }, { "name": "webmozart/assert", "version": "1.3.0", @@ -1471,7 +1644,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.0" + "php": ">=7.1" }, "platform-dev": [] } diff --git a/docs/PHPCollections-Collections-ArrayList.md b/docs/PHPCollections-Collections-ArrayList.md new file mode 100644 index 0000000..088f656 --- /dev/null +++ b/docs/PHPCollections-Collections-ArrayList.md @@ -0,0 +1,189 @@ +PHPCollections\Collections\ArrayList +=============== + +A list of values of any type. + +* Class name: ArrayList +* Namespace: PHPCollections\Collections +* This class implements: CollectionInterface, IterableInterface, SortableInterface + +Methods +------- + +### add + + void PHPCollections\Collections\ArrayList::add(mixed $value) + +Adds a new element to the collection. + +* Visibility: **public** + +#### Arguments +* $value **mixed** + +### contains + + boolean PHPCollections\Collections\ArrayList::contains(mixed $needle) + + Checks if the collection + contains a given value. + +* Visibility: **public** + +#### Arguments +* $needle **mixed** + +### filter + + ?ArrayList PHPCollections\Collections\ArrayList::filter(callable $callback) + +Returns all the coincidences found +for the given callback or null. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### find + + ?ArrayList PHPCollections\Collections\ArrayList::find(callable $callback, boolean $shouldStop = false) + + Searches for one or more elements + in the collection. + +* Visibility: **public** + +#### Arguments +* $callback **callable** +* $shouldStop **boolean** + +### first + + mixed PHPCollections\Collections\ArrayList::first() + +Gets the first element of the collection. + +* Visibility: **public** + +#### Throws +**\OutOfRangeException** + +### forEach + + void PHPCollections\Collections\ArrayList::forEach(callable $callback) + +Iterates over every element of the collection. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### get + + mixed PHPCollections\Collections\ArrayList::get(integer $offset) + +Gets the element specified +at the given index. + +* Visibility: **public** + +#### Arguments +* $offset **integer** + +### last + + mixed PHPCollections\Collections\ArrayList::last() + +Gets the last element of the collection. + +* Visibility: **public** + +### map + + ?ArrayList PHPCollections\Collections\ArrayList::map(callable $callback) + +Updates elements in the collection by +applying a given callback function. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### merge + + ArrayList PHPCollections\Collections\ArrayList::merge(array $data) + +Merges new data with the actual +collection and returns a new one. + +* Visibility: **public** + +#### Arguments +* $data **array** + +### rand + + mixed PHPCollections\Collections\ArrayList::rand() + +Returns a random element of +the collection. + +* Visibility: **public** + +#### Throws +* **\PHPCollections\Exceptions\InvalidOperationException** + +### remove + + void PHPCollections\Collections\ArrayList::remove(integer $offset) + +Removes an item from the collection +and repopulates the data array. + +* Visibility: **public** + +#### Arguments +* $offset **integer** + +#### Throws +* **\OutOfRangeException** + +### reverse + + ArrayList PHPCollections\Collections\ArrayList::reverse() + +Returns a new collection with the +reversed values. + +* Visibility: **public** + +#### Throws +* **\PHPCollections\Exceptions\InvalidOperationException** + +### sort + + bool PHPCollections\Collections\ArrayList::sort(callable $callback) + +Sorts collection's data by values +applying a given callback. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### update + + bool PHPCollections\Collections\ArrayList::update(integer $index, mixed $value) + + Updates the value of the element + at the given index. + +* Visibility: **public** + +#### Arguments +* $index **integer** +* $value **mixed** diff --git a/docs/PHPCollections-Collections-BaseCollection.md b/docs/PHPCollections-Collections-BaseCollection.md new file mode 100644 index 0000000..60f74c0 --- /dev/null +++ b/docs/PHPCollections-Collections-BaseCollection.md @@ -0,0 +1,81 @@ +PHPCollections\Collections\BaseCollection +=============== + +The base class for countable and +JSON serializable collections. + +* Class name: BaseCollection +* Namespace: PHPCollections\Collections +* This is an **abstract** class +* This class implements: Countable, JsonSerializable + +Properties +---------- + +### $dataHolder + + protected \PHPCollections\DataHolder $dataHolder + +The data container. + +* Visibility: **protected** + +Methods +------- + +### __construct + + void PHPCollections\Collections\BaseCollection::__construct(array $data) + +Initializes the dataHolder property. + +* Visibility: **public** + +#### Arguments +* $data **array** + +### clear + + void PHPCollections\Collections\BaseCollection::clear() + +Reinitializes the dataHolder property. + +* Visibility: **public** + +### count + + integer PHPCollections\Collections\BaseCollection::count() + +Returns the length of the collection. + +* Visibility: **public** + +### exists + + boolean PHPCollections\Collections\BaseCollection::exists(mixed $offset) + +Checks if the given index +exists in the collection. + +* Visibility: **public** + +#### Arguments +* $offset **mixed** + +### jsonSerialize + + array PHPCollections\Collections\BaseCollection::jsonSerialize() + +Defines the behavior of the collection +when json_encode is called. + +* Visibility: **public** + +### toArray + + array PHPCollections\Collections\BaseCollection::toArray() + +Returns a plain array with +your dictionary data. + +* Visibility: **public** diff --git a/docs/PHPCollections-Collections-Dictionary.md b/docs/PHPCollections-Collections-Dictionary.md new file mode 100644 index 0000000..192502d --- /dev/null +++ b/docs/PHPCollections-Collections-Dictionary.md @@ -0,0 +1,253 @@ +PHPCollections\Collections\Dictionary +=============== + +A Pair object collection +represented by a generic +type key and value. + +* Class name: Dictionary +* Namespace: PHPCollections\Collections +* This class extends: BaseCollection +* This class implements: DictionaryInterface + +Properties +---------- + +### $keyType + + private mixed $keyType + +The type of the keys +for this dictionary. + +* Visibility: **private** + +### $valueType + + private mixed $valueType + +The type of the values +for this dictionary. + +* Visibility: **private** + +Methods +------- + +### __construct + + void PHPCollections\Collections\Dictionary::__construct(mixed $keyType, mixed $valueType, array $data = []) + +Initializes the class properties. + +* Visibility: **public** + +#### Arguments +* $keyType **mixed** +* $valueType **mixed** +* $data **array** + +### add + + void PHPCollections\Collections\Dictionary::add(mixed $key, mixed $value) + +Adds a new value to the dictionary. + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** + +### checkType + + void PHPCollections\Collections\Dictionary::checkType(mixed $values) + +Determines if the passed data is +of the type specified in the keyType/valueType +attribute, if not throws and InvalidArgumentException. + +* Visibility: **private** + +#### Arguments +* $values **mixed** + +#### Throws +* **\InvalidArgumentException** + +### filter + + ?Dictionary PHPCollections\Collections\Dictionary::filter(callable $callback) + +Filters the collection applying +a given callback. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### find + + ?mixed PHPCollections\Collections\Dictionary::find(callable $callback) + +Finds an element based on a given callback. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### first + + mixed PHPCollections\Collections\Dictionary::first() + +Returns the first element in the collection. + +* Visibility: **public** + +#### Throws +**\PHPCollections\Exceptions\InvalidOperationException** + +### forEach + + void PHPCollections\Collections\Dictionary::forEach(callable $callback) + +Iterates over every element of the collection. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### get + + ?mixed PHPCollections\Collections\Dictionary::get(mixed $key) + +Returns the value for the specified +key or null if it's not defined. + +* Visibility: **public** + +#### Arguments +* $key **mixed** + +### getKeyType + + mixed PHPCollections\Collections\Dictionary::getKeyType() + +Returns the key type for this collection. + +* Visibility: **public** + +### getValueType + + mixed PHPCollections\Collections\Dictionary::getValueType() + +Returns the key value for this collection. + +* Visibility: **public** + +### initializePairs + + void PHPCollections\Collections\Dictionary::initializePairs(array $data) + +Populates the container with Pair objects. + +* Visibility: **private** + +#### Arguments +* $data **array** + +### last + + mixed PHPCollections\Collections\Dictionary::last() + +Returns the last element of +the collection. + +* Visibility: **public** + +#### Throws +* **\PHPCollections\Exceptions\InvalidOperationException** + +### map + + ?Dictionary PHPCollections\Collections\Dictionary::map(callable $callback) + +Updates elements in the collection by +applying a given callback function. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### merge + + Dictionary PHPCollections\Collections\Dictionary::merge(Dictionary $newDictionary) + +Merges two dictionaries into a new one. + +* Visibility: **public** + +#### Arguments +* $newDictionary **PHPCollections\Collections\Dictionary** + +### remove + + bool PHPCollections\Collections\Dictionary::remove(mixed key) + +Removes a value from the dictionary. + +* Visibility: **public** + +#### Arguments +* $key **mixed** + +### sort + + ?Dictionary PHPCollections\Collections\Dictionary::sort(callable $callback) + +Sorts the collection data by values +applying a given callback. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### toArray + + array PHPCollections\Collections\Dictionary::toArray() + +Returns an array representation +of your dictionary data. + +* Visibility: **public** + +### toJson + + string PHPCollections\Collections\Dictionary::toJson() + +Returns a JSON representation +of your dictionary data. + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** + +### update + + bool PHPCollections\Collections\Dictionary::update(mixed $key, mixed $value) + +Updates the value of one Pair +in the collection. + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** diff --git a/docs/PHPCollections-Collections-GenericList.md b/docs/PHPCollections-Collections-GenericList.md new file mode 100644 index 0000000..1572253 --- /dev/null +++ b/docs/PHPCollections-Collections-GenericList.md @@ -0,0 +1,244 @@ +PHPCollections\Collections\GenericList +=============== + +A list for a generic type of data. + +* Class name: GenericList +* Namespace: PHPCollections\Collections +* This class extends: BaseCollection +* This class implements: CollectionInterface, IterableInterface, SortableInterface + +Properties +---------- + +### $type + + private mixed $type + +The type of data that +will be stored. + +* Visibility: **private** + +Methods +------- + +### __construct + + void PHPCollections\Collections\GenericList::__construct(string $type, array $data) + +Initializes the class properties. + +* Visibility: **public** + +#### Arguments +* $type **string** +* $data **array** + +### add + + void PHPCollections\Collections\GenericList::add(mixed $value) + +Adds a new object to the collection. + +* Visibility: **public** + +#### Arguments +* $value **mixed** + +### checkType + + void PHPCollections\Collections\GenericList::checkType(mixed $data) + +Determines if the passed data is +of the type specified in the type +attribute, if not throws and Exception. + +* Visibility: **private** + +#### Arguments +* $values **mixed** + +#### Throws +* **\InvalidArgumentException** + +### filter + + ?GenericList PHPCollections\Collections\GenericList::filter(callable $callback) + +Returns all the coincidences found +for the given callback or null. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### find + + ?mixed PHPCollections\Collections\GenericList::find(callable $callback) + +Returns the first element that +matches whith the callback criteria. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### first + + mixed PHPCollections\Collections\GenericList::first() + +Gets the first element of the collection. + +* Visibility: **public** + +#### Throws +**\OutOfRangeException** + +### forEach + + void PHPCollections\Collections\GenericList::forEach(callable $callback) + +Iterates over every element of the collection. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### get + + ?object PHPCollections\Collections\GenericList::get(int $offset) + +Returns the object at the specified index +or null if it's not defined. + +* Visibility: **public** + +#### Arguments +* $offset **int** + +#### Throws +* **\OutOfRangeException** + +### last + + mixed PHPCollections\Collections\GenericList::last() + +Gets the last element of the collection. + +* Visibility: **public** + +#### Throws +* **\OutOfRangeException** + +### map + + ?GenericList PHPCollections\Collections\GenericList::map(callable $callback) + +Updates elements in the collection by +applying a given callback function. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### merge + + GenericList PHPCollections\Collections\GenericList::merge(array $data) + +Merges new data with the actual +collection and returns a new one. + +* Visibility: **public** + +#### Arguments +* $data **array** + +### rand + + mixed PHPCollections\Collections\GenericList::rand() + +Returns a random element from +the collection. + +* Visibility: **public** + +### remove + + bool PHPCollections\Collections\GenericList::remove(int $offset) + +Removes an item from the collection +and repopulate the data container. + +* Visibility: **public** + +#### Arguments +* $offset **int** + +#### Throws +* **\OutOfRangeException** + +### repopulate + + void PHPCollections\Collections\GenericList::repopulate() + +Repopulates the data container. + +* Visibility: **private** + +### reverse + + GenericList PHPCollections\Collections\GenericList::reverse() + +Returns a new collection with the +reversed values. + +* Visibility: **public** + +#### Throws +* **\PHPCollections\Exceptions\InvalidOperationException** + +### search + + ?GenericList PHPCollections\Collections\GenericList::search(callable $callback, boolean $shouldStop = false) + +Searches one or more elements in +the collection. + +* Visibility: **public** + +#### Arguments +* $callback **callable** +* $shouldStop **boolean** + +### sort + + bool PHPCollections\Collections\GenericList::sort(callable $callback) + +Sorts the collection data by values +applying a given callback. + +* Visibility: **public** + +#### Arguments +* $callback **callable** + +### update + + bool PHPCollections\Collections\GenericList::update(integer $index, mixed $value) + +Updates the value of the element +at the given index. + +* Visibility: **public** + +#### Arguments +* $index **integer** +* $value **mixed** + +#### Throws +* **\PHPCollections\Exceptions\InvalidOperationException** diff --git a/docs/PHPCollections-Collections-Pair.md b/docs/PHPCollections-Collections-Pair.md new file mode 100644 index 0000000..40b1b98 --- /dev/null +++ b/docs/PHPCollections-Collections-Pair.md @@ -0,0 +1,81 @@ +PHPCollections\Collections\Pair +=============== + +A simple key / value pair +object representation. + +* Class name: Pair +* Namespace: PHPCollections\Collections + +Properties +---------- + +### $key + + private mixed $key + +The key for the Pair object. + +* Visibility: **private** + +### $value + + private mixed $value + +The value for the Pair object. + +* Visibility: **private** + +Methods +------- + +### __construct + + void PHPCollections\Collections\Pair::__construct(mixed $key, mixed $value) + +Initializes class properties. + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** + +### __get + + mixed PHPCollections\Collections\Pair::__get(string $name) + +Allows access to the key +property by its value. + +* Visibility: **public** + +#### Arguments +* $name **string** + +### getKey + + mixed PHPCollections\Collections\Pair::getKey() + +Returns the key property. + +* Visibility: **public** + +### getValue + + mixed PHPCollections\Collections\Pair::getValue() + +Returns the value property. + +* Visibility: **public** + +### setValue + + void PHPCollections\Collections\Pair::setValue(mixed $value) + +Sets the value of the value property. + +* Visibility: **public** + +#### Arguments +* $value **mixed** diff --git a/docs/PHPCollections-Collections-Stack.md b/docs/PHPCollections-Collections-Stack.md new file mode 100644 index 0000000..0ed2f20 --- /dev/null +++ b/docs/PHPCollections-Collections-Stack.md @@ -0,0 +1,112 @@ +PHPCollections\Collections\Stack +=============== + +A generic LIFO Stack. + +* Class name: Stack +* Namespace: PHPCollections\Collections +* This class implements: Countable + +Properties +---------- + +### $data + + private array $data + +The data container. + +* Visibility: **private** + +### $type + + private mixed $type + +The type of the values +for this Stack. + +* Visibility: **private** + +Methods +------- + +### __construct + + void PHPCollections\Collections\Stack::__construct(string $type) + +Initialize class properties. + +* Visibility: **public** + +#### Arguments +* $type **string** + +### checkType + + void PHPCollections\Collections\Stack::checkType(mixed $value) + +Determines if the passed value is +of the type specified in the type +attribute, if not raises and Exception. + +* Visibility: **private** + +#### Arguments +* $value **mixed** + +#### Throws +* **\InvalidArgumentException** + +### clear + + void PHPCollections\Collections\Stack::clear() + +Clears the data values. + +* Visibility: **public** + +### count + + int PHPCollections\Collections\Stack::count() + +Returns the length of the Stack. + +* Visibility: **public** + +### isEmpty + + bool PHPCollections\Collections\Stack::isEmpty() + +Checks if the stack is empty. + +* Visibility: **public** + +### peek + + mixed PHPCollections\Collections\Stack::peek() + +Gets the element at +the end of the Stack. + +* Visibility: **public** + +### pop + + mixed PHPCollections\Collections\Stack::pop() + +Pops the element at +the end of the stack. + +* Visibility: **public** + +### push + + mixed PHPCollections\Collections\Stack::push(mixed $value) + +Adds a new element at +the end of the Stack. + +* Visibility: **public** + +#### Arguments +* $value **mixed** diff --git a/docs/PHPCollections-DataHolder.md b/docs/PHPCollections-DataHolder.md new file mode 100644 index 0000000..91ccfad --- /dev/null +++ b/docs/PHPCollections-DataHolder.md @@ -0,0 +1,106 @@ +PHPCollections\DataHolder +=============== + +A class for storing and managing data. + +* Class name: DataHolder +* Namespace: PHPCollections +* This class implements: ArrayAccess, IteratorAggregate + +Properties +---------- + +### $container + + private array $container + +The array for storing data. + +* Visibility: **private** + +Methods +------- + +### __construct + + void PHPCollections\DataHolder::__construct(array $data) + +Initializes the container property. + +* Visibility: **public** + +#### Arguments +* $data **array** + +### getContainer + + array PHPCollections\DataHolder::getContainer() + +Returns the container array. + +* Visibility: **public** + +### getIterator + + \ArrayIterator PHPCollections\DataHolder::getIterator() + +Returns an array iterator for +the container property. + +* Visibility: **public** + +### offsetExists + + boolean PHPCollections\DataHolder::offsetExists(mixed $offset) + +Checks if an offset exists in the container. + +* Visibility: **public** + +#### Arguments +* $offset **mixed** + +### offsetGet + + ?mixed PHPCollections\DataHolder::offsetGet(mixed $offset) + +Gets a value from the container. + +* Visibility: **public** + +#### Arguments +* $offset **mixed** + +### offsetSet + + void PHPCollections\DataHolder::offsetSet(mixed $offset, mixed $value) + +Sets a value into the container. + +* Visibility: **public** + +#### Arguments +* $offset **mixed** +* $value **mixed** + +### offsetUnset + + void PHPCollections\DataHolder::offsetUnset(mixed $offset) + +Unsets an offset from the container. + +* Visibility: **public** + +#### Arguments +* $offset **mixed** + +### setContainer + + void PHPCollections\DataHolder::setContainer(array $data) + +Sets the container array. + +* Visibility: **public** + +#### Arguments +* $data **array** diff --git a/docs/PHPCollections-Exceptions-InvalidOperationException.md b/docs/PHPCollections-Exceptions-InvalidOperationException.md new file mode 100644 index 0000000..d86dc52 --- /dev/null +++ b/docs/PHPCollections-Exceptions-InvalidOperationException.md @@ -0,0 +1,21 @@ +PHPCollections\Exceptions\InvalidOperationException +=============== + +An Exception for representing +invalid operations with collections. + +* Class name: InvalidOperationException +* Namespace: PHPCollections\Exceptions +* Parent class: Exception + +Methods +------- + +### __toString + + string PHPCollections\Exceptions\InvalidOperationException::__toString() + +Returns the string representation +of the Exception. + +* Visibility: **public** diff --git a/docs/PHPCollections-Interfaces-CollectionInterface.md b/docs/PHPCollections-Interfaces-CollectionInterface.md new file mode 100644 index 0000000..2841944 --- /dev/null +++ b/docs/PHPCollections-Interfaces-CollectionInterface.md @@ -0,0 +1,48 @@ +PHPCollections\Interfaces\CollectionInterface +=============== + +* Interface name: CollectionInterface +* Namespace: PHPCollections\Interfaces +* This is an **interface** + +Methods +------- + +### add + + void PHPCollections\Interfaces\CollectionInterface::add(mixed $value) + +* Visibility: **public** + +#### Arguments +* $value **mixed** + + + +### get + + mixed PHPCollections\Interfaces\CollectionInterface::get(int $offset) + +* Visibility: **public** + +#### Arguments +* $offset **int** + +### remove + + void PHPCollections\Interfaces\CollectionInterface::remove(int $offset) + +* Visibility: **public** + +#### Arguments +* $offset **int** + +### update + + bool PHPCollections\Interfaces\CollectionInterface::update(int $offset, mixed $value) + +* Visibility: **public** + +#### Arguments +* $offset **int** +* $value **mixed** diff --git a/docs/PHPCollections-Interfaces-DictionaryInterface.md b/docs/PHPCollections-Interfaces-DictionaryInterface.md new file mode 100644 index 0000000..7791e5c --- /dev/null +++ b/docs/PHPCollections-Interfaces-DictionaryInterface.md @@ -0,0 +1,47 @@ +PHPCollections\Interfaces\DictionaryInterface +=============== + +* Interface name: DictionaryInterface +* Namespace: PHPCollections\Interfaces +* This is an **interface** + +Methods +------- + +### add + + void PHPCollections\Interfaces\DictionaryInterface::add($key, $value) + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** + +### get + + mixed PHPCollections\Interfaces\DictionaryInterface::get($key) + +* Visibility: **public** + +#### Arguments +* $key **mixed** + +### remove + + bool PHPCollections\Interfaces\DictionaryInterface::remove($key) + +* Visibility: **public** + +#### Arguments +* $key **mixed** + +### update + + bool PHPCollections\Interfaces\DictionaryInterface::update($key, $value) + +* Visibility: **public** + +#### Arguments +* $key **mixed** +* $value **mixed** diff --git a/docs/PHPCollections-Interfaces-SortableInterface.md b/docs/PHPCollections-Interfaces-SortableInterface.md new file mode 100644 index 0000000..ba72805 --- /dev/null +++ b/docs/PHPCollections-Interfaces-SortableInterface.md @@ -0,0 +1,18 @@ +PHPCollections\Interfaces\SortableInterface +=============== + +* Interface name: SortableInterface +* Namespace: PHPCollections\Interfaces +* This is an **interface** + +Methods +------- + +### sort + + bool PHPCollections\Interfaces\SortableInterface::sort(callable $callback) + +* Visibility: **public** + +#### Arguments +* $callback **callable** diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..1036c85 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,19 @@ +Package Index +========= + +* PHPCollections + * PHPCollections\Exceptions + * [InvalidOperationException](PHPCollections-Exceptions-InvalidOperationException.md) + * PHPCollections\Interfaces + * [DictionaryInterface](PHPCollections-Interfaces-DictionaryInterface.md) + * [SortableInterface](PHPCollections-Interfaces-SortableInterface.md) + * [CollectionInterface](PHPCollections-Interfaces-CollectionInterface.md) + * PHPCollections\Collections + * [Pair](PHPCollections-Collections-Pair.md) + * [Stack](PHPCollections-Collections-Stack.md) + * [BaseCollection](PHPCollections-Collections-BaseCollection.md) + * [ArrayList](PHPCollections-Collections-ArrayList.md) + * [Dictionary](PHPCollections-Collections-Dictionary.md) + * [GenericList](PHPCollections-Collections-GenericList.md) + * [DataHolder](PHPCollections-DataHolder.md) + diff --git a/src/Collections/ArrayList.php b/src/Collections/ArrayList.php index 52d9eeb..c4559b2 100644 --- a/src/Collections/ArrayList.php +++ b/src/Collections/ArrayList.php @@ -11,7 +11,7 @@ use PHPCollections\Exceptions\InvalidOperationException; /** - * A list of values of any type + * A list of values of any type. */ class ArrayList extends BaseCollection implements CollectionInterface, IterableInterface, SortableInterface { diff --git a/src/Collections/BaseCollection.php b/src/Collections/BaseCollection.php index b0550f8..d80b71f 100644 --- a/src/Collections/BaseCollection.php +++ b/src/Collections/BaseCollection.php @@ -9,7 +9,7 @@ use PHPCollections\DataHolder; /** - * The base for countable and + * The base class for countable and * JSON serializable collections. */ abstract class BaseCollection implements Countable, JsonSerializable @@ -21,13 +21,6 @@ abstract class BaseCollection implements Countable, JsonSerializable */ protected $dataHolder; - /** - * Represents the index of the data array. - * - * @var int - */ - private $position = 0; - /** * Initializes the dataHolder property. * diff --git a/src/Collections/GenericList.php b/src/Collections/GenericList.php index b318a9b..60af511 100644 --- a/src/Collections/GenericList.php +++ b/src/Collections/GenericList.php @@ -17,15 +17,15 @@ class GenericList extends BaseCollection implements CollectionInterface, IterableInterface, SortableInterface { /** - * The type of data that's - * gonna be stored. + * The type of data that + * will be stored. * * @var mixed */ private $type; /** - * Initializes class properties. + * Initializes the class properties. * * @param string $type * @param array $data @@ -150,7 +150,8 @@ public function forEach(callable $callback): void } /** - * Returns the object at the specified index. + * Returns the object at the specified index + * or null if it's not defined. * * @param int $offset. * @throws \OutOfRangeException @@ -239,7 +240,7 @@ public function rand() /** * Removes an item from the collection - * and repopulate the data array. + * and repopulate the data container. * * @param int $offset * @throws \OutOfRangeException @@ -261,11 +262,11 @@ public function remove(int $offset): void } /** - * Repopulates the data array. + * Repopulates the data container. * * @return void */ - public function repopulate(): void + private function repopulate(): void { $oldData = array_values($this->toArray()); $this->dataHolder->setContainer($oldData); diff --git a/src/utils.php b/src/utils.php index 91613f1..924dc00 100644 --- a/src/utils.php +++ b/src/utils.php @@ -2,9 +2,10 @@ /** * Return the correct article - * for preceding a specific word + * for preceding a specific word. * * @param string $word + * * @return string */ function getArticle(string $word) :string