These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Wikibase\DataModel\Services\Diff; |
||
4 | |||
5 | use InvalidArgumentException; |
||
6 | use Wikibase\DataModel\Entity\EntityDocument; |
||
7 | use Wikibase\DataModel\Entity\Property; |
||
8 | use Wikibase\DataModel\Services\Diff\Internal\FingerprintPatcher; |
||
9 | |||
10 | /** |
||
11 | * @since 1.0 |
||
12 | * |
||
13 | * @license GPL-2.0+ |
||
14 | * @author Jeroen De Dauw < [email protected] > |
||
15 | */ |
||
16 | class PropertyPatcher implements EntityPatcherStrategy { |
||
17 | |||
18 | /** |
||
19 | * @var FingerprintPatcher |
||
20 | */ |
||
21 | private $fingerprintPatcher; |
||
22 | |||
23 | /** |
||
24 | * @var StatementListPatcher |
||
25 | */ |
||
26 | private $statementListPatcher; |
||
27 | |||
28 | public function __construct() { |
||
29 | 4 | $this->fingerprintPatcher = new FingerprintPatcher(); |
|
30 | 4 | $this->statementListPatcher = new StatementListPatcher(); |
|
31 | 4 | } |
|
32 | 4 | ||
33 | /** |
||
34 | * @param string $entityType |
||
35 | * |
||
36 | * @return boolean |
||
37 | */ |
||
38 | public function canPatchEntityType( $entityType ) { |
||
39 | 1 | return $entityType === 'property'; |
|
40 | 1 | } |
|
41 | |||
42 | /** |
||
43 | * @param EntityDocument $entity |
||
44 | * @param EntityDiff $patch |
||
45 | * |
||
46 | * @throws InvalidArgumentException |
||
47 | */ |
||
48 | public function patchEntity( EntityDocument $entity, EntityDiff $patch ) { |
||
49 | $this->assertIsProperty( $entity ); |
||
50 | 3 | ||
51 | 3 | $this->patchProperty( $entity, $patch ); |
|
0 ignored issues
–
show
|
|||
52 | } |
||
53 | 2 | ||
54 | 2 | private function assertIsProperty( EntityDocument $property ) { |
|
55 | if ( !( $property instanceof Property ) ) { |
||
56 | 3 | throw new InvalidArgumentException( '$property must be an instance of Property' ); |
|
57 | 3 | } |
|
58 | 1 | } |
|
59 | |||
60 | 2 | private function patchProperty( Property $property, EntityDiff $patch ) { |
|
61 | $this->fingerprintPatcher->patchFingerprint( $property->getFingerprint(), $patch ); |
||
62 | 2 | ||
63 | 2 | $this->statementListPatcher->patchStatementList( |
|
64 | $property->getStatements(), |
||
65 | 2 | $patch->getClaimsDiff() |
|
66 | 2 | ); |
|
67 | 2 | } |
|
68 | 2 | ||
69 | } |
||
70 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.