gravityview /
GravityView
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | namespace GV; |
||
| 3 | |||
| 4 | /** If this file is called directly, abort. */ |
||
| 5 | if ( ! defined( 'GRAVITYVIEW_DIR' ) ) |
||
|
0 ignored issues
–
show
|
|||
| 6 | die(); |
||
| 7 | |||
| 8 | /** |
||
| 9 | * A generic Collection base class. |
||
| 10 | */ |
||
| 11 | class Collection { |
||
| 12 | /** |
||
| 13 | * @var array Main storage for objects in this collection. |
||
| 14 | */ |
||
| 15 | private $storage = array(); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Add an object to this collection. |
||
| 19 | * |
||
| 20 | * @param mixed $value The object to be added. |
||
| 21 | * |
||
| 22 | * @api |
||
| 23 | * @since future |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function append( $value ) { |
||
| 27 | $this->storage []= $value; |
||
|
0 ignored issues
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Returns all the objects in this collection as an an array. |
||
| 32 | * |
||
| 33 | * @api |
||
| 34 | * @since future |
||
| 35 | * @return array The objects in this collection. |
||
| 36 | */ |
||
| 37 | public function all() { |
||
| 38 | return $this->storage; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns the count of the objects in this collection. |
||
| 43 | * |
||
| 44 | * @api |
||
| 45 | * @since future |
||
| 46 | * @return int The size of this collection. |
||
| 47 | */ |
||
| 48 | public function count() { |
||
| 49 | return count( $this->storage ); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
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.