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

BelongsTo   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B getResult() 0 36 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 BelongsTo
23
 *
24
 * @package O2System\Reactor\Models\Sql\Relations
25
 */
26
class BelongsTo extends Abstracts\AbstractRelation
27
{
28
    /**
29
     * Get Result
30
     *
31
     * @return \O2System\Reactor\Models\Sql\DataObjects\Result\Row|bool
32
     */
33
    public function getResult()
34
    {
35
        if ($this->map->relationModel->row instanceof Sql\DataObjects\Result\Row) {
0 ignored issues
show
introduced by
$this->map->relationModel->row is always a sub-type of O2System\Reactor\Models\Sql\DataObjects\Result\Row.
Loading history...
36
37
            $criteria = $this->map->relationModel->row->offsetGet($this->map->relationForeignKey);
0 ignored issues
show
Bug introduced by
The property relationForeignKey does not seem to exist on O2System\Reactor\Models\...tions\Maps\Intermediary.
Loading history...
38
            $conditions = [$this->map->referencePrimaryKey => $criteria];
39
40
            if ($this->map->referenceModel instanceof Sql\Model) {
0 ignored issues
show
introduced by
$this->map->referenceModel is always a sub-type of O2System\Reactor\Models\Sql\Model.
Loading history...
Bug introduced by
The property referenceModel does not exist on O2System\Reactor\Models\...tions\Maps\Intermediary. Did you mean referenceTable?
Loading history...
41
                $result = $this->map->relationModel->qb
42
                    ->from($this->map->referenceModel->table)
43
                    ->getWhere($conditions, 1);
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
                        $this->map->referenceModel->result = new Sql\DataObjects\Result($result,
48
                            $this->map->referenceModel);
49
50
                        return $this->map->referenceModel->row = $this->map->referenceModel->result->first();
51
                    }
52
                }
53
            } elseif ( ! empty($this->map->referenceTable)) {
54
                $result = $this->map->relationModel->qb
55
                    ->from($this->map->referenceTable)
56
                    ->getWhere($conditions, 1);
57
58
                if ($result instanceof Result) {
59
                    if ($result->count() > 0) {
60
                        $result = new Sql\DataObjects\Result($result, $this->map->relationModel);
61
62
                        return $result->first();
63
                    }
64
                }
65
            }
66
        }
67
68
        return false;
69
    }
70
}