1 | <?php |
||
13 | final class TestApi implements CrudsApiInterface, EntityCacheAwareInterface, StaticApiFactoryInterface |
||
14 | { |
||
15 | /** @var RpcClientInterface */ |
||
16 | private $client; |
||
17 | /** @var ApiMetadata */ |
||
18 | private $metadata; |
||
19 | /** @var EntityDataCacheInterface */ |
||
20 | private $cache; |
||
21 | |||
22 | /** |
||
23 | * TestApi constructor. |
||
24 | * |
||
25 | * @param RpcClientInterface $client |
||
26 | * @param ApiMetadata $metadata |
||
27 | */ |
||
28 | public function __construct(RpcClientInterface $client, ApiMetadata $metadata) |
||
29 | { |
||
30 | $this->client = $client; |
||
31 | $this->metadata = $metadata; |
||
32 | $this->cache = new VoidEntityCache($metadata); |
||
33 | } |
||
34 | |||
35 | /** {@inheritdoc} */ |
||
36 | public static function createApi(RpcClientInterface $client, ApiMetadata $metadata) |
||
40 | |||
41 | /** {@inheritdoc} */ |
||
42 | public function count(array $criteria) |
||
48 | |||
49 | /** {@inheritdoc} */ |
||
50 | public function create(array $data) |
||
62 | |||
63 | /** {@inheritdoc} */ |
||
64 | public function find(array $identifier) |
||
78 | |||
79 | /** {@inheritdoc} */ |
||
80 | public function patch(array $identifier, array $patch, array $data) |
||
86 | |||
87 | /** {@inheritdoc} */ |
||
88 | public function search(array $criteria = [], array $orderBy = null, $limit = null, $offset = null) |
||
107 | |||
108 | /** {@inheritdoc} */ |
||
109 | public function remove(array $identifier) |
||
115 | |||
116 | /** @return RpcClientInterface */ |
||
117 | public function getClient() |
||
121 | |||
122 | /** @return ApiMetadata */ |
||
123 | public function getMetadata() |
||
127 | |||
128 | /** {@inheritdoc} */ |
||
129 | public function setEntityCache(EntityDataCacheInterface $cache) |
||
133 | |||
134 | /** |
||
135 | * @param string $method |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | private function getMethod($method) |
||
143 | } |
||
144 |
Let?s assume that you have the following
foreach
statement:$itemValue
is assigned by reference. This is possible because the expression (in the example$array
) can be used as a reference target.However, if we were to replace
$array
with something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference