Passed
Push — main ( 12de61...3daa58 )
by Sammy
01:31
created

Model::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace HexMakina\TightORM;
4
5
use HexMakina\Crudites\Crudites;
6
use HexMakina\Crudites\Table\Row;
7
use HexMakina\Crudites\CruditesException;
8
use HexMakina\BlackBox\Database\TableInterface;
0 ignored issues
show
Bug introduced by
The type HexMakina\BlackBox\Database\TableInterface 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...
9
use HexMakina\BlackBox\Database\SelectInterface;
10
11
abstract class Model extends Row
12
{
13
    // returns the value of the PK, whatever it's name
14
    // returns the name of the PK, if $mode === 'name'
15
    public function id($mode = null)
16
    {
17
        $primary_key = $this->table()->autoIncrementedPrimaryKey();
18
19
        if (is_null($primary_key) && count($pks = $this->table()->primaryKeys()) == 1) {
20
            $primary_key = current($pks);
21
        }
22
23
        return $mode === 'name' ? $primary_key->name() : $this->get($primary_key->name());
24
    }
25
26
    // Model might have properties, if not, use row data
27
    public function get($prop_name)
28
    {
29
        if (property_exists($this, $prop_name) === true) {
30
            return $this->$prop_name;
31
        }
32
33
        return parent::get($prop_name);
0 ignored issues
show
introduced by
The method get() does not exist on HexMakina\Crudites\Table\Row. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

33
        return parent::/** @scrutinizer ignore-call */ get($prop_name);
Loading history...
34
    }
35
36
    // Model might have properties, if not, use row data
37
    public function set($prop_name, $value)
38
    {
39
        if (property_exists($this, $prop_name) === true) {
40
            $this->$prop_name = $value;
41
        } else {
42
            parent::set($prop_name, $value);
0 ignored issues
show
introduced by
The method set() does not exist on HexMakina\Crudites\Table\Row. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

42
            parent::/** @scrutinizer ignore-call */ 
43
                    set($prop_name, $value);
Loading history...
43
        }
44
    }
45
}
46