GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 86dce3...98cf71 )
by Nur
02:40
created

HasMany   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B getResult() 0 32 8
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Models\Sql\Relations;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Database\DataObjects\Result;
19
use O2System\Reactor\Models\Sql;
20
21
/**
22
 * Class HasMany
23
 *
24
 * @package O2System\Reactor\Models\Sql\Relations
25
 */
26
class HasMany extends Sql\Relations\Abstracts\AbstractRelation
27
{
28
    /**
29
     * HasMany::getResult
30
     *
31
     * @return \O2System\Reactor\Models\Sql\DataObjects\Result|bool
32
     */
33
    public function getResult()
34
    {
35
        if ($this->map->referenceModel->row instanceof Sql\DataObjects\Result\Row) {
0 ignored issues
show
Bug introduced by
The property referenceModel does not exist on O2System\Reactor\Models\...tions\Maps\Intermediary. Did you mean referenceTable?
Loading history...
introduced by
$this->map->referenceModel->row is always a sub-type of O2System\Reactor\Models\Sql\DataObjects\Result\Row.
Loading history...
36
37
            $criteria = $this->map->referenceModel->row->offsetGet($this->map->referenceModel->primaryKey);
38
            $conditions = [$this->map->relationForeignKey => $criteria];
0 ignored issues
show
Bug introduced by
The property relationForeignKey does not seem to exist on O2System\Reactor\Models\...tions\Maps\Intermediary.
Loading history...
39
40
            if ($this->map->relationModel instanceof Sql\Model) {
0 ignored issues
show
introduced by
$this->map->relationModel is always a sub-type of O2System\Reactor\Models\Sql\Model.
Loading history...
41
                $result = $this->map->relationModel->qb
42
                    ->from($this->map->relationTable)
43
                    ->getWhere($conditions);
44
45
                if ($result instanceof Result) {
0 ignored issues
show
introduced by
$result is always a sub-type of O2System\Database\DataObjects\Result.
Loading history...
46
                    if ($result->count() > 0) {
47
                        return $this->map->relationModel->result = new Sql\DataObjects\Result($result,
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map->relat...is->map->relationModel) returns the type O2System\Reactor\Models\Sql\DataObjects\Result which is incompatible with the return type mandated by O2System\Reactor\Models\...ctRelation::getResult() of O2System\Reactor\Models\...esult\Row|array|boolean.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
48
                            $this->map->relationModel);
49
                    }
50
                }
51
            } elseif ( ! empty($this->map->relationTable)) {
52
                $result = $this->map->referenceModel->qb
53
                    ->from($this->map->relationTable)
54
                    ->getWhere($conditions);
55
56
                if ($result instanceof Result) {
57
                    if ($result->count() > 0) {
58
                        return new Sql\DataObjects\Result($result, $this->map->referenceModel);
59
                    }
60
                }
61
            }
62
        }
63
64
        return false;
65
    }
66
}