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

Completed
Push — master ( 024700...341ac6 )
by Jérémiah
04:30
created

NodeFieldDefinition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 40.63 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 0
dl 13
loc 32
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toMappingDefinition() 3 18 5
A cleanIdFetcher() 10 10 2

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\Relay\Node;
13
14
use GraphQL\Type\Definition\Config;
15
use Overblog\GraphQLBundle\Definition\Builder\MappingInterface;
16
use Overblog\GraphQLBundle\Definition\Type;
17
18
class NodeFieldDefinition implements MappingInterface
19
{
20 8
    public function toMappingDefinition(array $config)
21
    {
22 8 View Code Duplication
        if (!isset($config['idFetcher']) || !is_string($config['idFetcher'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
23 2
            throw new \InvalidArgumentException('Node "idFetcher" config is invalid.');
24
        }
25
26 6
        $idFetcher = $this->cleanIdFetcher($config['idFetcher']);
27 6
        $nodeInterfaceType = isset($config['nodeInterfaceType']) && is_string($config['nodeInterfaceType']) ? $config['nodeInterfaceType'] : null;
28
29
        return [
30 6
            'description' => 'Fetches an object given its ID',
31 6
            'type' => $nodeInterfaceType,
32
            'args' => [
33 6
                'id' => ['type' => 'ID!', 'description' => 'The ID of an object'],
34 6
            ],
35 6
            'resolve' => "@=resolver('relay_node_field', [args, idFetcherCallback($idFetcher)])",
36 6
        ];
37
    }
38
39 6 View Code Duplication
    private function cleanIdFetcher($idFetcher)
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...
40
    {
41 6
        $cleanIdFetcher = $idFetcher;
42
43 6
        if (0 === strpos($idFetcher, '@=')) {
44 4
            $cleanIdFetcher = substr($idFetcher, 2);
45 4
        }
46
47 6
        return $cleanIdFetcher;
48
    }
49
}
50