Passed
Push — master ( 6b49ff...b93f48 )
by Paweł
05:24
created

FindOrCreate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A findOrCreate() 0 8 2
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 12.06.2018
6
 */
7
8
namespace app\components\traits;
9
10
11
use yii\db\ActiveRecord;
12
13
trait FindOrCreate
14
{
15
    public function findOrCreate(array $conditions, string $class): ActiveRecord
16
    {
17
        $model = $class::findOne($conditions);
18
        if ($model === null) {
19
            $model = new $class($conditions);
20
        }
21
22
        return $model;
23
    }
24
}