Passed
Push — master ( af81a3...50b6e9 )
by Julien
12:38 queued 07:47
created

Snapshot   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
dl 0
loc 21
c 2
b 0
f 0
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeCreate() 0 4 1
A notify() 0 11 3
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\Behavior;
13
14
use Phalcon\Mvc\Model;
15
use Phalcon\Mvc\Model\Behavior;
16
use Phalcon\Mvc\ModelInterface;
17
18
class Snapshot extends Behavior
19
{
20
    use SkippableTrait;
21
    
22 2
    public function notify(string $type, ModelInterface $model): ?bool
23
    {
24 2
        if (!$this->isEnabled()) {
25
            return null;
26
        }
27
        
28 2
        if ($type === 'beforeCreate') {
29 2
            $this->beforeCreate($model);
30
        }
31
        
32 2
        return null;
33
    }
34
    
35 2
    public function beforeCreate(ModelInterface $model): void
36
    {
37 2
        assert($model instanceof Model);
38 2
        $model->setSnapshotData($model->toArray());
39
    }
40
}
41