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 ( 14b721...0d2738 )
by Jérémiah
01:21
created

Paginator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 32.93 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 27
loc 82
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A backward() 13 13 1
A forward() 14 14 1
A auto() 0 10 3
A protectArgs() 0 4 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
namespace Overblog\GraphQLBundle\Relay\Connection;
4
5
use Overblog\GraphQLBundle\Definition\Argument;
6
use Overblog\GraphQLBundle\Relay\Connection\Output\Connection;
7
use Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder;
8
9
class Paginator
10
{
11
    /**
12
     * @var callable
13
     */
14
    private $fetcher;
15
16
    /**
17
     * @param callable $fetcher
18
     */
19 5
    public function __construct(callable $fetcher)
20
    {
21 5
        $this->fetcher = $fetcher;
22 5
    }
23
24
    /**
25
     * @param Argument|array $args
26
     * @param int|callable   $total
27
     *
28
     * @return Connection
29
     */
30 3 View Code Duplication
    public function backward($args, $total)
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...
31
    {
32 3
        $args = $this->protectArgs($args);
33 3
        $limit = $args['last'];
34 3
        $offset = max(0, ConnectionBuilder::getOffsetWithDefault($args['before'], $total) - $limit);
0 ignored issues
show
Bug introduced by
It seems like $total defined by parameter $total on line 30 can also be of type callable; however, Overblog\GraphQLBundle\R...:getOffsetWithDefault() does only seem to accept integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
36 3
        $entities = call_user_func($this->fetcher, $offset, $limit);
37
38 3
        return ConnectionBuilder::connectionFromArraySlice($entities, $args, [
39 3
            'sliceStart' => $offset,
40 3
            'arrayLength' => $total,
41 3
        ]);
42
    }
43
44
    /**
45
     * @param Argument|array $args
46
     *
47
     * @return Connection
48
     */
49 3 View Code Duplication
    public function forward($args)
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...
50
    {
51 3
        $args = $this->protectArgs($args);
52 3
        $limit = $args['first'];
53 3
        $offset = ConnectionBuilder::getOffsetWithDefault($args['after'], 0);
54
55
        // The extra fetched element is here to determine if there is a next page.
56 3
        $entities = call_user_func($this->fetcher, $offset, $limit + 1);
57
58 3
        return ConnectionBuilder::connectionFromArraySlice($entities, $args, [
59 3
            'sliceStart' => $offset,
60 3
            'arrayLength' => $offset + count($entities),
61 3
        ]);
62
    }
63
64
    /**
65
     * @param Argument|array $args
66
     * @param int|callable   $total
67
     *
68
     * @return Connection
69
     */
70 1
    public function auto($args, $total)
71
    {
72 1
        $args = $this->protectArgs($args);
73
74 1
        if ($args['last']) {
75 1
            return $this->backward($args, is_callable($total) ? call_user_func($total) : $total);
76
        } else {
77 1
            return $this->forward($args);
78
        }
79
    }
80
81
    /**
82
     * @param Argument|array $args
83
     *
84
     * @return Argument
85
     */
86 5
    private function protectArgs($args)
87
    {
88 5
        return $args instanceof Argument ? $args : new Argument($args);
89
    }
90
}
91