Test Failed
Push — master ( 4bba41...7bbbf4 )
by Julien
04:35
created

Manager::setBehavior()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Model;
13
14
use Phalcon\Mvc\Model\Manager as PhalconModelsManager;
15
use Phalcon\Mvc\Model\BehaviorInterface;
16
use Phalcon\Mvc\ModelInterface;
17
18
class Manager extends PhalconModelsManager implements ManagerInterface
19
{
20
    public function getBehaviors(): array
21
    {
22
        return $this->behaviors;
23
    }
24
    
25
    public function setBehaviors(array $behaviors): void
26
    {
27
        $this->behaviors = $behaviors;
28
    }
29
    
30
    /**
31
     * Get a behavior using the behavior name
32
     */
33
    public function getBehavior(ModelInterface $model, string $behaviorName)
34
    {
35
        $entityName = strtolower(get_class($model));
36
        
37
        return $this->behaviors[$entityName][$behaviorName] ?? null;
38
    }
39
    
40
    /**
41
     * Set a behavior using the behavior name
42
     */
43
    public function setBehavior(ModelInterface $model, string $behaviorName, BehaviorInterface $behavior): void
44
    {
45
        $entityName = strtolower(get_class($model));
46
        
47
        if (!isset($this->behaviors[$entityName])) {
48
            $this->behaviors[$entityName] = [];
49
        }
50
        
51
        $this->behaviors[$entityName][$behaviorName] = $behavior;
52
    }
53
    
54
    /**
55
     * Return true if the behavior is set
56
     */
57
    public function hasBehavior(ModelInterface $model, string $behaviorName): bool
58
    {
59
        $entityName = strtolower(get_class($model));
60
        
61
        return isset($this->behaviors[$entityName][$behaviorName]);
62
    }
63
}
64