Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.48% |
19 / 21 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
ChangeOpsFormsEdit | |
90.48% |
19 / 21 |
|
50.00% |
2 / 4 |
8.06 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getActions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validate | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
apply | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 |
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\ChangeOp; |
12 | use Wikibase\Repo\ChangeOp\ChangeOpApplyException; |
13 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
14 | use Wikimedia\Assert\Assert; |
15 | |
16 | /** |
17 | * This is missing aggregation of summaries but they never would see light of day due to |
18 | * EditEntity::modifyEntity() & EditEntity::getSummary() anyways |
19 | * |
20 | * @license GPL-2.0-or-later |
21 | */ |
22 | class ChangeOpsFormsEdit implements ChangeOp { |
23 | |
24 | /** @var ChangeOp[] */ |
25 | private array $changeOpForForm; |
26 | |
27 | /** |
28 | * @param ChangeOp[] $changeOpForForm [ string $formId => ChangeOp $changeOp ] |
29 | */ |
30 | public function __construct( array $changeOpForForm ) { |
31 | $this->changeOpForForm = $changeOpForForm; |
32 | } |
33 | |
34 | /** @inheritDoc */ |
35 | public function getActions() { |
36 | return []; |
37 | } |
38 | |
39 | /** @inheritDoc */ |
40 | public function validate( EntityDocument $entity ) { |
41 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
42 | '@phan-var Lexeme $entity'; |
43 | |
44 | /** @var Lexeme $entity */ |
45 | |
46 | foreach ( $this->changeOpForForm as $formId => $changeOps ) { |
47 | if ( $entity->getForms()->getById( new FormId( $formId ) ) === null ) { |
48 | return Result::newError( [ |
49 | Error::newError( |
50 | 'Form does not exist', |
51 | null, |
52 | 'form-not-found', |
53 | [ $formId ] |
54 | ), |
55 | ] ); |
56 | } |
57 | } |
58 | |
59 | return Result::newSuccess(); |
60 | } |
61 | |
62 | /** @inheritDoc */ |
63 | public function apply( EntityDocument $entity, ?Summary $summary = null ) { |
64 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
65 | '@phan-var Lexeme $entity'; |
66 | /** @var Lexeme $entity */ |
67 | |
68 | foreach ( $this->changeOpForForm as $formId => $changeOp ) { |
69 | $form = $entity->getForms()->getById( new FormId( $formId ) ); |
70 | if ( $form === null ) { |
71 | throw new ChangeOpApplyException( 'wikibase-validator-form-not-found' ); |
72 | } |
73 | |
74 | // Passes summary albeit there is no clear definition how summaries should be combined |
75 | $changeOp->apply( $form, $summary ); |
76 | } |
77 | |
78 | return new DummyChangeOpResult(); |
79 | } |
80 | |
81 | } |