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

OfferUpdate::calendar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 12
nc 1
nop 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