Test Failed
Push — master ( fcd77b...792760 )
by Julien
04:24
created

Snapshot::getSnapshotBehavior()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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\ModelInterface;
15
use Zemit\Mvc\Model\AbstractTrait\AbstractEventsManager;
16
use Zemit\Mvc\Model\Behavior\Snapshot as SnapshotBehavior;
17
18
trait Snapshot
19
{
20
    use AbstractEventsManager;
21
    
22
    public SnapshotBehavior $snapshotBehavior;
23
    
24
    abstract protected function keepSnapshots(bool $keepSnapshot): void;
25
    
26
    /**
27
     * Initializing Snapshot
28
     */
29
    public function initializeSnapshot(?array $options = null): void
30
    {
31
        $options ??= $this->getOptionsManager()->get('snapshot') ?? [];
0 ignored issues
show
Bug introduced by
It seems like getOptionsManager() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        $options ??= $this->/** @scrutinizer ignore-call */ getOptionsManager()->get('snapshot') ?? [];
Loading history...
32
        $this->keepSnapshots($options['keepSnapshots'] ?? true);
33
        $this->addBehavior(new SnapshotBehavior($options));
0 ignored issues
show
Bug introduced by
It seems like addBehavior() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               addBehavior(new SnapshotBehavior($options));
Loading history...
34
    }
35
    
36
    /**
37
     * Set Snapshot Behavior
38
     */
39
    public function setSnapshotBehavior(SnapshotBehavior $snapshotBehavior): void
40
    {
41
        $this->snapshotBehavior = $snapshotBehavior;
42
        $this->addBehavior($this->snapshotBehavior);
43
    }
44
    
45
    /**
46
     * Get Snapshot Behavior
47
     */
48
    public function getSnapshotBehavior(): SnapshotBehavior
49
    {
50
        return $this->snapshotBehavior;
51
    }
52
    
53
    /**
54
     * Check if the model has changed and return null otherwise
55
     */
56
    public function hasChangedCallback(callable $callback, bool $anyField = true): \Closure
57
    {
58
        return function (ModelInterface $model, $field) use ($callback, $anyField) {
59
            return (!$model->hasSnapshotData()
0 ignored issues
show
Bug introduced by
The method hasSnapshotData() does not exist on Phalcon\Mvc\ModelInterface. It seems like you code against a sub-type of Phalcon\Mvc\ModelInterface such as Phalcon\Mvc\Model or Zemit\Models\Setting or Zemit\Models\Category or Zemit\Models\Audit or Zemit\Models\UserGroup or Zemit\Models\User or Zemit\Models\Field or Zemit\Models\Page or Zemit\Models\Log or Zemit\Models\File or Zemit\Models\Role or Zemit\Models\GroupRole or Zemit\Models\Template or Zemit\Models\AuditDetail or Zemit\Models\UserType or Zemit\Models\Post or Zemit\Models\PostCategory or Zemit\Models\Session or Zemit\Models\TranslateField or Zemit\Models\GroupType or Zemit\Models\Translate or Zemit\Models\Email or Zemit\Models\Data or Zemit\Models\Group or Zemit\Models\Lang or Zemit\Models\EmailFile or Zemit\Models\TranslateTable or Zemit\Models\SiteLang or Zemit\Models\UserRole or Zemit\Models\Flag or Zemit\Models\Menu or Zemit\Models\Site or Zemit\Models\Type or Zemit\Models\Channel or Zemit\Models\Meta. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
            return (!$model->/** @scrutinizer ignore-call */ hasSnapshotData()
Loading history...
60
                || $model->hasChanged($anyField ? null : $field)
0 ignored issues
show
Bug introduced by
The method hasChanged() does not exist on Phalcon\Mvc\ModelInterface. It seems like you code against a sub-type of Phalcon\Mvc\ModelInterface such as Phalcon\Mvc\Model or Zemit\Models\Setting or Zemit\Models\Category or Zemit\Models\Audit or Zemit\Models\UserGroup or Zemit\Models\User or Zemit\Models\Field or Zemit\Models\Page or Zemit\Models\Log or Zemit\Models\File or Zemit\Models\Role or Zemit\Models\GroupRole or Zemit\Models\Template or Zemit\Models\AuditDetail or Zemit\Models\UserType or Zemit\Models\Post or Zemit\Models\PostCategory or Zemit\Models\Session or Zemit\Models\TranslateField or Zemit\Models\GroupType or Zemit\Models\Translate or Zemit\Models\Email or Zemit\Models\Data or Zemit\Models\Group or Zemit\Models\Lang or Zemit\Models\EmailFile or Zemit\Models\TranslateTable or Zemit\Models\SiteLang or Zemit\Models\UserRole or Zemit\Models\Flag or Zemit\Models\Menu or Zemit\Models\Site or Zemit\Models\Type or Zemit\Models\Channel or Zemit\Models\Meta. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
                || $model->/** @scrutinizer ignore-call */ hasChanged($anyField ? null : $field)
Loading history...
61
                || $model->hasUpdated($anyField ? null : $field))
0 ignored issues
show
Bug introduced by
The method hasUpdated() does not exist on Phalcon\Mvc\ModelInterface. It seems like you code against a sub-type of Phalcon\Mvc\ModelInterface such as Phalcon\Mvc\Model or Zemit\Models\Setting or Zemit\Models\Category or Zemit\Models\Audit or Zemit\Models\UserGroup or Zemit\Models\User or Zemit\Models\Field or Zemit\Models\Page or Zemit\Models\Log or Zemit\Models\File or Zemit\Models\Role or Zemit\Models\GroupRole or Zemit\Models\Template or Zemit\Models\AuditDetail or Zemit\Models\UserType or Zemit\Models\Post or Zemit\Models\PostCategory or Zemit\Models\Session or Zemit\Models\TranslateField or Zemit\Models\GroupType or Zemit\Models\Translate or Zemit\Models\Email or Zemit\Models\Data or Zemit\Models\Group or Zemit\Models\Lang or Zemit\Models\EmailFile or Zemit\Models\TranslateTable or Zemit\Models\SiteLang or Zemit\Models\UserRole or Zemit\Models\Flag or Zemit\Models\Menu or Zemit\Models\Site or Zemit\Models\Type or Zemit\Models\Channel or Zemit\Models\Meta. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
                || $model->/** @scrutinizer ignore-call */ hasUpdated($anyField ? null : $field))
Loading history...
62
                ? $callback($model, $field)
63
                : $model->readAttribute($field);
0 ignored issues
show
Bug introduced by
The method readAttribute() does not exist on Phalcon\Mvc\ModelInterface. It seems like you code against a sub-type of Phalcon\Mvc\ModelInterface such as Phalcon\Mvc\Model or Zemit\Models\Setting or Zemit\Models\Category or Zemit\Models\Audit or Zemit\Models\UserGroup or Zemit\Models\User or Zemit\Models\Field or Zemit\Models\Page or Zemit\Models\Log or Zemit\Models\File or Zemit\Models\Role or Zemit\Models\GroupRole or Zemit\Models\Template or Zemit\Models\AuditDetail or Zemit\Models\UserType or Zemit\Models\Post or Zemit\Models\PostCategory or Zemit\Models\Session or Zemit\Models\TranslateField or Zemit\Models\GroupType or Zemit\Models\Translate or Zemit\Models\Email or Zemit\Models\Data or Zemit\Models\Group or Zemit\Models\Lang or Zemit\Models\EmailFile or Zemit\Models\TranslateTable or Zemit\Models\SiteLang or Zemit\Models\UserRole or Zemit\Models\Flag or Zemit\Models\Menu or Zemit\Models\Site or Zemit\Models\Type or Zemit\Models\Channel or Zemit\Models\Meta. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
                : $model->/** @scrutinizer ignore-call */ readAttribute($field);
Loading history...
64
        };
65
    }
66
}
67