TdbmFluidColumnGraphqlOptionsTest::testGraphql()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace TheCodingMachine\FluidSchema;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use Doctrine\DBAL\Types\Type;
7
use PHPUnit\Framework\TestCase;
8
9
class TdbmFluidColumnGraphqlOptionsTest extends TestCase
10
{
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();
0 ignored issues
show
Unused Code introduced by
$idColumn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
        $this->assertContains('outputType = "ID"', $schema->getTable('posts')->getColumn('id')->getComment());
50
51
        $users = $fluid->table('users');
52
        $uuidColumn = $users->uuid()->graphqlField();
0 ignored issues
show
Unused Code introduced by
$uuidColumn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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