Skip to content

Commit b8725ab

Browse files
committed
docblocks updated
1 parent 6ecd884 commit b8725ab

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

src/TypedArray.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,29 @@ class TypedArray extends ArrayObject
4040
protected $type = '';
4141

4242
/**
43-
* __construct.
44-
*
4543
* Class Contructor.
4644
*
47-
* @param string $type
48-
* @param array $array
45+
* <pre><code class="php">use Linna\TypedArray;
46+
*
47+
* //correct, only int passed to array.
48+
* $array = new TypedArray('int', [1, 2, 3, 4]);
49+
* $array[] = 5;
50+
*
51+
* //throw InvalidArgumentException.
52+
* $array = new TypedArray('int', [1, 'a', 3, 4]);
53+
* //throw InvalidArgumentException.
54+
* $array[] = 'a';
55+
* </code></pre>
56+
*
57+
* <b>Note</b>: Allowed types are only <i>array</i>, <i>bool</i>, <i>callable</i>,
58+
* <i>float</i>, <i>int</i>, <i>object</i> and <i>string</i>.
59+
*
60+
* @param string $type Type for values inside array.
61+
* @param array $array Optional, if you wish initialize object with values.
4962
*
50-
* @throws InvalidArgumentException If type is not supported and if
51-
* elements of passed with $array
52-
* are not of the configured type
63+
* @throws InvalidArgumentException If type is not supported or if
64+
* elements in the optional array parameter
65+
* aren't of the configured type.
5366
*/
5467
public function __construct(string $type, array $array = [])
5568
{

src/TypedObjectArray.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,33 @@ class TypedObjectArray extends ArrayObject
2727
protected $type = '';
2828

2929
/**
30-
* __construct.
31-
*
3230
* Class Contructor.
3331
*
34-
* @param string $type
35-
* @param array $array
32+
* <pre><code class="php">use Linna\TypedObjectArray;
33+
*
34+
* //correct, only Foo class instances passed to array.
35+
* $array = new TypedObjectArray(Foo::class, [
36+
* new Foo(),
37+
* new Foo()
38+
* ]);
39+
* $array[] = new Foo();
40+
*
41+
* //throw InvalidArgumentException.
42+
* $array = new TypedObjectArray(Foo::class, [
43+
* new Foo(),
44+
* new Bar()
45+
* ]);
46+
* //throw InvalidArgumentException.
47+
* $array[] = new Bar();
48+
* </code></pre>
49+
*
50+
* <b>Note</b>: Allowed types are only <i>existing classes</i>.
51+
*
52+
* @param string $type Type for values inside array.
53+
* @param array $array Optional, if you wish initialize object with values.
3654
*
37-
* @throws InvalidArgumentException If elements of passed with $array
38-
* are not of the configured type
55+
* @throws InvalidArgumentException If elements in the optional array parameter
56+
* aren't of the configured type.
3957
*/
4058
public function __construct(string $type, array $array = [])
4159
{

0 commit comments

Comments
 (0)