Conditions | 11 |
Paths | 11 |
Total Lines | 38 |
Code Lines | 22 |
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 |
||
53 | private function initCols(ITypeControl $typeControl) |
||
54 | { |
||
55 | $numFields = pg_num_fields($this->handler); |
||
56 | if ($numFields < 0 || $numFields === null) { |
||
57 | throw new ResultException('Error retrieving number of fields of the result.'); |
||
58 | } |
||
59 | $this->columns = []; |
||
60 | $this->colNameMap = []; |
||
61 | $this->colTypes = []; |
||
62 | for ($i = 0; $i < $numFields; $i++) { |
||
63 | /* NOTE: pg_field_type() cannot be used for simplicity - multiple types of the same name might exist in |
||
64 | * different schemas. Thus, the only reasonable way to recognize the types is using their OIDs, |
||
65 | * returned by pg_field_type_oid(). Up to some extreme cases, within a given database, the same OID |
||
66 | * will always refer to the same data type. |
||
67 | */ |
||
68 | $name = pg_field_name($this->handler, $i); |
||
69 | if ($name === false || $name === null) { // NOTE: besides false, pg_field_name() might return NULL on error |
||
70 | throw new ResultException("Error retrieving name of result column $i."); |
||
71 | } |
||
72 | if ($name == '?column?') { |
||
73 | $name = null; |
||
74 | } |
||
75 | $typeOid = pg_field_type_oid($this->handler, $i); |
||
76 | if ($typeOid === false || $typeOid === null) { // NOTE: besides false, pg_field_type_oid() might return NULL on error |
||
77 | throw new ResultException("Error retrieving type OID of result column $i."); |
||
78 | } |
||
79 | // NOTE: the type dictionary may change during the iterations, so taky a fresh one every time |
||
80 | $typeDictionary = $typeControl->getTypeDictionary(); |
||
81 | $type = $typeDictionary->requireTypeByOid($typeOid); |
||
82 | |||
83 | $this->columns[] = new Column($this, $i, $name, $type); |
||
84 | if ($name !== null) { |
||
85 | $this->colNameMap[$name] = (isset($this->colNameMap[$name]) ? Tuple::AMBIGUOUS_COL : $i); |
||
86 | } |
||
87 | |||
88 | $this->colTypes[] = $type; |
||
89 | } |
||
90 | } |
||
91 | |||
158 |