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 | public function getActions() { |
35 | return []; |
36 | } |
37 | |
38 | public function validate( EntityDocument $entity ) { |
39 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
40 | '@phan-var Lexeme $entity'; |
41 | |
42 | /** @var Lexeme $entity */ |
43 | |
44 | foreach ( $this->changeOpForForm as $formId => $changeOps ) { |
45 | if ( $entity->getForms()->getById( new FormId( $formId ) ) === null ) { |
46 | return Result::newError( [ |
47 | Error::newError( |
48 | 'Form does not exist', |
49 | null, |
50 | 'form-not-found', |
51 | [ $formId ] |
52 | ), |
53 | ] ); |
54 | } |
55 | } |
56 | |
57 | return Result::newSuccess(); |
58 | } |
59 | |
60 | public function apply( EntityDocument $entity, ?Summary $summary = null ) { |
61 | Assert::parameterType( Lexeme::class, $entity, '$entity' ); |
62 | '@phan-var Lexeme $entity'; |
63 | /** @var Lexeme $entity */ |
64 | |
65 | foreach ( $this->changeOpForForm as $formId => $changeOp ) { |
66 | $form = $entity->getForms()->getById( new FormId( $formId ) ); |
67 | if ( $form === null ) { |
68 | throw new ChangeOpApplyException( 'wikibase-validator-form-not-found' ); |
69 | } |
70 | |
71 | // Passes summary albeit there is no clear definition how summaries should be combined |
72 | $changeOp->apply( $form, $summary ); |
73 | } |
74 | |
75 | return new DummyChangeOpResult(); |
76 | } |
77 | |
78 | } |