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

EventDatetimesConnection::get_connection_args()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 56
rs 8.9599
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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