Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpLemmaRemove | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
4 | |
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% |
12 / 12 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\ChangeOp; |
4 | |
5 | use InvalidArgumentException; |
6 | use ValueValidators\Result; |
7 | use Wikibase\DataModel\Entity\EntityDocument; |
8 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
9 | use Wikibase\Lib\Summary; |
10 | use Wikibase\Repo\ChangeOp\ChangeOpBase; |
11 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
12 | use Wikimedia\Assert\Assert; |
13 | |
14 | /** |
15 | * @license GPL-2.0-or-later |
16 | */ |
17 | class ChangeOpLemmaRemove extends ChangeOpBase { |
18 | |
19 | private const SUMMARY_ACTION_REMOVE = 'remove'; |
20 | |
21 | /** |
22 | * @var string |
23 | */ |
24 | private $language; |
25 | |
26 | public function __construct( $language ) { |
27 | Assert::parameterType( 'string', $language, '$language' ); |
28 | |
29 | $this->language = $language; |
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 Result::newSuccess(); |
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 | $lemmas = $entity->getLemmas(); |
56 | |
57 | if ( !$lemmas->hasTermForLanguage( $this->language ) ) { |
58 | return new DummyChangeOpResult(); |
59 | } |
60 | |
61 | $this->updateSummary( |
62 | $summary, |
63 | self::SUMMARY_ACTION_REMOVE, |
64 | $this->language, |
65 | $lemmas->getByLanguage( $this->language )->getText() |
66 | ); |
67 | $lemmas->removeByLanguage( $this->language ); |
68 | |
69 | return new DummyChangeOpResult(); |
70 | } |
71 | |
72 | } |