Completed
Push — develop ( b91125...52c290 )
by Seth
03:00
created

Event   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getEventHash() 0 19 6
1
<?php
2
3
namespace smtech\CanvasICSSync\SyncIntoCanvas;
4
5
class Event
6
{
7
    const FIELD_MAP = [
8
        'calendar_event[title]' => 'SUMMARY',
9
        'calendar_event[description]' => 'DESCRIPTION',
10
        'calendar_event[start_at]' => [
11
            0 => 'X-CURRENT-DTSTART',
12
            1 => 'DTSTART'
13
        ],
14
        'calendar_event[end_at]' => [
15
            0 => 'X-CURRENT-DTEND',
16
            1 => 'DTEND'
17
        ],
18
        'calendar_event[location_name]' => 'LOCATION'
19
    ];
20
21
    /**
22
     * Generate a hash of this version of an event to cache in the database
23
     **/
24
    public function getEventHash($event)
25
    {
26
        $blob = '';
27
        foreach (static::$FIELD_MAP as $field) {
28
            if (is_array($field)) {
29
                foreach ($field as $option) {
30
                    if (!empty($property = $event->getProperty($option))) {
31
                        $blob .= serialize($property);
32
                        break;
33
                    }
34
                }
35
            } else {
36
                if (!empty($property = $event->getProperty($field))) {
37
                    $blob .= serialize($property);
38
                }
39
            }
40
        }
41
        return md5($blob);
42
    }
43
}
44