| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| 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 |
||
| 11 | public function testGraphql() |
||
| 12 | { |
||
| 13 | $schema = new Schema(); |
||
| 14 | $fluid = new TdbmFluidSchema($schema); |
||
| 15 | |||
| 16 | $posts = $fluid->table('posts'); |
||
| 17 | |||
| 18 | $column = $posts->column('foo'); |
||
| 19 | $columnOptions = $column->integer(); |
||
| 20 | |||
| 21 | $graphqlOptions = $columnOptions->graphqlField(); |
||
| 22 | |||
| 23 | $graphqlOptions->fieldName('bar') |
||
| 24 | ->logged(true) |
||
| 25 | ->right('CAN_EDIT') |
||
| 26 | ->failWith(null); |
||
| 27 | |||
| 28 | $this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\") |
||
| 29 | @TheCodingMachine\GraphQLite\Annotations\Logged |
||
| 30 | @TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\") |
||
| 31 | @TheCodingMachine\GraphQLite\Annotations\FailWith(null)", $schema->getTable('posts')->getColumn('foo')->getComment()); |
||
| 32 | |||
| 33 | $graphqlOptions->logged(false) |
||
| 34 | ->outputType('ID'); |
||
| 35 | |||
| 36 | |||
| 37 | $this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\") |
||
| 38 | @TheCodingMachine\GraphQLite\Annotations\FailWith(null) |
||
| 39 | @TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\", outputType = \"ID\")", $schema->getTable('posts')->getColumn('foo')->getComment()); |
||
| 40 | |||
| 41 | $this->assertSame($columnOptions, $graphqlOptions->endGraphql()); |
||
| 42 | |||
| 43 | $column2 = $graphqlOptions->column('foo'); |
||
| 44 | $this->assertSame($column2, $column); |
||
| 45 | |||
| 46 | $this->assertContains('@TheCodingMachine\GraphQLite\Annotations\Type', $schema->getTable('posts')->getOptions()['comment']); |
||
| 47 | |||
| 48 | $idColumn = $posts->id()->graphqlField(); |
||
|
|
|||
| 49 | $this->assertContains('outputType = "ID"', $schema->getTable('posts')->getColumn('id')->getComment()); |
||
| 50 | |||
| 51 | $users = $fluid->table('users'); |
||
| 52 | $uuidColumn = $users->uuid()->graphqlField(); |
||
| 53 | $this->assertContains('outputType = "ID"', $schema->getTable('users')->getColumn('uuid')->getComment()); |
||
| 54 | |||
| 55 | $products = $fluid->table('products'); |
||
| 56 | $graphqlField = $products->uuid() |
||
| 57 | ->column('user_id')->references('users')->graphqlField(); |
||
| 58 | $this->assertNotContains('outputType = "ID"', $schema->getTable('products')->getColumn('user_id')->getComment()); |
||
| 59 | |||
| 60 | $this->assertSame('products', $graphqlField->then()->getDbalTable()->getName()); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.