Completed
Branch dev (ca5f7c)
by
unknown
34:50 queued 25:14
created

EventEditorGraphQLData::getData()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 1
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
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\Event;
8
use EventEspresso\core\domain\entities\admin\GraphQLData\Prices;
9
use EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes;
10
use EventEspresso\core\domain\entities\admin\GraphQLData\Tickets;
11
use ReflectionException;
12
13
/**
14
 * Class EventEditorGraphQLData
15
 * Assembles GraphQL entity data for the Event Editor
16
 *
17
 * @package EventEspresso\core\domain\services\admin\events\editor
18
 * @author  Manzoor Wani
19
 * @since   $VID:$
20
 */
21
class EventEditorGraphQLData
22
{
23
24
    /**
25
     * @var Event $event
26
     */
27
    protected $event;
28
29
    /**
30
     * @var Datetimes $datetimes
31
     */
32
    protected $datetimes;
33
34
    /**
35
     * @var Prices $prices
36
     */
37
    protected $prices;
38
39
    /**
40
     * @var PriceTypes $price_types
41
     */
42
    protected $price_types;
43
44
    /**
45
     * @var Tickets $tickets
46
     */
47
    protected $tickets;
48
49
    /**
50
     * @var EventEntityRelations $relations
51
     */
52
    protected $relations;
53
54
    /**
55
     * @var EventManagers $managers
56
     */
57
    protected $managers;
58
59
    /**
60
     * @var NewEventDefaultEntities $default_entities
61
     */
62
    protected $default_entities;
63
64
65
    /**
66
     * EventEditorGraphQLData constructor.
67
     *
68
     * @param Datetimes               $datetimes
69
     * @param Event                   $event
70
     * @param Prices                  $prices
71
     * @param PriceTypes              $price_types
72
     * @param Tickets                 $tickets
73
     * @param EventEntityRelations    $relations
74
     * @param EventManagers           $managers
75
     * @param NewEventDefaultEntities $default_entities
76
     */
77
    public function __construct(
78
        Datetimes $datetimes,
79
        Event $event,
80
        Prices $prices,
81
        PriceTypes $price_types,
82
        Tickets $tickets,
83
        EventEntityRelations $relations,
84
        EventManagers $managers,
85
        NewEventDefaultEntities $default_entities
86
    ) {
87
        $this->datetimes        = $datetimes;
88
        $this->event            = $event;
89
        $this->default_entities = $default_entities;
90
        $this->prices           = $prices;
91
        $this->price_types      = $price_types;
92
        $this->managers         = $managers;
93
        $this->relations        = $relations;
94
        $this->tickets          = $tickets;
95
    }
96
97
98
    /**
99
     * @param int $eventId
100
     * @return array
101
     * @throws EE_Error
102
     * @throws ReflectionException
103
     * @since $VID:$
104
     */
105
    public function getData(int $eventId)
106
    {
107
        $event = $this->event->getData(['id' => $eventId]);
108
        $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
109
        $eventManagers = $this->managers ->getData($eventId);
110
111
        // Avoid undefined variable warning in PHP >= 7.3
112
        $tickets = null;
0 ignored issues
show
Unused Code introduced by
$tickets is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
113
        $prices  = null;
0 ignored issues
show
Unused Code introduced by
$prices is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
114
115
        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
116
            $this->default_entities->getData($eventId);
117
            $datetimes = $this->datetimes->getData(['eventId' => $eventId]);
118
        }
119
120
        $tickets = $this->tickets->getData([
121
            'eventId'               => $eventId,
122
            'includeDefaultTickets' => true,
123
        ]);
124
125
        $prices = $this->prices->getData([
126
            'eventId'                     => $eventId,
127
            'includeDefaultTicketsPrices' => true,
128
            'includeDefaultPrices'        => true,
129
        ]);
130
131
        $priceTypes = $this->price_types->getData();
132
133
        $relations = $this->relations->getData($eventId);
134
135
        return compact(
136
            'datetimes',
137
            'event',
138
            'eventManagers',
139
            'prices',
140
            'priceTypes',
141
            'relations',
142
            'tickets'
143
        );
144
    }
145
}
146