Conditions | 5 |
Paths | 7 |
Total Lines | 60 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
29 | public function analyze() |
||
30 | { |
||
31 | /** @var RealMetadata[] $metadataCollection Set pointer to global metadata collection */ |
||
32 | $metadataCollection = []; |
||
33 | |||
34 | // Iterate all structures, parents first |
||
35 | foreach ($this->getEntities() as $columnRow) { |
||
36 | $table = $columnRow['Table']; |
||
37 | |||
38 | /** @var RealMetadata $metadata Set pointer to metadata instance by table name */ |
||
39 | $metadata = &$metadataCollection[$table]; |
||
40 | |||
41 | // If this is a new table - create metadata instance |
||
42 | if (null === $metadata) { |
||
43 | $entity = $this->entityName($table); |
||
44 | $metadata = new $this->metadataClass($this->fullEntityName($entity)); |
||
45 | $metadata->entity = $entity; |
||
46 | $metadata->entityName = $table; |
||
47 | |||
48 | // // Get old AR collections of metadata |
||
49 | // $arEntity = '\samson\activerecord\\'.$metadata->entity; |
||
50 | // if (class_exists($arEntity)) { |
||
51 | // foreach ($arEntity::$_attributes as $attribute) { |
||
52 | // $metadata->arAttributes[$this->fieldName($attribute)] = $attribute; |
||
53 | // } |
||
54 | // foreach ($arEntity::$_table_attributes as $attribute) { |
||
55 | // $metadata->arTableAttributes[$this->fieldName($attribute)] = $attribute; |
||
56 | // } |
||
57 | // foreach ($arEntity::$_types as $attribute => $oldType) { |
||
58 | // $metadata->arTypes[$attribute] = $oldType; |
||
59 | // } |
||
60 | // $metadata->arSelect = $arEntity::$_sql_select; |
||
61 | // $metadata->arMap = $arEntity::$_map; |
||
62 | // $metadata->arFrom = $arEntity::$_sql_from; |
||
63 | // $metadata->arGroup = $arEntity::$_own_group; |
||
64 | // $metadata->arRelationAlias = $arEntity::$_relation_alias; |
||
65 | // $metadata->arRelationType = $arEntity::$_relation_type; |
||
66 | // $metadata->arRelations = $arEntity::$_relations; |
||
67 | // } |
||
68 | } |
||
69 | |||
70 | // Generate correct PSR-2 field name |
||
71 | $fieldName = $this->fieldName($columnRow['Field']); |
||
72 | if (!in_array($fieldName, $metadata->fields)) { |
||
73 | $metadata->fieldNames[$fieldName] = $columnRow['Field']; |
||
74 | $metadata->fields[$columnRow['Field']] = $fieldName; |
||
75 | $metadata->types[$columnRow['Field']] = $this->databaseTypeToPHP($columnRow['Type']); |
||
76 | $metadata->internalTypes[$columnRow['Field']] = $columnRow['Type']; |
||
77 | $metadata->defaults[$columnRow['Field']] = $columnRow['Default']; |
||
78 | $metadata->nullable[$columnRow['Field']] = $columnRow['Null']; |
||
79 | |||
80 | // Store entity primary field |
||
81 | if (strtolower($columnRow['Key']) === 'pri') { |
||
82 | $metadata->primaryField = $columnRow['Field']; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | return $metadataCollection; |
||
88 | } |
||
89 | |||
161 | //[PHPCOMPRESSOR(remove,end)] |