Skip to content

Commit ae9dcc0

Browse files
author
Jean Claveau
committed
Updating README and docs
1 parent 58c2fab commit ae9dcc0

File tree

3 files changed

+153
-21
lines changed

3 files changed

+153
-21
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ php-deferred-callchain is installable via [Composer](http://getcomposer.org)
1818
composer require jclaveau/php-deferred-callchain
1919

2020
## Usage
21+
### Fluent call chain
2122
```php
22-
// fluent call chain
2323
$nameRobert = (new DeferredCallChain)
2424
->setName('Muda')
2525
->setFirstName('Robert')
@@ -30,8 +30,10 @@ $robert = $nameRobert( $mySubjectIMissedBefore );
3030

3131
echo $robert->getFullName(); // => "Robert Muda"
3232
echo (string) $nameRobert; // => "(new JClaveau\Async\DeferredCallChain)->setName('Muda')->setFirstName('Robert')"
33+
```
3334

34-
// working with arrays
35+
### Working with arrays
36+
```php
3537
$getSubColumnValue = (new DeferredCallChain)
3638
['column_1']
3739
['sub_column_3']

docs/README.md

Lines changed: 115 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@
44

55
* [DeferredCallChain](#deferredcallchain)
66
* [new_](#new_)
7+
* [offsetGet](#offsetget)
78
* [__call](#__call)
89
* [jsonSerialize](#jsonserialize)
910
* [__toString](#__tostring)
1011
* [__invoke](#__invoke)
12+
* [offsetSet](#offsetset)
13+
* [offsetExists](#offsetexists)
14+
* [offsetUnset](#offsetunset)
1115

1216
## DeferredCallChain
1317

14-
18+
This class stores an arbitrary stack of calls (methods or array entries access)
19+
that will be callable on any future variable.
1520

1621

1722

1823
* Full name: \JClaveau\Async\DeferredCallChain
19-
* This class implements: \JsonSerializable
24+
* This class implements: \JsonSerializable, \ArrayAccess
2025

2126

2227
### new_
2328

24-
29+
Simple factory to avoid (new DeferredCallChain)
2530

2631
```php
27-
DeferredCallChain::new_( )
32+
DeferredCallChain::new_( ): $this
2833
```
2934

3035

@@ -35,12 +40,34 @@ DeferredCallChain::new_( )
3540

3641
---
3742

38-
### __call
43+
### offsetGet
44+
45+
ArrayAccess interface
46+
47+
```php
48+
DeferredCallChain::offsetGet( string $key )
49+
```
50+
51+
52+
53+
54+
**Parameters:**
55+
56+
| Parameter | Type | Description |
57+
|-----------|------|-------------|
58+
| `$key` | **string** | The entry to acces |
59+
60+
61+
62+
63+
---
3964

65+
### __call
4066

67+
Stores any call in the the stack.
4168

4269
```php
43-
DeferredCallChain::__call( $method, array $arguments )
70+
DeferredCallChain::__call( string $method, array $arguments ): $this
4471
```
4572

4673

@@ -50,7 +77,7 @@ DeferredCallChain::__call( $method, array $arguments )
5077

5178
| Parameter | Type | Description |
5279
|-----------|------|-------------|
53-
| `$method` | **** | |
80+
| `$method` | **string** | |
5481
| `$arguments` | **array** | |
5582

5683

@@ -79,16 +106,21 @@ DeferredCallChain::jsonSerialize( )
79106

80107
### __toString
81108

82-
109+
Outputs the PHP code producing the current call chain while it's casted
110+
as a string.
83111

84112
```php
85-
DeferredCallChain::__toString( )
113+
DeferredCallChain::__toString( ): string
86114
```
87115

88116

89117

90118

91119

120+
**Return Value:**
121+
122+
The PHP code corresponding to this call chain
123+
92124

93125

94126
---
@@ -98,7 +130,78 @@ DeferredCallChain::__toString( )
98130
Invoking the instance produces the call of the stack
99131

100132
```php
101-
DeferredCallChain::__invoke( $target )
133+
DeferredCallChain::__invoke( $target ): \JClaveau\Async\The
134+
```
135+
136+
137+
138+
139+
**Parameters:**
140+
141+
| Parameter | Type | Description |
142+
|-----------|------|-------------|
143+
| `$target` | **** | The target to apply the callchain on |
144+
145+
146+
**Return Value:**
147+
148+
value returned once the call chain is called uppon $target
149+
150+
151+
152+
---
153+
154+
### offsetSet
155+
156+
Unused part of the ArrayAccess interface
157+
158+
```php
159+
DeferredCallChain::offsetSet( $offset, $value )
160+
```
161+
162+
163+
164+
165+
**Parameters:**
166+
167+
| Parameter | Type | Description |
168+
|-----------|------|-------------|
169+
| `$offset` | **** | |
170+
| `$value` | **** | |
171+
172+
173+
174+
175+
---
176+
177+
### offsetExists
178+
179+
Unused part of the ArrayAccess interface
180+
181+
```php
182+
DeferredCallChain::offsetExists( $offset )
183+
```
184+
185+
186+
187+
188+
**Parameters:**
189+
190+
| Parameter | Type | Description |
191+
|-----------|------|-------------|
192+
| `$offset` | **** | |
193+
194+
195+
196+
197+
---
198+
199+
### offsetUnset
200+
201+
Unused part of the ArrayAccess interface
202+
203+
```php
204+
DeferredCallChain::offsetUnset( $offset )
102205
```
103206

104207

@@ -108,7 +211,7 @@ DeferredCallChain::__invoke( $target )
108211

109212
| Parameter | Type | Description |
110213
|-----------|------|-------------|
111-
| `$target` | **** | |
214+
| `$offset` | **** | |
112215

113216

114217

@@ -118,4 +221,4 @@ DeferredCallChain::__invoke( $target )
118221

119222

120223
--------
121-
> This document was automatically generated from source code comments on 2018-11-06 using [phpDocumentor](http://www.phpdoc.org/) and [cvuorinen/phpdoc-markdown-public](https://github.com/cvuorinen/phpdoc-markdown-public)
224+
> This document was automatically generated from source code comments on 2018-11-14 using [phpDocumentor](http://www.phpdoc.org/) and [cvuorinen/phpdoc-markdown-public](https://github.com/cvuorinen/phpdoc-markdown-public)

src/DeferredCallChain.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
* @author Jean Claveau
77
*/
88
namespace JClaveau\Async;
9+
use BadMethodCallException;
910

1011
/**
12+
* This class stores an arbitrary stack of calls (methods or array entries access)
13+
* that will be callable on any future variable.
1114
*/
1215
class DeferredCallChain implements \JsonSerializable, \ArrayAccess
1316
{
14-
/** @var */
17+
/** @var array $stack The stack of deferred calls */
1518
protected $stack = [];
1619

1720
/**
21+
* Simple factory to avoid (new DeferredCallChain)
22+
*
23+
* @return $this
1824
*/
1925
public static function new_()
2026
{
@@ -23,6 +29,8 @@ public static function new_()
2329

2430
/**
2531
* ArrayAccess interface
32+
*
33+
* @param string $key The entry to acces
2634
*/
2735
public function &offsetGet($key)
2836
{
@@ -34,6 +42,8 @@ public function &offsetGet($key)
3442
}
3543

3644
/**
45+
* Stores any call in the the stack.
46+
*
3747
* @param string $method
3848
* @param array $arguments
3949
*
@@ -60,6 +70,10 @@ public function jsonSerialize()
6070
}
6171

6272
/**
73+
* Outputs the PHP code producing the current call chain while it's casted
74+
* as a string.
75+
*
76+
* @return string The PHP code corresponding to this call chain
6377
*/
6478
public function __toString()
6579
{
@@ -84,6 +98,9 @@ public function __toString()
8498

8599
/**
86100
* Invoking the instance produces the call of the stack
101+
*
102+
* @param $target The target to apply the callchain on
103+
* @return The value returned once the call chain is called uppon $target
87104
*/
88105
public function __invoke($target)
89106
{
@@ -107,31 +124,41 @@ public function __invoke($target)
107124
}
108125

109126
/**
110-
* ArrayAccess interface
127+
* Unused part of the ArrayAccess interface
128+
*
129+
* @param $offset
130+
* @param $value
131+
* @throws \BadMethodCallException
111132
*/
112133
public function offsetSet($offset, $value)
113134
{
114-
throw new \BadMethodCallException(
135+
throw new BadMethodCallException(
115136
"not implemented"
116137
);
117138
}
118139

119140
/**
120-
* ArrayAccess interface
141+
* Unused part of the ArrayAccess interface
142+
*
143+
* @param $offset
144+
* @throws \BadMethodCallException
121145
*/
122146
public function offsetExists($offset)
123147
{
124-
throw new \BadMethodCallException(
148+
throw new BadMethodCallException(
125149
"not implemented"
126150
);
127151
}
128152

129153
/**
130-
* ArrayAccess interface
154+
* Unused part of the ArrayAccess interface
155+
*
156+
* @param $offset
157+
* @throws \BadMethodCallException
131158
*/
132159
public function offsetUnset($offset)
133160
{
134-
throw new \BadMethodCallException(
161+
throw new BadMethodCallException(
135162
"not implemented"
136163
);
137164
}

0 commit comments

Comments
 (0)