Completed
Branch EDTR/gql-server-side (8c11b8)
by
unknown
25:44 queued 17:18
created

RootQueryDatetimesConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 67
loc 67
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A config() 12 12 1
A resolveConnection() 5 5 1
A resolveNode() 4 4 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
namespace EventEspresso\core\domain\services\graphql\connections;
4
5
use EE_Base_Class;
6
use EEM_Datetime;
7
use EventEspresso\core\domain\services\graphql\connection_resolvers\DatetimeConnectionResolver;
8
use EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection;
9
use EventEspresso\core\services\graphql\connections\ConnectionInterface;
10
use Exception;
11
use WPGraphQL\Type\WPObjectType;
12
13
/**
14
 * Class RootQueryDatetimesConnection
15
 * Description
16
 *
17
 * @package EventEspresso\core\domain\services\graphql\connections
18
 * @author  Brent Christensen
19
 * @since   $VID:$
20
 */
21 View Code Duplication
class RootQueryDatetimesConnection implements ConnectionInterface
22
{
23
24
    /**
25
     * @var EEM_Datetime $model
26
     */
27
    protected $model;
28
29
30
    /**
31
     * DatetimeConnection constructor.
32
     *
33
     * @param EEM_Datetime               $model
34
     */
35
    public function __construct(EEM_Datetime $model)
36
    {
37
        $this->model = $model;
38
    }
39
40
41
    /**
42
     * @return array
43
     * @since $VID:$
44
     */
45
    public function config()
46
    {
47
        return [
48
            'fromType'           => 'RootQuery',
49
            'toType'             => 'Datetime',
50
            'fromFieldName'      => 'datetimes',
51
            'connectionTypeName' => 'RootQueryDatetimesConnection',
52
            'connectionArgs'     => EventDatetimesConnection::get_connection_args(),
53
            'resolve'            => [$this, 'resolveConnection'],
54
            'resolveNode'        => [$this, 'resolveNode']
55
        ];
56
    }
57
58
59
    /**
60
     * @param $entity
61
     * @param $args
62
     * @param $context
63
     * @param $info
64
     * @return array
65
     * @throws Exception
66
     * @since $VID:$
67
     */
68
    public function resolveConnection($entity, $args, $context, $info)
69
    {
70
        $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info);
71
        return $resolver->get_connection();
72
    }
73
74
75
    /**
76
     * @param $id
77
     * @param $args
78
     * @param $context
79
     * @param $info
80
     * @return EE_Base_Class
81
     * @since $VID:$
82
     */
83
    public function resolveNode($id, $args, $context, $info)
84
    {
85
        return $this->model->get_one_by_ID($id);
86
    }
87
}
88