| Conditions | 9 |
| Paths | 10 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 1 |
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 | $metadata = new $this->metadataClass; |
||
| 44 | $metadata->entity = $this->entityName($table); |
||
| 45 | $metadata->entityName = $table; |
||
| 46 | $metadata->entityClassName = $this->fullEntityName($metadata->entity); |
||
| 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[$this->fieldName($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 | |||
| 79 | // Store entity primary field |
||
| 80 | if (strtolower($columnRow['Key']) === 'pri') { |
||
| 81 | $metadata->primaryField = $columnRow['Field']; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | return $metadataCollection; |
||
| 87 | } |
||
| 88 | |||
| 160 | //[PHPCOMPRESSOR(remove,end)] |