Completed
Pull Request — master (#364)
by Luc
15:39 queued 06:04
created

polyFillMultilingualFields()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 5
Ratio 38.46 %

Importance

Changes 0
Metric Value
dl 5
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Event\ReadModel\JSONLD;
4
5
use CultuurNet\UDB3\ReadModel\ConfigurableJsonDocumentLanguageAnalyzer;
6
use CultuurNet\UDB3\ReadModel\JsonDocument;
7
8
class EventJsonDocumentLanguageAnalyzer extends ConfigurableJsonDocumentLanguageAnalyzer
9
{
10
    public function __construct()
11
    {
12
        parent::__construct(
13
            [
14
                'name',
15
                'description',
16
                'bookingInfo.urlLabel',
17
            ]
18
        );
19
    }
20
21
    /**
22
     * @todo Remove when full replay is done.
23
     * @replay_i18n
24
     * @see https://jira.uitdatabank.be/browse/III-2201
25
     *
26
     * @param JsonDocument $jsonDocument
27
     * @return \CultuurNet\UDB3\Language[]
28
     */
29
    public function determineAvailableLanguages(JsonDocument $jsonDocument)
30
    {
31
        $jsonDocument = $this->polyFillMultilingualFields($jsonDocument);
32
        return parent::determineAvailableLanguages($jsonDocument);
33
    }
34
35
    /**
36
     * @todo Remove when full replay is done.
37
     * @replay_i18n
38
     * @see https://jira.uitdatabank.be/browse/III-2201
39
     *
40
     * @param JsonDocument $jsonDocument
41
     * @return \CultuurNet\UDB3\Language[]
42
     */
43
    public function determineCompletedLanguages(JsonDocument $jsonDocument)
44
    {
45
        $jsonDocument = $this->polyFillMultilingualFields($jsonDocument);
46
        return parent::determineCompletedLanguages($jsonDocument);
47
    }
48
49
    /**
50
     * @todo Remove when full replay is done.
51
     * @replay_i18n
52
     * @see https://jira.uitdatabank.be/browse/III-2201
53
     *
54
     * @param JsonDocument $jsonDocument
55
     * @return JsonDocument
56
     */
57
    private function polyFillMultilingualFields(JsonDocument $jsonDocument)
58
    {
59
        $body = $jsonDocument->getBody();
60
        $mainLanguage = isset($body->mainLanguage) ? $body->mainLanguage : 'nl';
61
62 View Code Duplication
        if (isset($body->bookingInfo->urlLabel) && is_string($body->bookingInfo->urlLabel)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
            $body->bookingInfo->urlLabel = (object) [
64
                $mainLanguage => $body->bookingInfo->urlLabel,
65
            ];
66
        }
67
68
        return $jsonDocument->withBody($body);
69
    }
70
}
71