Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ChangeOpLanguage
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 apply
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikibase\Lexeme\DataAccess\ChangeOp;
4
5use InvalidArgumentException;
6use ValueValidators\Result;
7use ValueValidators\ValueValidator;
8use Wikibase\DataModel\Entity\EntityDocument;
9use Wikibase\DataModel\Entity\ItemId;
10use Wikibase\Lexeme\Domain\Model\Lexeme;
11use Wikibase\Lib\Summary;
12use Wikibase\Repo\ChangeOp\ChangeOpBase;
13use Wikibase\Repo\ChangeOp\DummyChangeOpResult;
14use Wikimedia\Assert\Assert;
15
16/**
17 * @license GPL-2.0-or-later
18 */
19class ChangeOpLanguage extends ChangeOpBase {
20
21    private $language;
22    private $languageValidator;
23
24    public function __construct( ItemId $language, ValueValidator $languageValidator ) {
25        $this->language = $language;
26        $this->languageValidator = $languageValidator;
27    }
28
29    /**
30     * @param EntityDocument $entity
31     *
32     * @return Result
33     * @throws InvalidArgumentException
34     */
35    public function validate( EntityDocument $entity ) {
36        Assert::parameterType( Lexeme::class, $entity, '$entity' );
37
38        return $this->languageValidator->validate( $this->language );
39    }
40
41    /**
42     * @param EntityDocument $entity
43     * @param Summary|null $summary
44     *
45     * @throws InvalidArgumentException
46     */
47    public function apply( EntityDocument $entity, Summary $summary = null ) {
48        Assert::parameterType( Lexeme::class, $entity, '$entity' );
49        '@phan-var Lexeme $entity';
50
51        /** @var Lexeme $entity */
52        $this->updateSummary( $summary, 'set', '', $this->language->getSerialization() );
53        $entity->setLanguage( $this->language );
54
55        return new DummyChangeOpResult();
56    }
57
58}