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

RelationTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasManyThrough() 0 5 1
A hasOne() 0 5 1
A belongsToMany() 0 5 1
A belongsTo() 0 5 1
A hasMany() 0 5 1
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\Traits;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Reactor\Models\Sql\DataObjects\Result;
19
use O2System\Reactor\Models\Sql\DataObjects\Result\Row;
20
use O2System\Reactor\Models\Sql\Model;
21
use O2System\Reactor\Models\Sql\Relations;
22
23
/**
24
 * Class RelationTrait
25
 *
26
 * @package O2System\Reactor\Models\Sql\Traits
27
 */
28
trait RelationTrait
29
{
30
    /**
31
     * Belongs To
32
     *
33
     * Belongs To is the inverse of one to one relationship.
34
     *
35
     * @param string|Model $referenceModel
36
     * @param string|null  $foreignKey
37
     * @param string|null  $primaryKey
38
     *
39
     * @return Row|bool
40
     */
41
    public function belongsTo($referenceModel, $foreignKey = null, $primaryKey = null)
42
    {
43
        return (new Relations\BelongsTo(
44
            new Relations\Maps\Inverse($this, $referenceModel, $foreignKey, $primaryKey)
0 ignored issues
show
Bug introduced by
$this of type O2System\Reactor\Models\Sql\Traits\RelationTrait is incompatible with the type O2System\Reactor\Models\Sql\Model expected by parameter $relationModel of O2System\Reactor\Models\...\Inverse::__construct(). ( Ignorable by Annotation )

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

44
            new Relations\Maps\Inverse(/** @scrutinizer ignore-type */ $this, $referenceModel, $foreignKey, $primaryKey)
Loading history...
45
        ))->getResult();
46
    }
47
48
    // ------------------------------------------------------------------------
49
50
    /**
51
     * Belongs To Many
52
     *
53
     * Belongs To is the inverse of one to many relationship.
54
     *
55
     * @param string|Model $relationModel String of table name or AbstractModel
56
     * @param string|null  $foreignKey
57
     * @param string|null  $primaryKey
58
     *
59
     * @return Row|bool
60
     */
61
    public function belongsToMany($relationModel, $pivotTable = null, $foreignKey = null, $primaryKey = null)
62
    {
63
        return (new Relations\BelongsToMany(
0 ignored issues
show
Bug Best Practice introduced by
The expression return new O2System\Reac...imaryKey))->getResult() also could return the type O2System\Reactor\Models\Sql\DataObjects\Result which is incompatible with the documented return type O2System\Reactor\Models\...ects\Result\Row|boolean.
Loading history...
64
            new Relations\Maps\Intermediary($this, $relationModel, $pivotTable, $foreignKey, $primaryKey)
0 ignored issues
show
Bug introduced by
$this of type O2System\Reactor\Models\Sql\Traits\RelationTrait is incompatible with the type O2System\Reactor\Models\Sql\Model expected by parameter $relationModel of O2System\Reactor\Models\...rmediary::__construct(). ( Ignorable by Annotation )

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

64
            new Relations\Maps\Intermediary(/** @scrutinizer ignore-type */ $this, $relationModel, $pivotTable, $foreignKey, $primaryKey)
Loading history...
65
        ))->getResult();
66
    }
67
68
    // ------------------------------------------------------------------------
69
70
    /**
71
     * Has One
72
     *
73
     * Has one is a one to one relationship. The reference model might be associated
74
     * with one relation model / table.
75
     *
76
     * @param string|Model $relationModel String of table name or AbstractModel
77
     * @param string|null  $foreignKey
78
     * @param string|null  $primaryKey
79
     *
80
     * @return Row|bool
81
     */
82
    public function hasOne($relationModel, $foreignKey = null, $primaryKey = null)
83
    {
84
        return (new Relations\HasOne(
0 ignored issues
show
Bug introduced by
Are you sure the usage of new O2System\Reactor\Mod...imaryKey))->getResult() targeting O2System\Reactor\Models\...ons\HasOne::getResult() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
85
            new Relations\Maps\Reference($this, $relationModel, $foreignKey, $primaryKey)
0 ignored issues
show
Bug introduced by
$this of type O2System\Reactor\Models\Sql\Traits\RelationTrait is incompatible with the type O2System\Reactor\Models\Sql\Model expected by parameter $referenceModel of O2System\Reactor\Models\...eference::__construct(). ( Ignorable by Annotation )

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

85
            new Relations\Maps\Reference(/** @scrutinizer ignore-type */ $this, $relationModel, $foreignKey, $primaryKey)
Loading history...
86
        ))->getResult();
87
    }
88
89
    // ------------------------------------------------------------------------
90
91
    /**
92
     * Has Many
93
     *
94
     * Has Many is a one to many relationship, is used to define relationships where a single
95
     * reference model owns any amount of others relation model.
96
     *
97
     * @param string|Model $relationModel String of table name or AbstractModel
98
     * @param string|null  $foreignKey
99
     * @param string|null  $primaryKey
100
     *
101
     * @return Result|bool
102
     */
103
    public function hasMany($relationModel, $foreignKey = null, $primaryKey = null)
104
    {
105
        return (new Relations\HasMany(
106
            new Relations\Maps\Reference($this, $relationModel, $foreignKey, $primaryKey)
0 ignored issues
show
Bug introduced by
$this of type O2System\Reactor\Models\Sql\Traits\RelationTrait is incompatible with the type O2System\Reactor\Models\Sql\Model expected by parameter $referenceModel of O2System\Reactor\Models\...eference::__construct(). ( Ignorable by Annotation )

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

106
            new Relations\Maps\Reference(/** @scrutinizer ignore-type */ $this, $relationModel, $foreignKey, $primaryKey)
Loading history...
107
        ))->getResult();
108
    }
109
110
    // ------------------------------------------------------------------------
111
112
    /**
113
     * Has Many Through
114
     *
115
     * Has Many Through provides a convenient short-cut for accessing distant relations via
116
     * an intermediate relation model.
117
     *
118
     * @param string|Model $relationModel
119
     * @param string|Model $pivotTable
120
     * @param string|null  $foreignKey
121
     * @param string|null  $primaryKey
122
     *
123
     * @return Result|bool
124
     */
125
    public function hasManyThrough($relationModel, $referenceModel, $pivotForeignKey = null, $relationForeignKey = null)
126
    {
127
        return (new Relations\HasManyThrough(
128
            new Relations\Maps\Through($this, $pivotForeignKey, $relationModel, $relationForeignKey, $referenceModel)
0 ignored issues
show
Bug introduced by
$this of type O2System\Reactor\Models\Sql\Traits\RelationTrait is incompatible with the type O2System\Reactor\Models\Sql\Model expected by parameter $pivotModel of O2System\Reactor\Models\...\Through::__construct(). ( Ignorable by Annotation )

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

128
            new Relations\Maps\Through(/** @scrutinizer ignore-type */ $this, $pivotForeignKey, $relationModel, $relationForeignKey, $referenceModel)
Loading history...
129
        ))->getResult();
130
    }
131
}