Completed
Branch EDTR/master (872e60)
by
unknown
27:04 queued 17:58
created

TicketPricesConnection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A config() 0 12 1
A resolveConnection() 0 5 1
A resolveNode() 0 4 1
A get_connection_args() 0 48 1
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\ConnectionInterface;
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 implements ConnectionInterface
20
{
21
22
    /**
23
     * @var EEM_Price $model
24
     */
25
    protected $model;
26
27
28
    /**
29
     * TicketConnection constructor.
30
     *
31
     * @param EEM_Price $model
32
     */
33
    public function __construct(EEM_Price $model)
34
    {
35
        $this->model = $model;
36
    }
37
38
39
    /**
40
     * @return array
41
     * @since $VID:$
42
     */
43
    public function config()
44
    {
45
        return [
46
            'fromType'           => 'Ticket',
47
            'toType'             => 'Price',
48
            'fromFieldName'      => 'prices',
49
            'connectionTypeName' => 'TicketPricesConnection',
50
            'connectionArgs'     => self::get_connection_args(),
51
            'resolve'            => [$this, 'resolveConnection'],
52
            'resolveNode'        => [$this, 'resolveNode']
53
        ];
54
    }
55
56
57
    /**
58
     * @param $entity
59
     * @param $args
60
     * @param $context
61
     * @param $info
62
     * @return array
63
     * @throws Exception
64
     * @since $VID:$
65
     */
66
    public function resolveConnection($entity, $args, $context, $info)
67
    {
68
        $resolver = new PriceConnectionResolver($entity, $args, $context, $info);
69
        return $resolver->get_connection();
70
    }
71
72
73
    /**
74
     * @param $id
75
     * @param $args
76
     * @param $context
77
     * @param $info
78
     * @return EE_Base_Class
79
     * @since $VID:$
80
     */
81
    public function resolveNode($id, $args, $context, $info)
82
    {
83
        return $this->model->get_one_by_ID($id);
84
    }
85
86
    /**
87
     * Given an optional array of args, this returns the args to be used in the connection
88
     *
89
     * @access public
90
     * @param array $args The args to modify the defaults
91
     *
92
     * @return array
93
     */
94
    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
95
    public static function get_connection_args($args = [])
96
    {
97
        return array_merge(
98
            [
99
                'ticket' => [
100
                    'type'        => 'ID',
101
                    'description' => esc_html__('Globally unique ticket ID to get the prices for.', 'event_espresso'),
102
                ],
103
                'ticketIn' => [
104
                    'type'        => ['list_of' => 'ID'],
105
                    'description' => esc_html__('Globally unique ticket IDs to get the prices for.', 'event_espresso'),
106
                ],
107
                'ticketId' => [
108
                    'type'        => 'Int',
109
                    'description' => esc_html__('Ticket ID to get the prices for.', 'event_espresso'),
110
                ],
111
                'ticketIdIn' => [
112
                    'type'        => ['list_of' => 'Int'],
113
                    'description' => esc_html__('Ticket IDs to get the prices for.', 'event_espresso'),
114
                ],
115
                'priceType' => [
116
                    'type'        => 'ID',
117
                    'description' => esc_html__('Globally unique price type ID to get the prices for.', 'event_espresso'),
118
                ],
119
                'priceTypeIn' => [
120
                    'type'        => ['list_of' => 'ID'],
121
                    'description' => esc_html__('Globally unique price type IDs to get the prices for.', 'event_espresso'),
122
                ],
123
                'priceTypeId' => [
124
                    'type'        => 'Int',
125
                    'description' => esc_html__('Price type ID to get the prices for.', 'event_espresso'),
126
                ],
127
                'priceTypeIdIn' => [
128
                    'type'        => ['list_of' => 'Int'],
129
                    'description' => esc_html__('Price type IDs to get the prices for.', 'event_espresso'),
130
                ],
131
                'priceBaseType' => [
132
                    'type'        => 'PriceBaseTypeEnum',
133
                    'description' => esc_html__('Price Base type.', 'event_espresso'),
134
                ],
135
                'priceBaseTypeIn' => [
136
                    'type'        => ['list_of' => 'PriceBaseTypeEnum'],
137
                    'description' => esc_html__('Price Base types.', 'event_espresso'),
138
                ],
139
            ],
140
            $args
141
        );
142
    }
143
}
144