Completed
Push — master ( db5413...63e986 )
by Jonas
26s queued 11s
created

TracksIntermediateScopes   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 1
b 0
f 0
dl 0
loc 80
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withoutIntermediateScope() 0 11 2
A withoutIntermediateScopes() 0 11 3
A withIntermediateScope() 0 9 2
A removedIntermediateScopes() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelAdjacencyList\Eloquent;
4
5
trait TracksIntermediateScopes
6
{
7
	/**
8
	 * Applied intermediate Scopes.
9
	 *
10
	 * @var array
11
	 */
12
	protected $intermediateScopes = [];
13
14
	/**
15
	 * Removed intermediate Scopes.
16
	 *
17
	 * @var array
18
	 */
19
	protected $removedIntermediateScopes = [];
20
21
	/**
22
	 * Register a new intermediate scope.
23
	 *
24
	 * @param  string  $identifier
25
	 * @param  \Illuminate\Database\Eloquent\Scope|\Closure  $scope
26
	 * @return $this
27
	 */
28
	public function withIntermediateScope($identifier, $scope)
29
	{
30
		$this->intermediateScopes[$identifier] = $scope;
31
32
		if (method_exists($scope, 'extend')) {
33
			$scope->extend($this);
34
		}
35
36
		return $this;
37
	}
38
39
	/**
40
	 * Remove a registered intermediate scope.
41
	 *
42
	 * @param  \Illuminate\Database\Eloquent\Scope|string  $scope
43
	 * @return $this
44
	 */
45
	public function withoutIntermediateScope($scope)
46
	{
47
		if (!is_string($scope)) {
48
			$scope = get_class($scope);
49
		}
50
51
		unset($this->intermediateScopes[$scope]);
52
53
		$this->removedIntermediateScopes[] = $scope;
54
55
		return $this;
56
	}
57
58
	/**
59
	 * Remove all or passed registered intermediate Scopes.
60
	 *
61
	 * @param  array|null  $scopes
62
	 * @return $this
63
	 */
64
	public function withoutIntermediateScopes(array $scopes = null)
65
	{
66
		if (!is_array($scopes)) {
67
			$scopes = array_keys($this->intermediateScopes);
68
		}
69
70
		foreach ($scopes as $scope) {
71
			$this->withoutIntermediateScope($scope);
72
		}
73
74
		return $this;
75
	}
76
77
	/**
78
	 * Get an array of intermediate Scopes that were removed from the query.
79
	 *
80
	 * @return array
81
	 */
82
	public function removedIntermediateScopes()
83
	{
84
		return $this->removedIntermediateScopes;
85
	}
86
}
87