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.

RestfulTrait   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 64
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 13 4
A find() 0 8 3
A create() 0 4 1
A update() 0 8 3
A delete() 0 8 3
1
<?php
2
3
namespace Ciromattia\Teamwork\Traits;
4
5
trait RestfulTrait
6
{
7
    /**
8
     * @param string|array $query The query parameters (optional).
9
     * @return mixed
10
     */
11
    public function all($query = '')
12
    {
13
        if (!empty($query)) {
14
            if (is_array($query)) {
15
                $query = http_build_query($query);
16
            } else if (is_string($query)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
17
18
            } else {
19
                $query = '';
20
            }
21
        }
22
        return $this->client->get($this->endpoint, $query)->response();
0 ignored issues
show
Bug introduced by
The property client 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...
Bug introduced by
The property endpoint 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...
23
    }
24
25
    /**
26
     * @return mixed
27
     */
28
    public function find($id = null)
29
    {
30
        if (!empty($id))
31
            $this->id = $id;
0 ignored issues
show
Bug introduced by
The property id 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...
32
        if (!$this->id)
33
            throw new \InvalidArgumentException('No valid ID provided');
34
        return $this->client->get("$this->endpoint/{$this->id}")->response();
35
    }
36
37
    /**
38
     * @return array | companyID
39
     */
40
    public function create($data)
41
    {
42
        return $this->client->post("$this->endpoint", [$this->wrapper => $data])->response();
0 ignored issues
show
Bug introduced by
The property wrapper 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...
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function update($data, $id = null)
49
    {
50
        if (!empty($id))
51
            $this->id = $id;
52
        if (!$this->id)
53
            throw new \InvalidArgumentException('No valid ID provided');
54
        return $this->client->put("$this->endpoint/$this->id", [$this->wrapper => $data])->response();
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function delete($id = null)
61
    {
62
        if (!empty($id))
63
            $this->id = $id;
64
        if (!$this->id)
65
            throw new \InvalidArgumentException('No valid ID provided');
66
        return $this->client->delete("$this->endpoint/$this->id")->response();
67
    }
68
}