Completed
Pull Request — master (#313)
by
unknown
05:46
created

determineAvailableLanguages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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