| Conditions | 6 |
| Paths | 16 |
| Total Lines | 52 |
| 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 |
||
| 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 | $queryPart = static::QueryPartFromRefReturn( |
||
| 43 | $db, |
||
| 44 | $ref->getMethod($methodName)->getReturnType(), |
||
| 45 | $prop |
||
| 46 | ); |
||
| 47 | if (false === in_array($prop, $nullables, true)) { |
||
| 48 | $queryPart .= ' NOT NULL'; |
||
| 49 | } |
||
| 50 | |||
| 51 | $queryParts[] = $queryPart; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $primaryKeyCols = []; |
||
| 56 | foreach ($type::DaftObjectIdProperties() as $col) { |
||
| 57 | $primaryKeyCols[] = $db->escapeIdentifier($col); |
||
| 58 | } |
||
| 59 | |||
| 60 | if (count($primaryKeyCols) > 0) { |
||
| 61 | $queryParts[] = |
||
| 62 | 'PRIMARY KEY (' . |
||
| 63 | implode(',', $primaryKeyCols) . |
||
| 64 | ')'; |
||
| 65 | } |
||
| 66 | |||
| 67 | $query .= |
||
| 68 | implode(',', $queryParts) . |
||
| 69 | ');'; |
||
| 70 | |||
| 71 | $db->safeQuery($query); |
||
| 72 | } |
||
| 115 |