Conditions | 11 |
Paths | 64 |
Total Lines | 53 |
Code Lines | 33 |
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 |
||
11 | public function execute($space, $params) |
||
12 | { |
||
13 | $index = $space->castIndex($params); |
||
14 | if (is_null($index)) { |
||
15 | throw new Exception("No valid index for ".json_encode($params)); |
||
16 | } |
||
17 | |||
18 | $values = $space->getIndexValues($index, $params); |
||
19 | |||
20 | $tuple = []; |
||
21 | $schema = $space->getMapper()->getSchema(); |
||
22 | |||
23 | foreach ($space->getFormat() as $i => $info) { |
||
24 | $name = $info['name']; |
||
25 | if (!array_key_exists($name, $params)) { |
||
26 | $params[$name] = null; |
||
27 | } |
||
28 | |||
29 | $params[$name] = $schema->formatValue($info['type'], $params[$name]); |
||
30 | if (is_null($params[$name])) { |
||
31 | if (!$space->isPropertyNullable($name)) { |
||
32 | $params[$name] = $schema->getDefaultValue($info['type']); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | $tuple[$i] = $params[$name]; |
||
37 | } |
||
38 | |||
39 | $primary = $space->getPrimaryIndex(); |
||
40 | $sequence = 0; |
||
41 | if (count($primary['parts']) == 1) { |
||
42 | $key = $space->getFormat()[$primary['parts'][0][0]]['name']; |
||
43 | if (!array_key_exists($key, $params) || !$params[$key]) { |
||
44 | $sequence = 1; |
||
45 | $space->getMapper() |
||
46 | ->getPlugin(Sequence::class) |
||
47 | ->initializeSequence($space); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | $tuple = $this($space->getName(), $index, $values, $tuple, $sequence); |
||
52 | |||
53 | if (is_string($tuple)) { |
||
54 | throw new Exception($tuple); |
||
55 | } |
||
56 | |||
57 | $key = []; |
||
58 | $format = $space->getFormat(); |
||
59 | foreach ($primary['parts'] as $part) { |
||
60 | $key[$format[$part[0]]['name']] = $tuple[$part[0]]; |
||
61 | } |
||
62 | return $key; |
||
63 | } |
||
64 | |||
104 |