Test Failed
Push — v2 ( 737a06 )
by Berend
03:55
created

SoftDelete::initSoftDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace miBadger\ActiveRecord\Traits;
4
5
use miBadger\Query\Query;
6
use miBadger\ActiveRecord\ColumnProperty;
7
8
const TRAIT_SOFT_DELETE_FIELD_KEY = "soft_delete";
9
10
trait SoftDelete
11
{
12
	protected $softDelete;
13
14
	protected function initSoftDelete()
15
	{
16
		$this->softDelete = false;
17
18
		$this->extendTableDefinition(TRAIT_SOFT_DELETE_FIELD_KEY, [
0 ignored issues
show
Bug introduced by
It seems like extendTableDefinition() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
			'value' => &$this->softDelete,
20
			'validate' => null,
21
			'default' => 0,
22
			'type' => 'INT',
23
			'length' => 1,
24
			'properties' => ColumnProperty::NOT_NULL
25
		]);
26
27
		$this->registerSearchHook(TRAIT_SOFT_DELETE_FIELD_KEY, 'softDeleteSearchHook');
0 ignored issues
show
Bug introduced by
It seems like registerSearchHook() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
	}
29
30
	protected function softDeleteSearchHook(Query $query)
31
	{
32
		$query->where(TRAIT_SOFT_DELETE_FIELD_KEY, '=', 0);
33
	}
34
35
	public function getSoftDeleteFieldName()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
	{
37
		return TRAIT_SOFT_DELETE_FIELD_KEY;
38
	}
39
	
40
	public function softDelete()
41
	{
42
		$this->softDelete = true;
43
		return $this;
44
	}
45
46
	public function softRestore()
47
	{
48
		$this->softDelete = false;
49
		return $this;
50
	}
51
52
	public function getDeletionStatus() 
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
53
	{
54
		return $this->softDelete;
55
	}
56
}