| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| 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 | // create Heroes Table |
||
| 40 | $table = $schema->createTable('heroes'); |
||
| 41 | $table->addColumn('id', 'integer', [ |
||
| 42 | 'autoincrement' => true, |
||
| 43 | ]); |
||
| 44 | $table->addColumn('name', 'string'); |
||
| 45 | $table->addColumn('code', 'string'); |
||
| 46 | $table->setPrimaryKey(['id']); |
||
| 47 | $table->addUniqueIndex(['code']); |
||
| 48 | |||
| 49 | // create Users Table |
||
| 50 | $table = $schema->createTable('users'); |
||
| 51 | $table->addColumn('id', 'integer', [ |
||
| 52 | 'autoincrement' => true, |
||
| 53 | ]); |
||
| 54 | $table->addColumn('first', 'string'); |
||
| 55 | $table->addColumn('last', 'string'); |
||
| 56 | $table->addColumn('code', 'string'); |
||
| 57 | $table->setPrimaryKey(['id']); |
||
| 58 | $table->addUniqueIndex(['code']); |
||
| 59 | |||
| 60 | $currentSchema = $this->connection->getSchemaManager()->createSchema(); |
||
| 61 | $sql = $currentSchema->getMigrateToSql($schema, $this->connection->getDatabasePlatform()); |
||
| 62 | array_walk($sql, function ($script) { |
||
| 63 | $this->connection->executeUpdate($script); |
||
| 64 | }); |
||
| 65 | |||
| 66 | parent::setUp(); |
||
| 67 | $this->emitter = new BlackHole(); |
||
| 68 | $utility = new WriterUtility($this->connection); |
||
| 69 | $this->pipeline = (new PipelineBuilder($this->emitter)) |
||
| 70 | ->delete(['id']) |
||
| 71 | ->filter(new class implements FilterCallbackInterface |
||
| 72 | { |
||
| 73 | public function __invoke(DataBagInterface $dataBag): bool |
||
| 74 | { |
||
| 75 | return !empty($dataBag['code']); |
||
| 76 | } |
||
| 77 | }) |
||
| 78 | ->map('name', new class implements MapperCallbackInterface |
||
| 79 | { |
||
| 80 | public function __invoke($value, DataBagInterface $dataBag) |
||
| 81 | { |
||
| 82 | return $dataBag['first'] . ' ' . $dataBag['last']; |
||
| 83 | } |
||
| 84 | }) |
||
| 85 | ->addSection(new Write( |
||
| 86 | 'heroes_write', |
||
| 87 | $this->connection, |
||
| 88 | 'heroes', |
||
| 89 | $utility, |
||
| 90 | new UniqueIndexStrategy('heroes', $utility), |
||
| 91 | $this->emitter |
||
| 92 | )) |
||
| 93 | ->build(); |
||
| 94 | } |
||
| 95 | |||
| 165 |