| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| 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 |
||
| 33 | protected function setUp(): void |
||
| 34 | { |
||
| 35 | $params = require __DIR__ . '/config/db-config.php'; |
||
| 36 | $this->connection = DriverManager::getConnection($params); |
||
| 37 | |||
| 38 | $schema = new Schema(); |
||
| 39 | |||
| 40 | // create teams Table |
||
| 41 | $table = $schema->createTable('teams'); |
||
| 42 | $table->addColumn('id', 'integer', [ |
||
| 43 | 'autoincrement' => true, |
||
| 44 | ]); |
||
| 45 | $table->addColumn('name', 'string'); |
||
| 46 | $table->setPrimaryKey(['id']); |
||
| 47 | $table->addUniqueIndex(['name']); |
||
| 48 | |||
| 49 | // create heroes Table |
||
| 50 | $table = $schema->createTable('heroes'); |
||
| 51 | $table->addColumn('id', 'integer', [ |
||
| 52 | 'autoincrement' => true, |
||
| 53 | ]); |
||
| 54 | $table->addColumn('name', 'string'); |
||
| 55 | $table->addColumn('code', 'string'); |
||
| 56 | $table->addColumn('team_id', 'integer'); |
||
| 57 | $table->addForeignKeyConstraint('teams', ['team_id'], ['id']); |
||
| 58 | $table->setPrimaryKey(['id']); |
||
| 59 | $table->addUniqueIndex(['code']); |
||
| 60 | |||
| 61 | $currentSchema = $this->connection->getSchemaManager()->createSchema(); |
||
| 62 | $sql = $currentSchema->getMigrateToSql($schema, $this->connection->getDatabasePlatform()); |
||
| 63 | array_walk($sql, function ($script) { |
||
| 64 | $this->connection->executeUpdate($script); |
||
| 65 | }); |
||
| 66 | |||
| 67 | parent::setUp(); |
||
| 68 | $this->emitter = new BlackHole(); |
||
| 69 | $utility = new WriterUtility($this->connection); |
||
| 70 | $this->pipeline = (new PipelineBuilder($this->emitter)) |
||
| 71 | ->cp('name', 'hero_name') // copy to tmp hero_name |
||
| 72 | ->cp('team', 'name') // copy team to name |
||
| 73 | ->addSection(new Write( |
||
| 74 | 'teams_write', |
||
| 75 | $this->connection, |
||
| 76 | 'teams', |
||
| 77 | $utility, |
||
| 78 | new UniqueIndexStrategy('teams', $utility), |
||
| 79 | $this->emitter, |
||
| 80 | new class implements AutoIncrementCallbackInterface |
||
| 81 | { |
||
| 82 | public function __invoke(int $id, DataBagInterface $dataBag) |
||
| 83 | { |
||
| 84 | $dataBag['team_id'] = $id; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | )) |
||
| 88 | ->cp('hero_name', 'name') // copy hero_name back to name |
||
| 89 | ->delete(['hero_name', 'team']) |
||
| 90 | ->addSection(new Write( |
||
| 91 | 'heroes_write', |
||
| 92 | $this->connection, |
||
| 93 | 'heroes', |
||
| 94 | $utility, |
||
| 95 | new UniqueIndexStrategy('heroes', $utility), |
||
| 96 | $this->emitter |
||
| 97 | )) |
||
| 98 | ->build(); |
||
| 99 | } |
||
| 100 | |||
| 194 |