Passed
Pull Request — master (#83)
by Wilmer
24:07 queued 09:08
created

OrderItemWithConstructor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 28
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A instantiate() 0 3 1
A getOrder() 0 3 1
A tableName() 0 3 1
A instance() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\ActiveRecord;
9
10
/**
11
 * OrderItemWithConstructor.
12
 *
13
 * @property int $order_id
14
 * @property int $item_id
15
 * @property int $quantity
16
 * @property string $subtotal
17
 */
18
class OrderItemWithConstructor extends ActiveRecord
19
{
20
    public static function tableName(): string
21
    {
22
        return 'order_item';
23
    }
24
25
    public function __construct($item_id, $quantity)
26
    {
27
        $this->item_id = $item_id;
28
        $this->quantity = $quantity;
29
30
        parent::__construct();
0 ignored issues
show
Bug introduced by
The method __construct() does not exist on Yiisoft\ActiveRecord\ActiveRecord. It seems like you code against a sub-type of Yiisoft\ActiveRecord\ActiveRecord such as Yiisoft\ActiveRecord\Tes...rd\OrderWithConstructor or Yiisoft\ActiveRecord\Tes...ubs\ActiveRecord\Animal or Yiisoft\ActiveRecord\Tes...CustomerWithConstructor or Yiisoft\ActiveRecord\Tes...\ProfileWithConstructor or Yiisoft\ActiveRecord\Tes...rderItemWithConstructor. ( Ignorable by Annotation )

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

30
        parent::/** @scrutinizer ignore-call */ 
31
                __construct();
Loading history...
31
    }
32
33
    public static function instance($refresh = false): self
0 ignored issues
show
Unused Code introduced by
The parameter $refresh is not used and could be removed. ( Ignorable by Annotation )

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

33
    public static function instance(/** @scrutinizer ignore-unused */ $refresh = false): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        return self::instantiate([]);
36
    }
37
38
    public static function instantiate($row): self
39
    {
40
        return (new \ReflectionClass(static::class))->newInstanceWithoutConstructor();
41
    }
42
43
    public function getOrder(): ActiveQuery
44
    {
45
        return $this->hasOne(OrderWithConstructor::class, ['id' => 'order_id']);
46
    }
47
}
48