Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ChangeOpRepresentationList
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
7
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
 apply
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 validate
100.00% covered (success)
100.00%
2 / 2
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
 getChangeOps
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\Model\Form;
8use Wikibase\Lexeme\MediaWiki\Api\Summary\SummaryAggregator;
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 ChangeOpRepresentationList implements ChangeOp {
19
20    private const SUMMARY_ACTION_AGGREGATE = 'update-form-representations';
21
22    /**
23     * @var ChangeOp[]
24     */
25    private $changeOps;
26
27    /**
28     * @var SummaryAggregator
29     */
30    private $summaryAggregator;
31
32    /**
33     * @param ChangeOp[] $changeOps
34     */
35    public function __construct( array $changeOps ) {
36        $this->changeOps = $changeOps;
37        $this->summaryAggregator = new SummaryAggregator( self::SUMMARY_ACTION_AGGREGATE );
38    }
39
40    public function apply( EntityDocument $entity, Summary $summary = null ) {
41        Assert::parameterType( Form::class, $entity, '$entity' );
42
43        foreach ( $this->changeOps as $changeOp ) {
44            $subSummary = new Summary();
45            $changeOp->apply( $entity, $subSummary );
46
47            if ( $summary !== null ) {
48                $this->summaryAggregator->overrideSummary( $summary, $subSummary );
49            }
50        }
51
52        return new DummyChangeOpResult();
53    }
54
55    public function validate( EntityDocument $entity ) {
56        // TODO: should rather combine the validation results from individual change ops
57        // OR: return error on first validation error occurred
58        Assert::parameterType( Form::class, $entity, '$entity' );
59
60        return Result::newSuccess();
61    }
62
63    public function getActions() {
64        // TODO: should rather combine the actions of individual change ops
65        return [ EntityPermissionChecker::ACTION_EDIT ];
66    }
67
68    /**
69     * Get the array of change operations.
70     *
71     * @return ChangeOp[]
72     */
73    public function getChangeOps() {
74        return $this->changeOps;
75    }
76
77}