Completed
Push — master ( 24c913...da3260 )
by Kristof
04:58
created

OfferUpdate   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A calendar() 0 20 1
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\ReadModel\JSONLD;
4
5
use CultuurNet\UDB3\Calendar;
6
7
/**
8
 * Class OfferUpdate
9
 *
10
 * Creates callbacks that can be applied to json-ld offers.
11
 *
12
 * @package CultuurNet\UDB3\Offer\ReadModel\JSONLD
13
 *
14
 */
15
class OfferUpdate
16
{
17
    /**
18
     * @param Calendar $calendar
19
     *  The calendar to use when updating the offer
20
     *
21
     * @return \Closure
22
     *  A closure that accepts the existing offer body and applies the update.
23
     */
24
    public static function calendar(Calendar $calendar)
25
    {
26
        $offerCalenderUpdate = function ($body) use ($calendar) {
27
            // Purge any existing calendar data
28
            unset(
29
                $body->calendarType,
30
                $body->startDate,
31
                $body->endDate,
32
                $body->subEvent,
33
                $body->openingHours
34
            );
35
36
            return (object) array_merge(
37
                (array) $body,
38
                $calendar->toJsonLd()
39
            );
40
        };
41
42
        return $offerCalenderUpdate;
43
    }
44
}
45