| Conditions | 42 |
| Paths | 42 |
| Total Lines | 74 |
| Code Lines | 57 |
| 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 |
||
| 67 | public static function fromType(string $type): Primitive |
||
| 68 | { |
||
| 69 | switch (strtolower(trim($type))) { |
||
| 70 | |||
| 71 | case 'bytea': |
||
| 72 | return Primitive::Binary(); |
||
| 73 | |||
| 74 | case 'boolean': |
||
| 75 | case 'bool': |
||
| 76 | return Primitive::Boolean(); |
||
| 77 | |||
| 78 | case 'date': |
||
| 79 | case 'timestamp': |
||
| 80 | return Primitive::Date(); |
||
| 81 | |||
| 82 | case 'time': |
||
| 83 | case 'timetz': |
||
| 84 | return Primitive::TimeOfDay(); |
||
| 85 | |||
| 86 | case 'timestamptz': |
||
| 87 | return Primitive::DateTimeOffset(); |
||
| 88 | case 'numeric': |
||
| 89 | case 'decimal': |
||
| 90 | return Primitive::Decimal(); |
||
| 91 | |||
| 92 | case 'float8': |
||
| 93 | return Primitive::Double(); |
||
| 94 | |||
| 95 | case 'interval': |
||
| 96 | return Primitive::Duration(); |
||
| 97 | |||
| 98 | case 'uuid': |
||
| 99 | return Primitive::Guid(); |
||
| 100 | |||
| 101 | case 'int2': |
||
| 102 | case 'smallint': |
||
| 103 | case 'smallserial': |
||
| 104 | case 'serial2': |
||
| 105 | return Primitive::Int16(); |
||
| 106 | |||
| 107 | case 'int': |
||
| 108 | case 'int4': |
||
| 109 | case 'integer': |
||
| 110 | case 'serial4': |
||
| 111 | case 'serial': |
||
| 112 | return Primitive::Int32(); |
||
| 113 | |||
| 114 | case 'int8': |
||
| 115 | case 'bigint': |
||
| 116 | case 'bigserial': |
||
| 117 | case 'serial8': |
||
| 118 | return Primitive::Int64(); |
||
| 119 | |||
| 120 | case 'float4': |
||
| 121 | case 'real': |
||
| 122 | return Primitive::Single(); |
||
| 123 | |||
| 124 | case 'varchar': |
||
| 125 | case 'text': |
||
| 126 | case 'cidr': |
||
| 127 | case 'inet': |
||
| 128 | case 'json': |
||
| 129 | case 'jsonb': |
||
| 130 | case 'macaddr': |
||
| 131 | case 'macaddr8': |
||
| 132 | case 'char': |
||
| 133 | case 'tsquery': |
||
| 134 | case 'tsvector': |
||
| 135 | case 'xml': |
||
| 136 | case 'bpchar': |
||
| 137 | return Primitive::String(); |
||
| 138 | } |
||
| 139 | |||
| 140 | throw new EntityException("Not described type found: $type"); |
||
| 141 | } |
||
| 167 |