| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 20 | public function testAddField() |
||
| 21 | { |
||
| 22 | $fieldsData = [ |
||
| 23 | 'id' => [ |
||
| 24 | 'type' => new IntType() |
||
| 25 | ] |
||
| 26 | ]; |
||
| 27 | $config = new ObjectTypeConfig([ |
||
| 28 | 'name' => 'UserType', |
||
| 29 | 'fields' => $fieldsData |
||
| 30 | ]); |
||
| 31 | |||
| 32 | $this->assertTrue($config->hasFields()); |
||
| 33 | $idField = new Field(['name' => 'id', 'type' => new IntType()]); |
||
| 34 | $idField->getName(); |
||
| 35 | $nameField = new Field(['name' => 'name', 'type' => new StringType()]); |
||
| 36 | |||
| 37 | $this->assertEquals([ |
||
| 38 | 'id' => $idField, |
||
| 39 | ], $config->getFields()); |
||
| 40 | |||
| 41 | $config->addField($nameField); |
||
| 42 | $this->assertEquals([ |
||
| 43 | 'id' => $idField, |
||
| 44 | 'name' => $nameField |
||
| 45 | ], $config->getFields()); |
||
| 46 | |||
| 47 | $config->removeField('id'); |
||
| 48 | $this->assertEquals([ |
||
| 49 | 'name' => $nameField |
||
| 50 | ], $config->getFields()); |
||
| 51 | |||
| 52 | $config->addFields([ |
||
| 53 | 'id' => $idField |
||
| 54 | ]); |
||
| 55 | $this->assertEquals([ |
||
| 56 | 'name' => $nameField, |
||
| 57 | 'id' => $idField, |
||
| 58 | ], $config->getFields()); |
||
| 59 | |||
| 60 | $levelField = new Field(['name' => 'level', 'type' => new IntType()]); |
||
| 61 | $config->addFields([ |
||
| 62 | $levelField |
||
| 63 | ]); |
||
| 64 | $this->assertEquals([ |
||
| 65 | 'name' => $nameField, |
||
| 66 | 'id' => $idField, |
||
| 67 | 'level' => $levelField, |
||
| 68 | ], $config->getFields()); |
||
| 69 | |||
| 70 | } |
||
| 71 | |||
| 73 |