Completed
Branch EDTR/master (0d7008)
by
unknown
34:37 queued 26:06
created

EventDatetimesConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 113
Duplicated Lines 9.73 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 11
loc 113
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A config() 11 11 1
A resolveConnection() 0 5 1
B get_connection_args() 0 56 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\services\graphql\connections\ConnectionBase;
9
use Exception;
10
use WPGraphQL\Type\WPObjectType;
11
12
/**
13
 * Class EventDatetimesConnection
14
 * Description
15
 *
16
 * @package EventEspresso\core\domain\services\graphql\connections
17
 * @author  Brent Christensen
18
 * @since   $VID:$
19
 */
20
class EventDatetimesConnection extends ConnectionBase
21
{
22
23
24
    /**
25
     * DatetimeConnection constructor.
26
     *
27
     * @param EEM_Datetime               $model
28
     */
29
    public function __construct(EEM_Datetime $model)
30
    {
31
        $this->model = $model;
32
    }
33
34
35
    /**
36
     * @return array
37
     * @since $VID:$
38
     */
39 View Code Duplication
    public function config()
40
    {
41
        return [
42
            'fromType'           => $this->namespace . 'Event',
43
            'toType'             => $this->namespace . 'Datetime',
44
            'fromFieldName'      => 'datetimes',
45
            'connectionTypeName' => "{$this->namespace}EventDatetimesConnection",
46
            'connectionArgs'     => self::get_connection_args(),
47
            'resolve'            => [$this, 'resolveConnection'],
48
        ];
49
    }
50
51
52
    /**
53
     * @param $entity
54
     * @param $args
55
     * @param $context
56
     * @param $info
57
     * @return array
58
     * @throws Exception
59
     * @since $VID:$
60
     */
61
    public function resolveConnection($entity, $args, $context, $info)
62
    {
63
        $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info);
64
        return $resolver->get_connection();
65
    }
66
67
    /**
68
     * Given an optional array of args, this returns the args to be used in the connection
69
     *
70
     * @access public
71
     * @param array $args The args to modify the defaults
72
     *
73
     * @return array
74
     */
75
    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
76
    public static function get_connection_args($args = [])
77
    {
78
        return array_merge(
79
            [
80
                'orderby'      => [
81
                    'type'        => ['list_of' => 'DatetimesConnectionOrderbyInput'],
82
                    'description' => esc_html__('What parameter to use to order the objects by.', 'event_espresso'),
83
                ],
84
                'event'  => [
85
                    'type'        => 'ID',
86
                    'description' => esc_html__('Globally unique event ID to get the datetimes for.', 'event_espresso'),
87
                ],
88
                'eventIn'  => [
89
                    'type'        => ['list_of' => 'ID'],
90
                    'description' => esc_html__('Globally unique event IDs to get the datetimes for.', 'event_espresso'),
91
                ],
92
                'eventId'  => [
93
                    'type'        => 'Int',
94
                    'description' => esc_html__('Event ID to get the datetimes for.', 'event_espresso'),
95
                ],
96
                'eventIdIn'  => [
97
                    'type'        => ['list_of' => 'Int'],
98
                    'description' => esc_html__('Event IDs to get the datetimes for.', 'event_espresso'),
99
                ],
100
                'ticket' => [
101
                    'type'        => 'ID',
102
                    'description' => esc_html__('Globally unique ticket ID to get the datetimes for.', 'event_espresso'),
103
                ],
104
                'ticketIn' => [
105
                    'type'        => ['list_of' => 'ID'],
106
                    'description' => esc_html__('Globally unique ticket IDs to get the datetimes for.', 'event_espresso'),
107
                ],
108
                'ticketId' => [
109
                    'type'        => 'Int',
110
                    'description' => esc_html__('Ticket ID to get the datetimes for.', 'event_espresso'),
111
                ],
112
                'ticketIdIn' => [
113
                    'type'        => ['list_of' => 'Int'],
114
                    'description' => esc_html__('Ticket IDs to get the datetimes for.', 'event_espresso'),
115
                ],
116
                'upcoming' => [
117
                    'type'        => 'Boolean',
118
                    'description' => esc_html__('Datetimes which are upcoming.', 'event_espresso'),
119
                ],
120
                'active'   => [
121
                    'type'        => 'Boolean',
122
                    'description' => esc_html__('Datetimes which are active.', 'event_espresso'),
123
                ],
124
                'expired'  => [
125
                    'type'        => 'Boolean',
126
                    'description' => esc_html__('Datetimes which are expired.', 'event_espresso'),
127
                ],
128
            ],
129
            $args
130
        );
131
    }
132
}
133