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

Snapshot::notify()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
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\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