Completed
Push — master ( 72048b...aafbe4 )
by Peter
18:50
created

AspectManager::removeAspect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 18.06.18
6
 * Time: 21:59
7
 */
8
9
namespace Maslosoft\Mangan;
10
11
12
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
13
use Maslosoft\Mangan\Interfaces\AspectsInterface;
14
15
class AspectManager
16
{
17
	/**
18
	 * Gracefully add aspect, this will check
19
	 * if model implements AspectsInterface
20
	 * and add only if it does.
21
	 *
22
	 * @see AspectsInterface
23
	 * @param AnnotatedInterface $model
24
	 * @param                    $aspect
25
	 */
26 119
	public static function addAspect(AnnotatedInterface $model, $aspect)
27
	{
28 119
		if($model instanceof AspectsInterface)
29
		{
30 44
			$model->addAspect($aspect);
31
		}
32 119
	}
33
34
	/**
35
	 * Gracefully remove aspect, this will check
36
	 * if model implements AspectsInterface
37
	 * and remove only if it does.
38
	 *
39
	 * @see AspectsInterface
40
	 * @param AnnotatedInterface $model
41
	 * @param                    $aspect
42
	 */
43 119
	public static function removeAspect(AnnotatedInterface $model, $aspect)
44
	{
45 119
		if($model instanceof AspectsInterface)
46
		{
47 44
			$model->removeAspect($aspect);
48
		}
49 119
	}
50
51
	/**
52
	 * Gracefully check if has aspect, this will check
53
	 * if model implements `AspectsInterface`
54
	 * and check only if it does. If model does not
55
	 * implement AspectsInterface it will return `false`,
56
	 * like if it has no such aspect.
57
	 *
58
	 * @see AspectsInterface
59
	 * @param AnnotatedInterface $model
60
	 * @param                    $aspect
61
	 * @return bool|string
62
	 */
63 27
	public static function hasAspect(AnnotatedInterface $model, $aspect)
64
	{
65 27
		if($model instanceof AspectsInterface)
66
		{
67 14
			return $model->hasAspect($aspect);
68
		}
69 13
		return false;
70
	}
71
}