Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#185)
by Jérémiah
07:57
created

TypeResolverTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 115
Duplicated Lines 37.39 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 43
loc 115
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A createResolver() 0 4 1
A getResolverSolutionsMapping() 0 7 1
A createObjectType() 0 4 1
A testAddNotSupportedSolution() 0 7 1
A testResolveKnownType() 0 7 1
A testResolveUnknownType() 0 4 1
A testWrongListOfWrappingType() 0 4 1
A testResolveWithListOfWrapper() 8 8 1
A testResolveWithNonNullWrapper() 8 8 1
A testResolveWithNonNullListOfWrapper() 9 9 1
A testResolveWitListOfNonNullWrapper() 9 9 1
A testResolveWitNonNullListOfNonNullWrapper() 0 10 1
A testResolveWitListOfListOfWrapper() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Tests\Resolver;
13
14
use GraphQL\Type\Definition\ListOfType;
15
use GraphQL\Type\Definition\NonNull;
16
use GraphQL\Type\Definition\ObjectType;
17
use Overblog\GraphQLBundle\Resolver\TypeResolver;
18
19
class TypeResolverTest extends AbstractResolverTest
20
{
21
    protected function createResolver()
22
    {
23
        return new TypeResolver();
24
    }
25
26
    protected function getResolverSolutionsMapping()
27
    {
28
        return [
29
            'Toto' => ['solutionFunc' => [$this, 'createObjectType'], 'solutionFuncArgs' => [['name' => 'Toto']]],
30
            'Tata' => ['solutionFunc' => [$this, 'createObjectType'], 'solutionFuncArgs' => [['name' => 'Tata']]],
31
        ];
32
    }
33
34
    public function createObjectType(array $config)
35
    {
36
        return new ObjectType($config);
37
    }
38
39
    /**
40
     * @expectedException \Overblog\GraphQLBundle\Resolver\UnsupportedResolverException
41
     * @expectedExceptionMessage Resolver "not-supported" must be "GraphQL\Type\Definition\Type" "stdClass" given.
42
     */
43
    public function testAddNotSupportedSolution()
44
    {
45
        $this->resolver->addSolution('not-supported', function () {
46
            return new \stdClass();
47
        });
48
        $this->resolver->getSolution('not-supported');
49
    }
50
51
    public function testResolveKnownType()
52
    {
53
        $type = $this->resolver->resolve('Toto');
54
55
        $this->assertInstanceOf(ObjectType::class, $type);
56
        $this->assertEquals('Toto', $type->name);
57
    }
58
59
    /**
60
     * @expectedException \Overblog\GraphQLBundle\Resolver\UnresolvableException
61
     */
62
    public function testResolveUnknownType()
63
    {
64
        $this->resolver->resolve('Fake');
65
    }
66
67
    /**
68
     * @expectedException \Overblog\GraphQLBundle\Resolver\UnresolvableException
69
     */
70
    public function testWrongListOfWrappingType()
71
    {
72
        $this->resolver->resolve('[Tata');
73
    }
74
75 View Code Duplication
    public function testResolveWithListOfWrapper()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        /** @var \GraphQL\Type\Definition\WrappingType $type */
78
        $type = $this->resolver->resolve('[Tata]');
79
80
        $this->assertInstanceOf(ListOfType::class, $type);
81
        $this->assertEquals('Tata', $type->getWrappedType());
82
    }
83
84 View Code Duplication
    public function testResolveWithNonNullWrapper()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        /** @var \GraphQL\Type\Definition\WrappingType $type */
87
        $type = $this->resolver->resolve('Toto!');
88
89
        $this->assertInstanceOf(NonNull::class, $type);
90
        $this->assertEquals('Toto', $type->getWrappedType());
91
    }
92
93 View Code Duplication
    public function testResolveWithNonNullListOfWrapper()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        /** @var \GraphQL\Type\Definition\WrappingType $type */
96
        $type = $this->resolver->resolve('[Toto]!');
97
98
        $this->assertInstanceOf(NonNull::class, $type);
99
        $this->assertInstanceOf(ListOfType::class, $type->getWrappedType());
100
        $this->assertEquals('Toto', $type->getWrappedType()->getWrappedType());
101
    }
102
103 View Code Duplication
    public function testResolveWitListOfNonNullWrapper()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        /** @var \GraphQL\Type\Definition\WrappingType $type */
106
        $type = $this->resolver->resolve('[Toto!]');
107
108
        $this->assertInstanceOf(ListOfType::class, $type);
109
        $this->assertInstanceOf(NonNull::class, $type->getWrappedType());
110
        $this->assertEquals('Toto', $type->getWrappedType()->getWrappedType());
111
    }
112
113
    public function testResolveWitNonNullListOfNonNullWrapper()
114
    {
115
        /** @var \GraphQL\Type\Definition\WrappingType $type */
116
        $type = $this->resolver->resolve('[Toto!]!');
117
118
        $this->assertInstanceOf(NonNull::class, $type);
119
        $this->assertInstanceOf(ListOfType::class, $type->getWrappedType());
120
        $this->assertInstanceOf(NonNull::class, $type->getWrappedType()->getWrappedType());
121
        $this->assertEquals('Toto', $type->getWrappedType()->getWrappedType()->getWrappedType());
122
    }
123
124 View Code Duplication
    public function testResolveWitListOfListOfWrapper()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        /** @var \GraphQL\Type\Definition\WrappingType $type */
127
        $type = $this->resolver->resolve('[[Toto]]');
128
129
        $this->assertInstanceOf(ListOfType::class, $type);
130
        $this->assertInstanceOf(ListOfType::class, $type->getWrappedType());
131
        $this->assertEquals('Toto', $type->getWrappedType()->getWrappedType());
132
    }
133
}
134