1 | <?php declare(strict_types=1); |
||
26 | class ObjectMap implements ObjectMapInterface |
||
27 | { |
||
28 | use ObjectTypeHintTrait; |
||
29 | |||
30 | protected $behavior = self::DEFAULT; |
||
31 | |||
32 | /** |
||
33 | * @var Bucket[] |
||
34 | */ |
||
35 | protected $keys = []; |
||
36 | |||
37 | /** |
||
38 | * @param int $behavior |
||
39 | */ |
||
40 | 42 | public function __construct(int $behavior = self::DEFAULT) |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 28 | public function put($key, $value) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 5 | public function get($key) |
|
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | 23 | public function has($key): bool |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 7 | public function remove($key) |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 16 | public function count() |
|
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | 3 | public function clear() |
|
127 | |||
128 | /** |
||
129 | * @param object $value |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 33 | protected function getHash($value) |
|
137 | |||
138 | /** |
||
139 | * @param string $hash |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | 14 | protected function doRemove(string $hash) |
|
147 | |||
148 | /** |
||
149 | * @param object $key |
||
150 | * @param object $value |
||
151 | * @param string $hash |
||
152 | * |
||
153 | * @return Bucket |
||
154 | */ |
||
155 | 26 | protected function createBucket($key, $value, string $hash): Bucket |
|
167 | |||
168 | /** |
||
169 | * @param $obj |
||
170 | * @param string $hash |
||
171 | * |
||
172 | * @return WeakReference |
||
173 | */ |
||
174 | protected function createReference($obj, string $hash): WeakReference |
||
180 | } |
||
181 | |||
188 |
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.