Skip to content

Commit e634645

Browse files
committed
Added docs.
1 parent 57cd1ae commit e634645

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

README.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,26 @@ if(!$result->isValid()) {
5252
}
5353
```
5454

55+
> NOTE: The `isValid()` method returns `true` if
56+
> no state was set, or the state is of the success type.
57+
5558
## Collection of results
5659

60+
### Introduction
61+
5762
If an operation can have multiple possible result states,
58-
like a validation operation, for example, you can use the
59-
collection class.
63+
like a validation operation, for example, you can use the
64+
result collection class.
6065

6166
Every call to `makeError()`, `makeWarning()` or `makeSuccess()`
6267
will add a new result instance to the collection.
6368

69+
> All result types are stored in the collection, so it is
70+
> important to note that both failed and successful operations
71+
> can be tracked.
72+
73+
### Quick Start
74+
6475
```php
6576
use function AppUtils\operationCollection;
6677
use AppUtils\OperationResult_Collection;
@@ -93,6 +104,69 @@ if(!$collection->isValid()) {
93104
}
94105
```
95106

107+
> NOTE: The `isValid()` method returns `true` if none of the
108+
> results in the collection are of the error or warning type.
109+
110+
### Accessing the results
111+
112+
Accessing results is made to be as easy as possible, with many
113+
different ways to get the information you need.
114+
115+
```php
116+
use function AppUtils\operationCollection;
117+
118+
$collection = operationCollection();
119+
120+
// Get all results in the order they were added
121+
$results = $collection->getResults();
122+
123+
// Get all errors
124+
$errors = $collection->getErrors();
125+
126+
// Get all warnings
127+
$warnings = $collection->getWarnings();
128+
129+
// Get all successes
130+
$successes = $collection->getSuccesses();
131+
132+
// Get all notices
133+
$notices = $collection->getNotices();
134+
135+
// Check if the collection contains any result of a specific type
136+
if($collection->isError()) {}
137+
if($collection->isWarning()) {}
138+
if($collection->isSuccess()) {}
139+
if($collection->isNotice()) {}
140+
141+
// Check if the collection contains a specific result code
142+
if($collection->containsCode(1)) {
143+
// do something
144+
}
145+
146+
// Get all unique result codes
147+
$codes = $collection->getCodes();
148+
```
149+
150+
### Counting results
151+
152+
All result types can be counted individually, and the total
153+
number of results can be counted as well.
154+
155+
```php
156+
use function AppUtils\operationCollection;
157+
158+
$collection = operationCollection();
159+
160+
// Count the total number of results
161+
$all = $collection->countResults();
162+
$errors = $collection->countErrors();
163+
$warnings = $collection->countWarnings();
164+
$successes = $collection->countSuccesses();
165+
$notices = $collection->countNotices();
166+
167+
168+
```
169+
96170
## Extend the result classes
97171

98172
Both the `OperationResult` and collection classes are designed to be extended,

0 commit comments

Comments
 (0)