1 | <?php |
||
12 | class Collection { |
||
13 | /** |
||
14 | * @var array Main storage for objects in this collection. |
||
15 | */ |
||
16 | private $storage = array(); |
||
17 | |||
18 | /** |
||
19 | * Add an object to this collection. |
||
20 | * |
||
21 | * @param mixed $value The object to be added. |
||
22 | * |
||
23 | * @api |
||
24 | * @since future |
||
25 | * @return void |
||
26 | */ |
||
27 | 2 | public function add( $value ) { |
|
30 | |||
31 | /** |
||
32 | * Clear this collection. |
||
33 | * |
||
34 | * @api |
||
35 | * @since future |
||
36 | * @return void |
||
37 | */ |
||
38 | 1 | public function clear() { |
|
41 | |||
42 | /** |
||
43 | * Merge another collection into here. |
||
44 | * |
||
45 | * @param \GV\Collection $collection The collection to be merged. |
||
46 | * |
||
47 | * @api |
||
48 | * @since future |
||
49 | * @return void |
||
50 | */ |
||
51 | 1 | public function merge( \GV\Collection $collection ) { |
|
54 | |||
55 | /** |
||
56 | * Returns all the objects in this collection as an an array. |
||
57 | * |
||
58 | * @api |
||
59 | * @since future |
||
60 | * @return array The objects in this collection. |
||
61 | */ |
||
62 | 2 | public function all() { |
|
65 | |||
66 | /** |
||
67 | * Get the last added object. |
||
68 | * |
||
69 | * @api |
||
70 | * @since future |
||
71 | * @return mixed|null The last item in here, or null if there are none. |
||
72 | */ |
||
73 | 1 | public function last() { |
|
76 | |||
77 | /** |
||
78 | * Returns the count of the objects in this collection. |
||
79 | * |
||
80 | * @api |
||
81 | * @since future |
||
82 | * @return int The size of this collection. |
||
83 | */ |
||
84 | 3 | public function count() { |
|
87 | } |
||
88 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.