Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ChangeOpFormAdd
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 apply
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
2
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\ChangeOpBase;
12use Wikibase\Repo\ChangeOp\DummyChangeOpResult;
13use Wikimedia\Assert\Assert;
14
15/**
16 * @license GPL-2.0-or-later
17 */
18class ChangeOpFormAdd extends ChangeOpBase {
19
20    private const SUMMARY_ACTION_ADD = 'add-form';
21
22    /**
23     * @var ChangeOp
24     */
25    private $changeOpForm;
26
27    /**
28     * @param ChangeOp $changeOpForm
29     */
30    public function __construct( ChangeOp $changeOpForm ) {
31        $this->changeOpForm = $changeOpForm;
32    }
33
34    public function validate( EntityDocument $entity ): Result {
35        Assert::parameterType( Lexeme::class, $entity, '$entity' );
36
37        return Result::newSuccess();
38    }
39
40    public function apply( EntityDocument $entity, Summary $summary = null ) {
41        Assert::parameterType( Lexeme::class, $entity, '$entity' );
42        '@phan-var Lexeme $entity';
43
44        /** @var Lexeme $entity */
45
46        $form = new BlankForm();
47
48        $entity->addOrUpdateForm( $form );
49        $this->changeOpForm->apply( $form, null );
50
51        if ( $summary !== null ) {
52            // TODO: consistently do not extend ChangeOpBase?
53            $this->updateSummary(
54                $summary,
55                self::SUMMARY_ACTION_ADD,
56                null,
57                array_values( $form->getRepresentations()->toTextArray() )
58            );
59            // TODO: use FormId not string?
60            $summary->addAutoCommentArgs( $form->getId()->getSerialization() );
61        }
62
63        return new DummyChangeOpResult();
64    }
65
66}