BasicEntityRemover::removeEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Wikibase\QueryEngine\SQLStore\EntityStore;
4
5
use Wikibase\DataModel\Entity\EntityDocument;
6
use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class BasicEntityRemover implements EntityRemovalStrategy {
13
14
	private $snakRemover;
15
16
	public function __construct( SnakRemover $snakRemover ) {
17
		$this->snakRemover = $snakRemover;
18
	}
19
20
	public function removeEntity( EntityDocument $entity ) {
21
		$this->snakRemover->removeSnaksOfSubject( $entity->getId() );
0 ignored issues
show
Bug introduced by
It seems like $entity->getId() can be null; however, removeSnaksOfSubject() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
22
	}
23
24
	/**
25
	 * @param EntityDocument $entity
26
	 *
27
	 * @return boolean
28
	 */
29
	public function canRemove( EntityDocument $entity ) {
30
		return true;
31
	}
32
33
}
34