Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpLanguage | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
apply | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\ChangeOp; |
4 | |
5 | use InvalidArgumentException; |
6 | use ValueValidators\Result; |
7 | use ValueValidators\ValueValidator; |
8 | use Wikibase\DataModel\Entity\EntityDocument; |
9 | use Wikibase\DataModel\Entity\ItemId; |
10 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
11 | use Wikibase\Lib\Summary; |
12 | use Wikibase\Repo\ChangeOp\ChangeOpBase; |
13 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
14 | use Wikimedia\Assert\Assert; |
15 | |
16 | /** |
17 | * @license GPL-2.0-or-later |
18 | */ |
19 | class ChangeOpLanguage extends ChangeOpBase { |
20 | |
21 | private ItemId $language; |
22 | private ValueValidator $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 | } |