| Conditions | 8 |
| Paths | 20 |
| Total Lines | 58 |
| Code Lines | 35 |
| 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 | $queryPart = static::QueryPartFromRefReturn( |
||
| 48 | $db, |
||
| 49 | $refReturn, |
||
| 50 | $prop |
||
| 51 | ); |
||
| 52 | if (false === in_array($prop, $nullables, true)) { |
||
| 53 | $queryPart .= ' NOT NULL'; |
||
| 54 | } |
||
| 55 | |||
| 56 | $queryParts[] = $queryPart; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | $primaryKeyCols = []; |
||
| 62 | foreach ($type::DaftObjectIdProperties() as $col) { |
||
| 63 | $primaryKeyCols[] = $db->escapeIdentifier($col); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (count($primaryKeyCols) > 0) { |
||
| 67 | $queryParts[] = |
||
| 68 | 'PRIMARY KEY (' . |
||
| 69 | implode(',', $primaryKeyCols) . |
||
| 70 | ')'; |
||
| 71 | } |
||
| 72 | |||
| 73 | $query .= |
||
| 74 | implode(',', $queryParts) . |
||
| 75 | ');'; |
||
| 76 | |||
| 77 | $db->safeQuery($query); |
||
| 78 | } |
||
| 120 |