Completed
Branch EDTR/master (5c103b)
by
unknown
10:13 queued 38s
created

EventEditorGraphQLData   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 105
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 14
loc 105
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
B getData() 14 36 8

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\admin\events\editor;
4
5
use EE_Error;
6
use EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes;
7
use EventEspresso\core\domain\entities\admin\GraphQLData\Prices;
8
use EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes;
9
use EventEspresso\core\domain\entities\admin\GraphQLData\Tickets;
10
use ReflectionException;
11
12
/**
13
 * Class EventEditorGraphQLData
14
 * Assembles GraphQL entity data for the Event Editor
15
 *
16
 * @package EventEspresso\core\domain\services\admin\events\editor
17
 * @author  Manzoor Wani
18
 * @since   $VID:$
19
 */
20
class EventEditorGraphQLData
21
{
22
23
    /**
24
     * @var Datetimes $datetimes
25
     */
26
    protected $datetimes;
27
28
    /**
29
     * @var Prices $prices
30
     */
31
    protected $prices;
32
33
    /**
34
     * @var PriceTypes $price_types
35
     */
36
    protected $price_types;
37
38
    /**
39
     * @var Tickets $tickets
40
     */
41
    protected $tickets;
42
43
    /**
44
     * @var EventEntityRelations $relations
45
     */
46
    protected $relations;
47
48
    /**
49
     * @var NewEventDefaultEntities $default_entities
50
     */
51
    protected $default_entities;
52
53
54
    /**
55
     * EventEditorGraphQLData constructor.
56
     *
57
     * @param Datetimes  $datetimes
58
     * @param Prices     $prices
59
     * @param PriceTypes $price_types
60
     * @param Tickets    $tickets
61
     * @param EventEntityRelations $relations
62
     * @param NewEventDefaultEntities $default_entities
63
     */
64
    public function __construct(
65
        Datetimes $datetimes,
66
        Prices $prices,
67
        PriceTypes $price_types,
68
        Tickets $tickets,
69
        EventEntityRelations $relations,
70
        NewEventDefaultEntities $default_entities
71
    ) {
72
        $this->datetimes = $datetimes;
73
        $this->default_entities = $default_entities;
74
        $this->prices = $prices;
75
        $this->price_types = $price_types;
76
        $this->relations = $relations;
77
        $this->tickets = $tickets;
78
    }
79
80
81
    /**
82
     * @param int $eventId
83
     * @return array
84
     * @throws EE_Error
85
     * @throws ReflectionException
86
     * @since $VID:$
87
     */
88
    public function getData($eventId)
89
    {
90
        $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
91
92
        // Avoid undefined variable warning in PHP >= 7.3
93
        $tickets = null;
94
        $prices = null;
95
96
        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
97
            $this->default_entities->getData($eventId);
98
            $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
99
        }
100
101 View Code Duplication
        if (! empty($datetimes['nodes'])) {
102
            $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
103
104
            if (! empty($datetimeIn)) {
105
                $tickets = $this->tickets->getData(['datetimeIn' => $datetimeIn]);
106
            }
107
        }
108
109 View Code Duplication
        if (! empty($tickets['nodes'])) {
110
            $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
111
112
            if (! empty($ticketIn)) {
113
                $prices = $this->prices->getData(['ticketIn' => $ticketIn]);
114
            }
115
        }
116
117
        $priceTypes = $this->price_types->getData();
118
119
        $relations = $this->relations->getData($eventId);
120
121
122
        return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
123
    }
124
}
125