Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.00% covered (success)
92.00%
23 / 25
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexemeChangeOpDeserializer
92.00% covered (success)
92.00%
23 / 25
66.67% covered (warning)
66.67%
2 / 3
9.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 setContext
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createEntityChangeOp
88.89% covered (warning)
88.89%
16 / 18
0.00% covered (danger)
0.00%
0 / 1
7.07
1<?php
2
3namespace Wikibase\Lexeme\Presentation\ChangeOp\Deserialization;
4
5use Wikibase\Repo\ChangeOp\ChangeOp;
6use Wikibase\Repo\ChangeOp\ChangeOpDeserializer;
7use Wikibase\Repo\ChangeOp\ChangeOps;
8use Wikibase\Repo\ChangeOp\Deserialization\ClaimsChangeOpDeserializer;
9
10/**
11 * Class for creating ChangeOp for EditEntity API
12 *
13 * @license GPL-2.0-or-later
14 * @author Amir Sarabadani <ladsgroup@gmail.com>
15 */
16class LexemeChangeOpDeserializer implements ChangeOpDeserializer {
17
18    /**
19     * @var LemmaChangeOpDeserializer
20     */
21    private $lemmaChangeOpDeserializer;
22
23    /**
24     * @var LexicalCategoryChangeOpDeserializer
25     */
26    private $lexicalCategoryChangeOpDeserializer;
27
28    /**
29     * @var LanguageChangeOpDeserializer
30     */
31    private $languageChangeOpDeserializer;
32
33    /**
34     * @var ClaimsChangeOpDeserializer
35     */
36    private $statementChangeOpDeserializer;
37
38    /**
39     * @var FormListChangeOpDeserializer
40     */
41    private $formListChangeOpDeserializer;
42
43    /**
44     * @var SenseListChangeOpDeserializer
45     */
46    private $senseListChangeOpDeserializer;
47
48    /**
49     * @var ValidationContext
50     */
51    private $validationContext;
52
53    public function __construct(
54        LemmaChangeOpDeserializer $lemmaChangeOpDeserializer,
55        LexicalCategoryChangeOpDeserializer $lexicalCategoryChangeOpDeserializer,
56        LanguageChangeOpDeserializer $languageChangeOpDeserializer,
57        ClaimsChangeOpDeserializer $statementChangeOpDeserializer,
58        FormListChangeOpDeserializer $formListChangeOpDeserializer,
59        SenseListChangeOpDeserializer $senseListChangeOpDeserializer
60    ) {
61        $this->lemmaChangeOpDeserializer = $lemmaChangeOpDeserializer;
62        $this->lexicalCategoryChangeOpDeserializer = $lexicalCategoryChangeOpDeserializer;
63        $this->languageChangeOpDeserializer = $languageChangeOpDeserializer;
64        $this->statementChangeOpDeserializer = $statementChangeOpDeserializer;
65        $this->formListChangeOpDeserializer = $formListChangeOpDeserializer;
66        $this->senseListChangeOpDeserializer = $senseListChangeOpDeserializer;
67    }
68
69    /**
70     * @param ValidationContext $validationContext
71     */
72    public function setContext( ValidationContext $validationContext ) {
73        $this->validationContext = $validationContext;
74    }
75
76    /**
77     * @see ChangeOpDeserializer::createEntityChangeOp
78     *
79     * @param array[] $changeRequest
80     *
81     * @return ChangeOp
82     */
83    public function createEntityChangeOp( array $changeRequest ) {
84        $changeOps = new ChangeOps();
85
86        if ( array_key_exists( 'lemmas', $changeRequest ) ) {
87            $changeOps->add( $this->lemmaChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
88        }
89
90        if ( array_key_exists( 'lexicalCategory', $changeRequest ) ) {
91            $changeOps->add(
92                $this->lexicalCategoryChangeOpDeserializer->createEntityChangeOp( $changeRequest )
93            );
94        }
95
96        if ( array_key_exists( 'language', $changeRequest ) ) {
97            $changeOps->add( $this->languageChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
98        }
99
100        if ( array_key_exists( 'claims', $changeRequest ) ) {
101            $changeOps->add( $this->statementChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
102        }
103
104        if ( array_key_exists( 'forms', $changeRequest ) ) {
105            $this->formListChangeOpDeserializer->setContext( $this->validationContext->at( 'forms' ) );
106            $changeOps->add( $this->formListChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
107        }
108
109        if ( array_key_exists( 'senses', $changeRequest ) ) {
110            $this->senseListChangeOpDeserializer->setContext( $this->validationContext->at( 'senses' ) );
111            $changeOps->add( $this->senseListChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
112        }
113
114        return $changeOps;
115    }
116
117}