Test Failed
Push — master ( 8f2167...5d2217 )
by Georgi
08:27
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 \Epesi\Core\Data\Model
0 ignored issues
show
Bug introduced by
The type Epesi\Core\Data\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
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 Epesi\Core\Data\Model.
Loading history...
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...
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
	
47
	// to be removed for atk4/data 2.0
48
	public function addFields($fields = [], $defaults = [])
49
	{
50
	    foreach ($fields as $key => $field) {
51
	        if (!is_int($key)) {
52
	            // field name can be passed as array key
53
	            $name = $key;
54
	        } elseif (is_string($field)) {
55
	            // or it can be simple string = field name
56
	            $name = $field;
57
	            $field = [];
58
	        } elseif (is_array($field) && isset($field[0]) && is_string($field[0])) {
59
	            // or field name can be passed as first element of seed array (old behaviour)
60
	            $name = array_shift($field);
61
	        } else {
62
	            // some unsupported format, maybe throw exception here?
63
	            continue;
64
	        }
65
	        
66
	        $seed = array_merge($defaults, (array) $field);
67
	        
68
	        $this->addField($name, $seed);
0 ignored issues
show
Bug introduced by
The method addField() does not exist on Epesi\Core\Data\HasEpesiConnection. Did you maybe mean addFields()? ( Ignorable by Annotation )

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

68
	        $this->/** @scrutinizer ignore-call */ 
69
                addField($name, $seed);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
	    }
70
	    
71
	    return $this;
72
	}
73
}