Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AddFormToLexemeChangeOp
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 apply
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getActions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikibase\Lexeme\DataAccess\ChangeOp;
4
5use ValueValidators\Result;
6use Wikibase\DataModel\Entity\EntityDocument;
7use Wikibase\Lexeme\Domain\DummyObjects\BlankForm;
8use Wikibase\Lexeme\Domain\Model\Lexeme;
9use Wikibase\Lib\Summary;
10use Wikibase\Repo\ChangeOp\ChangeOp;
11use Wikibase\Repo\ChangeOp\DummyChangeOpResult;
12use Wikibase\Repo\Store\EntityPermissionChecker;
13use Wikimedia\Assert\Assert;
14
15/**
16 * @license GPL-2.0-or-later
17 */
18class AddFormToLexemeChangeOp implements ChangeOp {
19
20    /**
21     * @var Lexeme
22     */
23    private $lexeme;
24
25    /**
26     * @var ChangeOp
27     */
28    private $changeOpFormEdit;
29
30    public function __construct( Lexeme $lexeme, ChangeOp $changeOpFormEdit ) {
31        $this->lexeme = $lexeme;
32        $this->changeOpFormEdit = $changeOpFormEdit;
33    }
34
35    public function validate( EntityDocument $form ) {
36        Assert::parameterType( BlankForm::class, $form, '$form' );
37
38        $this->changeOpFormEdit->validate( $form );
39
40        return Result::newSuccess();
41    }
42
43    public function apply( EntityDocument $form, Summary $summary = null ) {
44        Assert::parameterType( BlankForm::class, $form, '$form' );
45        '@phan-var BlankForm $form';
46
47        /** @var BlankForm $form */
48        $this->lexeme->addOrUpdateForm( $form );
49        $this->changeOpFormEdit->apply( $form );
50
51        return new DummyChangeOpResult();
52    }
53
54    public function getActions() {
55        return [ EntityPermissionChecker::ACTION_EDIT ];
56    }
57
58}