Report::status()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace FLAIRUK\GoodTillSystem\Models;
4
5
use FLAIRUK\GoodTillSystem\API;
6
use Illuminate\Support\Facades\Config;
7
use FLAIRUK\GoodTillSystem\Models\Sale;
8
use FLAIRUK\GoodTillSystem\Models\Product;
9
10 View Code Duplication
class Report extends API {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
12
13
    protected $url;
14
15
    const SALE = 'sale';
16
    const PRODUCTS = 'products';
17
    const REPORT = 'report';
18
19
    /**
20
     * Create a new GoodTill instance.
21
     *
22
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
23
     */
24
    public function __construct($user)
25
    {
26
        $this->user = $user;
0 ignored issues
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
28
        parent::__construct($user, $this->url);
29
    }
30
31
    public function setURL(): void {
32
        $this->url = Config::get('goodtill.routes.api') . self::REPORT . '/';
33
    }
34
35
    /**
36
     * External Products
37
     * 
38
     * @return Product
39
     */
40
    public function products(): Product {
41
        $sale = new Product($this->user);
42
        $sale->setURL($this->url . self::PRODUCTS . '/');
43
        return $sale;
44
    }
45
46
    public function sale($id = null): Sale {
47
        $sale = new Sale($this->user);
48
        $sale->setURL($this->url . self::SALE . '/' . $id ?? $id);
49
        return $sale;
50
51
    }
52
53
    public function status() {
54
        $this->url = $this->url . self::SALE . '/';
55
        return $this;
56
    }  
57
}
58