| Conditions | 21 |
| Paths | 1561 |
| Total Lines | 106 |
| Code Lines | 77 |
| 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 |
||
| 50 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 51 | { |
||
| 52 | foreach ($this->schema->getRoles() as $role) { |
||
| 53 | $output->write("<fg=magenta>[{$role}</>"); |
||
| 54 | $alias = $this->schema->resolveAlias($role); |
||
| 55 | // alias |
||
| 56 | if ($alias !== null && $alias !== $role) { |
||
| 57 | $output->write("=><fg=magenta>{$alias}</>"); |
||
| 58 | } |
||
| 59 | // table |
||
| 60 | $output->write("<fg=magenta>]</>"); |
||
| 61 | |||
| 62 | // database |
||
| 63 | $database = $this->schema->define($role, Schema::DATABASE); |
||
| 64 | $table = $this->schema->define($role, Schema::TABLE); |
||
| 65 | if ($database !== null) { |
||
| 66 | $output->write(" :: <fg=green>{$database}</>.<fg=green>{$table}</>"); |
||
| 67 | } |
||
| 68 | $output->writeln(''); |
||
| 69 | |||
| 70 | // Entity |
||
| 71 | $entity = $this->schema->define($role, Schema::ENTITY); |
||
| 72 | $output->write(' Entity : '); |
||
| 73 | $output->writeln($entity === null ? 'no entity' : "<fg=blue>{$entity}</>"); |
||
| 74 | // Mapper |
||
| 75 | $mapper = $this->schema->define($role, Schema::MAPPER); |
||
| 76 | $output->write(' Mapper : '); |
||
| 77 | $output->writeln($mapper === null ? 'no mapper' : "<fg=blue>{$mapper}</>"); |
||
| 78 | // Constrain |
||
| 79 | $constrain = $this->schema->define($role, Schema::CONSTRAIN); |
||
| 80 | $output->write(' Constrain : '); |
||
| 81 | $output->writeln($constrain === null ? 'no constrain' : "<fg=blue>{$constrain}</>"); |
||
| 82 | // Repository |
||
| 83 | $repository = $this->schema->define($role, Schema::REPOSITORY); |
||
| 84 | $output->write(' Repository : '); |
||
| 85 | $output->writeln($repository === null ? 'no repository' : "<fg=blue>{$repository}</>"); |
||
| 86 | // PK |
||
| 87 | $pk = $this->schema->define($role, Schema::PRIMARY_KEY); |
||
| 88 | $output->write(' Primary key: '); |
||
| 89 | $output->writeln($pk === null ? 'no primary key' : "<fg=green>{$pk}</>"); |
||
| 90 | // Fields |
||
| 91 | $columns = $this->schema->define($role, Schema::COLUMNS); |
||
| 92 | $output->writeln(" Fields :"); |
||
| 93 | $output->writeln(" (<fg=cyan>property</> -> <fg=green>db.field</> -> <fg=blue>typecast</>)"); |
||
| 94 | $types = $this->schema->define($role, Schema::TYPECAST); |
||
| 95 | foreach ($columns as $property => $field) { |
||
| 96 | $typecast = $types[$property] ?? $types[$field] ?? null; |
||
| 97 | $output->write(" <fg=cyan>{$property}</> -> <fg=green>{$field}</>"); |
||
| 98 | if ($typecast !== null) { |
||
| 99 | $output->write(" -> <fg=blue>{$typecast}</>"); |
||
| 100 | } |
||
| 101 | $output->writeln(''); |
||
| 102 | } |
||
| 103 | |||
| 104 | // Relations |
||
| 105 | $relations = $this->schema->define($role, Schema::RELATIONS); |
||
| 106 | if (count($relations) > 0) { |
||
| 107 | $output->writeln(' Relations :'); |
||
| 108 | foreach ($relations as $field => $relation) { |
||
| 109 | $type = self::STR_RELATION[$relation[Relation::TYPE] ?? ''] ?? '?'; |
||
| 110 | $target = $relation[Relation::TARGET] ?? '?'; |
||
| 111 | $loading = self::STR_PREFETCH_MODE[$relation[Relation::LOAD] ?? ''] ?? '?'; |
||
| 112 | $relSchema = $relation[Relation::SCHEMA]; |
||
| 113 | $innerKey = $relSchema[Relation::INNER_KEY] ?? '?'; |
||
| 114 | $outerKey = $relSchema[Relation::OUTER_KEY] ?? '?'; |
||
| 115 | $where = $relSchema[Relation::WHERE] ?? []; |
||
| 116 | $cascade = $relSchema[Relation::CASCADE] ?? null; |
||
| 117 | $cascadeStr = $cascade ? 'cascaded' : 'not cascaded'; |
||
| 118 | $nullable = $relSchema[Relation::NULLABLE] ?? null; |
||
| 119 | $nullableStr = $nullable ? 'nullable' : ($nullable === false ? 'not null' : 'n/a'); |
||
| 120 | $morphKey = $relSchema[Relation::MORPH_KEY] ?? null; |
||
| 121 | // Many-To-Many relation(s) options |
||
| 122 | $mmInnerKey = $relSchema[Relation::THROUGH_INNER_KEY] ?? '?'; |
||
| 123 | $mmOuterKey = $relSchema[Relation::THROUGH_OUTER_KEY] ?? '?'; |
||
| 124 | $mmEntity = $relSchema[Relation::THROUGH_ENTITY] ?? null; |
||
| 125 | $mmWhere = $relSchema[Relation::THROUGH_WHERE] ?? []; |
||
| 126 | |||
| 127 | $output->write( |
||
| 128 | " <fg=magenta>{$role}</>-><fg=cyan>{$field}</> " |
||
| 129 | . "{$type} <fg=magenta>{$target}</> {$loading} load" |
||
| 130 | ); |
||
| 131 | if ($morphKey !== null) { |
||
| 132 | $output->writeln(" Morphed key: <fg=green>{$morphKey}</>"); |
||
| 133 | } |
||
| 134 | $output->writeln(" <fg=yellow>{$cascadeStr}</>"); |
||
| 135 | $output->write(" {$nullableStr} <fg=green>{$table}</>.<fg=green>{$innerKey}</> <="); |
||
| 136 | if ($mmEntity !== null) { |
||
| 137 | $output->write(" <fg=magenta>{$mmEntity}</>.<fg=green>{$mmInnerKey}</>"); |
||
| 138 | $output->write("|"); |
||
| 139 | $output->write("<fg=magenta>{$mmEntity}</>.<fg=green>{$mmOuterKey}</> "); |
||
| 140 | } |
||
| 141 | $output->writeln("=> <fg=magenta>{$target}</>.<fg=green>{$outerKey}</> "); |
||
| 142 | if (count($where)) { |
||
| 143 | $output->write(" Where:"); |
||
| 144 | $output->writeln(str_replace(["\r\n", "\n"], "\n ", "\n" . print_r($where, 1))); |
||
| 145 | } |
||
| 146 | if (count($mmWhere)) { |
||
| 147 | $output->write(" Through where:"); |
||
| 148 | $output->writeln(str_replace(["\r\n", "\n"], "\n ", "\n" . print_r($mmWhere, 1))); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } else { |
||
| 152 | $output->writeln(' No relations'); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | return ExitCode::OK; |
||
| 156 | } |
||
| 158 |