Test Failed
Push — master ( 63bd73...510036 )
by Georgi
03:14
created

HasEpesiConnection::addFields()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
nc 5
nop 2
dl 0
loc 24
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Epesi\Core\Data;
4
5
trait HasEpesiConnection
6
{
7
	/**
8
	 * Create atk4 model and assign default persistence
9
	 * 
10
	 * @param array $defaults
11
	 * 
12
	 * @return \atk4\data\Model
13
	 */
14
	public static function create($defaults = [])
15
	{
16
		$atkDb = app()->make(Persistence\SQL::class);
17
		
18
		return new static($atkDb, $defaults);
0 ignored issues
show
Unused Code introduced by
The call to Epesi\Core\Data\HasEpesiConnection::__construct() has too many arguments starting with $atkDb. ( Ignorable by Annotation )

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

18
		return /** @scrutinizer ignore-call */ new static($atkDb, $defaults);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug Best Practice introduced by
The expression return new static($atkDb, $defaults) returns the type Epesi\Core\Data\HasEpesiConnection which is incompatible with the documented return type atk4\data\Model.
Loading history...
19
	}
20
	
21
	public static function migrate()
22
	{
23
		return \atk4\schema\Migration::getMigration(static::create())->migrate();
24
	}
25
	
26
	public function addCrits($crits = [])
27
	{
28
		foreach ($crits as $condition) {
29
			$this->addCondition(...$condition);
0 ignored issues
show
Bug introduced by
It seems like addCondition() 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

29
			$this->/** @scrutinizer ignore-call */ 
30
          addCondition(...$condition);
Loading history...
30
		}
31
		
32
		return $this;
33
	}
34
	
35
	/**
36
	 * Get the values of a given key.
37
	 *
38
	 * @param  string|array  $value
39
	 * @param  string|null  $key
40
	 * @return static
41
	 */
42
	public static function pluck($value, $key = null)
43
	{
44
	    return collect(self::create()->export())->pluck($value, $key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return collect(self::cre...))->pluck($value, $key) returns the type Illuminate\Support\Collection which is incompatible with the documented return type Epesi\Core\Data\HasEpesiConnection.
Loading history...
45
	}
46
}