Completed
Branch EDTR/tpc-enhancements (4b3f75)
by
unknown
52:35 queued 43:58
created

TicketPricesConnection::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_Price;
7
use EventEspresso\core\domain\services\graphql\connection_resolvers\PriceConnectionResolver;
8
use EventEspresso\core\services\graphql\connections\ConnectionBase;
9
use Exception;
10
11
/**
12
 * Class TicketPricesConnection
13
 * Description
14
 *
15
 * @package EventEspresso\core\domain\services\graphql\connections
16
 * @author  Manzoor Wani
17
 * @since   $VID:$
18
 */
19
class TicketPricesConnection extends ConnectionBase
20
{
21
22
23
    /**
24
     * TicketConnection constructor.
25
     *
26
     * @param EEM_Price $model
27
     */
28
    public function __construct(EEM_Price $model)
29
    {
30
        $this->model = $model;
31
    }
32
33
34
    /**
35
     * @return array
36
     * @since $VID:$
37
     */
38
    public function config()
39
    {
40
        return [
41
            'fromType'           => $this->namespace . 'Ticket',
42
            'toType'             => $this->namespace . 'Price',
43
            'fromFieldName'      => 'prices',
44
            'connectionTypeName' => "{$this->namespace}TicketPricesConnection",
45
            'connectionArgs'     => self::get_connection_args(),
46
            'resolve'            => [$this, 'resolveConnection'],
47
        ];
48
    }
49
50
51
    /**
52
     * @param $entity
53
     * @param $args
54
     * @param $context
55
     * @param $info
56
     * @return array
57
     * @throws Exception
58
     * @since $VID:$
59
     */
60
    public function resolveConnection($entity, $args, $context, $info)
61
    {
62
        $resolver = new PriceConnectionResolver($entity, $args, $context, $info);
63
        return $resolver->get_connection();
64
    }
65
66
    /**
67
     * Given an optional array of args, this returns the args to be used in the connection
68
     *
69
     * @access public
70
     * @param array $args The args to modify the defaults
71
     *
72
     * @return array
73
     */
74
    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
75
    public static function get_connection_args($args = [])
76
    {
77
        return array_merge(
78
            [
79
                'in'              => [
80
                    'type'        => ['list_of' => 'ID'],
81
                    'description' => esc_html__('Limit pices to the given globally unique IDs', 'event_espresso'),
82
                ],
83
                'idIn'            => [
84
                    'type'        => ['list_of' => 'ID'],
85
                    'description' => esc_html__('Limit pices to the given IDs', 'event_espresso'),
86
                ],
87
                'ticket'          => [
88
                    'type'        => 'ID',
89
                    'description' => esc_html__('Globally unique ticket ID to get the prices for.', 'event_espresso'),
90
                ],
91
                'ticketIn'        => [
92
                    'type'        => ['list_of' => 'ID'],
93
                    'description' => esc_html__('Globally unique ticket IDs to get the prices for.', 'event_espresso'),
94
                ],
95
                'ticketId'        => [
96
                    'type'        => 'Int',
97
                    'description' => esc_html__('Ticket ID to get the prices for.', 'event_espresso'),
98
                ],
99
                'ticketIdIn'      => [
100
                    'type'        => ['list_of' => 'Int'],
101
                    'description' => esc_html__('Ticket IDs to get the prices for.', 'event_espresso'),
102
                ],
103
                'priceType'       => [
104
                    'type'        => 'ID',
105
                    'description' => esc_html__('Globally unique price type ID to get the prices for.', 'event_espresso'),
106
                ],
107
                'priceTypeIn'     => [
108
                    'type'        => ['list_of' => 'ID'],
109
                    'description' => esc_html__('Globally unique price type IDs to get the prices for.', 'event_espresso'),
110
                ],
111
                'priceTypeId'     => [
112
                    'type'        => 'Int',
113
                    'description' => esc_html__('Price type ID to get the prices for.', 'event_espresso'),
114
                ],
115
                'priceTypeIdIn'   => [
116
                    'type'        => ['list_of' => 'Int'],
117
                    'description' => esc_html__('Price type IDs to get the prices for.', 'event_espresso'),
118
                ],
119
                'priceBaseType'   => [
120
                    'type'        => 'PriceBaseTypeEnum',
121
                    'description' => esc_html__('Price Base type.', 'event_espresso'),
122
                ],
123
                'priceBaseTypeIn' => [
124
                    'type'        => ['list_of' => 'PriceBaseTypeEnum'],
125
                    'description' => esc_html__('Price Base types.', 'event_espresso'),
126
                ],
127
            ],
128
            $args
129
        );
130
    }
131
}
132