Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpLexicalCategory | |
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 ChangeOpLexicalCategory extends ChangeOpBase { |
20 | |
21 | private ItemId $lexicalCategory; |
22 | private ValueValidator $lexicalCategoryValidator; |
23 | |
24 | public function __construct( |
25 | ItemId $lexicalCategory, |
26 | ValueValidator $lexicalCategoryValidator |
27 | ) { |
28 | $this->lexicalCategory = $lexicalCategory; |
29 | $this->lexicalCategoryValidator = $lexicalCategoryValidator; |
30 | } |
31 | |
32 | /** |
33 | * @param EntityDocument $entity |
34 | * |
35 | * @return Result |
36 | * @throws InvalidArgumentException |
37 | */ |
38 | public function validate( EntityDocument $entity ) { |
39 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
40 | |
41 | return $this->lexicalCategoryValidator->validate( $this->lexicalCategory ); |
42 | } |
43 | |
44 | /** |
45 | * @param EntityDocument $entity |
46 | * @param Summary|null $summary |
47 | * |
48 | * @throws InvalidArgumentException |
49 | */ |
50 | public function apply( EntityDocument $entity, ?Summary $summary = null ) { |
51 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
52 | '@phan-var Lexeme $entity'; |
53 | |
54 | /** @var Lexeme $entity */ |
55 | $this->updateSummary( $summary, 'set', '', $this->lexicalCategory->getSerialization() ); |
56 | $entity->setLexicalCategory( $this->lexicalCategory ); |
57 | |
58 | return new DummyChangeOpResult(); |
59 | } |
60 | |
61 | } |