Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpSenseClone | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
apply | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\ChangeOp; |
4 | |
5 | use ValueValidators\Result; |
6 | use Wikibase\DataModel\Entity\EntityDocument; |
7 | use Wikibase\Lexeme\Domain\DummyObjects\BlankSense; |
8 | use Wikibase\Lexeme\Domain\Model\Sense; |
9 | use Wikibase\Lib\Summary; |
10 | use Wikibase\Repo\ChangeOp\ChangeOp; |
11 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
12 | use Wikibase\Repo\Store\EntityPermissionChecker; |
13 | use Wikimedia\Assert\Assert; |
14 | |
15 | /** |
16 | * Copy the properties of the existing Sense ($sourceSense) into the passed BlankSense ($entity) |
17 | * |
18 | * @license GPL-2.0-or-later |
19 | */ |
20 | class ChangeOpSenseClone implements ChangeOp { |
21 | |
22 | private $sourceSense; |
23 | |
24 | /** |
25 | * @param Sense $sourceSense |
26 | */ |
27 | public function __construct( Sense $sourceSense ) { |
28 | $this->sourceSense = $sourceSense->copy(); |
29 | } |
30 | |
31 | public function apply( EntityDocument $entity, Summary $summary = null ) { |
32 | Assert::parameterType( BlankSense::class, $entity, '$entity' ); |
33 | '@phan-var Sense $entity'; |
34 | |
35 | /** @var Sense $entity */ |
36 | |
37 | $entity->getGlosses()->addAll( $this->sourceSense->getGlosses() ); |
38 | |
39 | // Resets statement GUIDs so they do not mention the former (sense) entity |
40 | // ChangeOpSenseAdd::apply() ensures a new - suitable - GUID is applied once new sense id known |
41 | foreach ( $this->sourceSense->getStatements() as $index => $statement ) { |
42 | $statement->setGuid( null ); |
43 | $entity->getStatements()->addStatement( $statement, $index ); |
44 | } |
45 | |
46 | // TODO summary; This is currently only used as part of merging to copy senses |
47 | // from the source lexemes onto the target. |
48 | // Generating a summary here is not necessary as of now. |
49 | |
50 | return new DummyChangeOpResult(); |
51 | } |
52 | |
53 | public function validate( EntityDocument $entity ): Result { |
54 | Assert::parameterType( BlankSense::class, $entity, '$entity' ); |
55 | |
56 | return Result::newSuccess(); |
57 | } |
58 | |
59 | public function getActions() { |
60 | return [ EntityPermissionChecker::ACTION_EDIT ]; |
61 | } |
62 | |
63 | } |