Passed
Pull Request — master (#38)
by Leandro
02:04
created

SaveRelationsTrait::isTransactional()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace lhs\Yii2SaveRelationsBehavior;
4
5
trait SaveRelationsTrait
6
{
7
8
    /**
9
     * Populates the relations with input data.
10
     */
11
    public function load($data, $formName = null)
12
    {
13
        $loaded = parent::load($data, $formName);
14
        if ($loaded && $this->hasMethod('loadRelations')) {
0 ignored issues
show
Bug introduced by
It seems like hasMethod() 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

14
        if ($loaded && $this->/** @scrutinizer ignore-call */ hasMethod('loadRelations')) {
Loading history...
15
            $this->loadRelations($data);
0 ignored issues
show
Bug introduced by
It seems like loadRelations() 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

15
            $this->/** @scrutinizer ignore-call */ 
16
                   loadRelations($data);
Loading history...
16
        }
17
        return $loaded;
18
    }
19
20
    /**
21
     * Starts transaction if [autoStartTransaction] has been defined
22
     */
23
    public function isTransactional($operation)
24
    {
25
        if ($this->hasProperty('autoStartTransaction')) {
0 ignored issues
show
Bug introduced by
It seems like hasProperty() 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

25
        if ($this->/** @scrutinizer ignore-call */ hasProperty('autoStartTransaction')) {
Loading history...
26
            return $this->autoStartTransaction;
27
        }
28
29
        return parent::isTransactional($operation);
30
    }
31
32
}