Test Failed
Push — master ( 9a7899...702660 )
by Mike
44s queued 11s
created

ClassroomApi::download()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace mikemix\Wiziq\API;
3
4
use mikemix\Wiziq\API\Request;
5
use mikemix\Wiziq\Common\Api\ClassroomApiInterface;
6
use mikemix\Wiziq\Entity\Attendees;
7
use mikemix\Wiziq\Entity\Classroom;
8
use mikemix\Wiziq\Entity\PermaClassroom;
9
10
class ClassroomApi implements ClassroomApiInterface
11
{
12
    /** @var Gateway */
13
    protected $gateway;
14
15 5
    public function __construct(Gateway $requester)
16
    {
17 5
        $this->gateway = $requester;
18 5
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 1
    public function create(Classroom $classroom)
24
    {
25 1
        $response = $this->gateway->sendRequest(new Request\Create($classroom))
26 1
            ->create[0]->class_details[0];
27
28
        return [
29 1
            'class_id'        => (int)$response->class_id,
30 1
            'recording_url'   => (string)$response->recording_url,
31 1
            'presenter_email' => (string)$response->presenter_list[0]->presenter[0]->presenter_email,
32 1
            'presenter_url'   => (string)$response->presenter_list[0]->presenter[0]->presenter_url,
33 1
        ];
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function modify($classroomId, Classroom $classroom)
40
    {
41 1
42 1
        $response = (boolean)$this->gateway->sendRequest(new Request\Modify($classroomId, $classroom))->modify["status"];
43
44
        return $response;
45
    }
46
     /**
47 1
     * {@inheritdoc}
48
     */
49 1
    public function download($classroomId, $recordingFormat = 'zip')
50 1
    {
51
52
        $response = $this->gateway->sendRequest(new Request\Download($classroomId, $recordingFormat))->download_recording;
0 ignored issues
show
Bug introduced by
The property download_recording does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53 1
54 1
        return $response;
55 1
    }
56 1
    /**
57 1
     * {@inheritdoc}
58
     */
59
    public function cancel($classroomId)
60
    {
61
        $response = (boolean)$this->gateway->sendRequest(new Request\Cancel($classroomId))->cancel['status'];
62
        return $response;
63 1
    }
64
65 1
    /**
66 1
     * {@inheritdoc}
67
     */
68 1
    public function getAttendanceReport($classroomId)
69 1
    {
70 1
        $attendance = [];
71
72 1
        $response = $this->gateway->sendRequest(new Request\AttendanceReport($classroomId))->get_attendance_report;
0 ignored issues
show
Bug introduced by
The property get_attendance_report does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
74
        foreach($response->attendee_list[0] as $attendee) {
75
            $data = [
76
                    'entry_time'       => (string)$attendee->entry_time,
77
                    'exit_time'        => (string)$attendee->exit_time,
78
                    'attended_minutes' => (string)$attendee->attended_minutes,
79
                    ];
80
            if(isset($attendee['presenter']) and $attendee['presenter']==true) {
81
                $data['presenter_id'] = (int)$attendee->presenter_id;
82
            } else {
83
                $data['attendee_id'] = (int)$attendee->attendee_id;
84
            }
85
86
            $attendance[] = $data;
87
        }
88
89
        return $attendance;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function createPermaClas(PermaClassroom $classroom)
96
    {
97
        $response = $this->gateway->sendRequest(new Request\CreatePermaClass($classroom));
98
        $details  = $response->create_perma_class[0]->perma_class_details[0];
99
100
        return [
101
            'class_id'        => (int)$details->class_master_id,
102
            'attendee_url'    => (string)$details->common_perma_attendee_url,
103
            'presenter_email' => (string)$details->presenter[0]->presenter_email,
104
            'presenter_url'   => (string)$details->presenter[0]->presenter_url,
105
        ];
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function addAttendeesToClass($classroomId, Attendees $attendees)
112
    {
113
        $response = $this->gateway->sendRequest(new Request\AddAttendees($classroomId, $attendees));
114
        $result   = [];
115
116
        foreach ($response->add_attendees[0]->attendee_list[0] as $attendee) {
117
            $result[] = ['id' => (int)$attendee->attendee_id, 'url' => (string)$attendee->attendee_url];
118
        }
119
120
        return $result;
121
    }
122
123
    /**
124
     * @codeCoverageIgnore
125
     * @param \SimpleXMLElement $response
126
     * @return array
127
     */
128
    protected function getPresentersFromResponse(\SimpleXMLElement $response)
129
    {
130
        $presenters = [];
131
        foreach ($response->presenter_list[0] as $presenter) {
132
            $presenters[] = [
133
                'email' => (string)$presenter->presenter_email,
134
                'url'   => (string)$presenter->presenter_url,
135
            ];
136
        }
137
138
        return $presenters;
139
    }
140
}
141