BasicEntityRemover   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A removeEntity() 0 3 1
A canRemove() 0 3 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