Conditions | 10 |
Paths | 28 |
Total Lines | 38 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function getHash() |
||
49 | { |
||
50 | $hash = []; |
||
51 | foreach ($this->metadata->getAttributes() as $key => $attrMeta) { |
||
52 | $value = $this->get($key); |
||
53 | if (null === $value) { |
||
54 | $hash[$key] = $value; |
||
55 | continue; |
||
56 | } |
||
57 | switch ($attrMeta->dataType) { |
||
58 | case 'date': |
||
59 | $value = $value->getTimestamp(); |
||
60 | break; |
||
61 | case 'object': |
||
62 | $value = (array) $object; |
||
|
|||
63 | ksort($value); |
||
64 | break; |
||
65 | case 'mixed': |
||
66 | $value = serialize($value); |
||
67 | break; |
||
68 | case 'array': |
||
69 | sort($value); |
||
70 | break; |
||
71 | } |
||
72 | $hash[$key] = $value; |
||
73 | } |
||
74 | foreach ($this->metadata->getEmbeds() as $key => $embbedPropMeta) { |
||
75 | if (true === $embbedPropMeta->isOne()) { |
||
76 | $embed = $this->get($key); |
||
77 | $hash[$key] = (null === $embed) ? null : $embed->getHash(); |
||
78 | } else { |
||
79 | $collection = $this->get($key); |
||
80 | $hash[$key] = $collection->getHash(); |
||
81 | } |
||
82 | } |
||
83 | ksort($hash); |
||
84 | return md5(serialize($hash)); |
||
85 | } |
||
86 | |||
110 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.