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

SaveRelationsTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isTransactional() 0 7 2
A load() 0 7 3
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
}