Conditions | 7 |
Paths | 16 |
Total Lines | 54 |
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 |
||
20 | protected function __construct(string $type, EasyDB $db) |
||
21 | { |
||
22 | parent::__construct($type, $db); |
||
23 | |||
24 | /** |
||
25 | * @var DefinesOwnIdPropertiesInterface $type |
||
26 | */ |
||
27 | $type = $type; |
||
28 | |||
29 | $query = |
||
30 | 'CREATE TABLE ' . |
||
31 | $db->escapeIdentifier($this->DaftObjectDatabaseTable()) . |
||
32 | ' ('; |
||
33 | |||
34 | $queryParts = []; |
||
35 | |||
36 | $ref = new ReflectionClass($type); |
||
37 | $nullables = $type::DaftObjectNullableProperties(); |
||
38 | |||
39 | foreach ($type::DaftObjectProperties() as $i => $prop) { |
||
40 | $methodName = 'Get' . ucfirst($prop); |
||
41 | if (true === $ref->hasMethod($methodName)) { |
||
42 | $refReturn = $ref->getMethod($methodName)->getReturnType(); |
||
43 | if ( |
||
44 | ($refReturn instanceof ReflectionType) && |
||
45 | true |
||
46 | ) { |
||
47 | $queryParts[] = static::QueryPartFromRefReturn( |
||
48 | $db, |
||
49 | $refReturn, |
||
50 | $prop, |
||
51 | $nullables |
||
52 | ); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | |||
57 | $primaryKeyCols = []; |
||
58 | foreach ($type::DaftObjectIdProperties() as $col) { |
||
59 | $primaryKeyCols[] = $db->escapeIdentifier($col); |
||
60 | } |
||
61 | |||
62 | if (count($primaryKeyCols) > 0) { |
||
63 | $queryParts[] = |
||
64 | 'PRIMARY KEY (' . |
||
65 | implode(',', $primaryKeyCols) . |
||
66 | ')'; |
||
67 | } |
||
68 | |||
69 | $query .= |
||
70 | implode(',', $queryParts) . |
||
71 | ');'; |
||
72 | |||
73 | $db->safeQuery($query); |
||
74 | } |
||
120 |