Product   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A category() 0 4 1
A __construct() 0 5 1
A restaurant() 0 4 1
1
<?php
2
3
namespace WagnerMontanini\GoomerApi\Models;
4
5
use CoffeeCode\DataLayer\DataLayer;
6
use WagnerMontanini\GoomerApi\Models\Restaurant;
7
use WagnerMontanini\GoomerApi\Models\ProductCategory;
8
9
/**
10
 * Class Product
11
 * @package WagnerMontanini\GoomerApi\Models
12
 */
13
class Product extends DataLayer
14
{
15
    
16
    /**
17
     * Product constructor.
18
     */
19
    public function __construct()
20
    {
21
        parent::__construct(
22
            "products",
23
            ["restaurant_id", "category_id", "name", "price"]
24
        );
25
    }
26
27
    public function restaurant(): Product
28
    {
29
        $this->restaurant = (new Restaurant())->findById($this->restaurant_id)->data();
0 ignored issues
show
Bug Best Practice introduced by
The property restaurant does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug Best Practice introduced by
The property restaurant_id does not exist on WagnerMontanini\GoomerApi\Models\Product. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
$this->restaurant_id of type null|string is incompatible with the type integer expected by parameter $id of CoffeeCode\DataLayer\DataLayer::findById(). ( Ignorable by Annotation )

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

29
        $this->restaurant = (new Restaurant())->findById(/** @scrutinizer ignore-type */ $this->restaurant_id)->data();
Loading history...
30
        return $this;
31
    }
32
33
    public function category(): Product
34
    {
35
        $this->category = (new ProductCategory())->findById($this->category_id)->data();
0 ignored issues
show
Bug Best Practice introduced by
The property category does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
$this->category_id of type null|string is incompatible with the type integer expected by parameter $id of CoffeeCode\DataLayer\DataLayer::findById(). ( Ignorable by Annotation )

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

35
        $this->category = (new ProductCategory())->findById(/** @scrutinizer ignore-type */ $this->category_id)->data();
Loading history...
Bug Best Practice introduced by
The property category_id does not exist on WagnerMontanini\GoomerApi\Models\Product. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
        return $this;
37
    }
38
39
}