Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpRemoveForm | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
apply | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
updateSummary | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\ChangeOp; |
4 | |
5 | use ValueValidators\Error; |
6 | use ValueValidators\Result; |
7 | use Wikibase\DataModel\Entity\EntityDocument; |
8 | use Wikibase\Lexeme\Domain\Model\FormId; |
9 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
10 | use Wikibase\Lib\Summary; |
11 | use Wikibase\Repo\ChangeOp\ChangeOpBase; |
12 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
13 | use Wikimedia\Assert\Assert; |
14 | |
15 | /** |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class ChangeOpRemoveForm extends ChangeOpBase { |
19 | |
20 | private const SUMMARY_ACTION_REMOVE = 'remove-form'; |
21 | |
22 | /** |
23 | * @var FormId |
24 | */ |
25 | private $formId; |
26 | |
27 | /** |
28 | * @param FormId $formId The FormId to remove |
29 | */ |
30 | public function __construct( FormId $formId ) { |
31 | $this->formId = $formId; |
32 | } |
33 | |
34 | public function validate( EntityDocument $entity ) { |
35 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
36 | '@phan-var Lexeme $entity'; |
37 | |
38 | /** @var Lexeme $entity */ |
39 | if ( $entity->getForms()->getById( $this->formId ) === null ) { |
40 | return Result::newError( [ |
41 | Error::newError( |
42 | 'Form does not exist', |
43 | null, |
44 | 'form-not-found', |
45 | [ $this->formId->getSerialization() ] |
46 | ), |
47 | ] ); |
48 | } |
49 | |
50 | return Result::newSuccess(); |
51 | } |
52 | |
53 | public function apply( EntityDocument $entity, ?Summary $summary = null ) { |
54 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
55 | '@phan-var Lexeme $entity'; |
56 | |
57 | /** @var Lexeme $entity */ |
58 | |
59 | $form = $entity->getForm( $this->formId ); |
60 | $entity->removeForm( $this->formId ); |
61 | |
62 | $this->updateSummary( |
63 | $summary, |
64 | self::SUMMARY_ACTION_REMOVE, |
65 | '', |
66 | array_values( $form->getRepresentations()->toTextArray() ) |
67 | ); |
68 | |
69 | return new DummyChangeOpResult(); |
70 | } |
71 | |
72 | protected function updateSummary( ?Summary $summary, $action, $language = '', $args = '' ) { |
73 | parent::updateSummary( $summary, $action, $language, $args ); |
74 | if ( $summary !== null ) { |
75 | $summary->addAutoCommentArgs( [ $this->formId->getSerialization() ] ); |
76 | } |
77 | } |
78 | |
79 | } |