Completed
Push — master ( 9cfcfd...a0da2a )
by Mr
01:55
created

Products   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 135
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 24
loc 135
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 1
A create() 0 8 1
A update() 0 8 1
A delete() 0 8 1
A search() 0 8 1
A searchMarketplace() 0 8 1
A getPickups() 0 8 1
A createImage() 0 8 1
A getImage() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Rezdy\Endpoints;
4
5
use Rezdy\Client;
6
use Rezdy\Interfaces\ProductInterface;
7
use Rezdy\Interfaces\ProductsInterface;
8
use Rezdy\Interfaces\QueryInterface;
9
10
class Products extends Client implements ProductInterface, ProductsInterface
11
{
12
    /**
13
     * Get product
14
     *
15
     * @param int $productCode
16
     *
17
     * @return QueryInterface
18
     */
19
    public function __invoke(string $productCode): ProductInterface
20
    {
21
        $this->productCode = $productCode;
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
22
23
        // Set HTTP params
24
        $this->type     = 'get';
25
        $this->endpoint = '/products/' . $productCode;
26
27
        return $this;
28
    }
29
30
    /**
31
     * Create product
32
     *
33
     * @return \Rezdy\Interfaces\QueryInterface
34
     */
35
    public function create(): QueryInterface
36
    {
37
        // Set HTTP params
38
        $this->type     = 'post';
39
        $this->endpoint = '/products';
40
41
        return $this;
42
    }
43
44
    /**
45
     * Update product
46
     *
47
     * @return \Rezdy\Interfaces\QueryInterface
48
     */
49
    public function update(): QueryInterface
50
    {
51
        // Set HTTP params
52
        $this->type     = 'put';
53
        $this->endpoint = '/products/' . $this->productCode;
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
54
55
        return $this;
56
    }
57
58
    /**
59
     * Delete product
60
     *
61
     * @return \Rezdy\Interfaces\QueryInterface
62
     */
63
    public function delete(): QueryInterface
64
    {
65
        // Set HTTP params
66
        $this->type     = 'delete';
67
        $this->endpoint = '/products/' . $this->productCode;
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
69
        return $this;
70
    }
71
72
    /**
73
     * Search products
74
     *
75
     * @return \Rezdy\Interfaces\QueryInterface
76
     */
77
    public function search(): QueryInterface
78
    {
79
        // Set HTTP params
80
        $this->type     = 'get';
81
        $this->endpoint = '/products';
82
83
        return $this;
84
    }
85
86
    /**
87
     * Search marketplace products
88
     *
89
     * @return \Rezdy\Interfaces\QueryInterface
90
     */
91
    public function searchMarketplace(): QueryInterface
92
    {
93
        // Set HTTP params
94
        $this->type     = 'get';
95
        $this->endpoint = '/products/marketplace';
96
97
        return $this;
98
    }
99
100
    /**
101
     * Get product pickups
102
     *
103
     * @return \Rezdy\Interfaces\QueryInterface
104
     */
105
    public function getPickups(): QueryInterface
106
    {
107
        // Set HTTP params
108
        $this->type     = 'get';
109
        $this->endpoint = '/products/' . $this->productCode . '/pickups';
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
110
111
        return $this;
112
    }
113
114
    /**
115
     * Add product image
116
     *
117
     * @return \Rezdy\Interfaces\QueryInterface
118
     */
119
    public function createImage(): QueryInterface
120
    {
121
        // Set HTTP params
122
        $this->type     = 'post';
123
        $this->endpoint = '/products/' . $this->productCode . '/images';
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
124
125
        return $this;
126
    }
127
128
    /**
129
     * Remove product Image
130
     *
131
     * @param string $mediaId
132
     *
133
     * @return \Rezdy\Interfaces\QueryInterface
134
     */
135
    public function getImage(string $mediaId): QueryInterface
136
    {
137
        // Set HTTP params
138
        $this->type     = 'delete';
139
        $this->endpoint = '/products/' . $this->productCode . '/images/' . $mediaId;
0 ignored issues
show
Documentation introduced by
The property productCode does not exist on object<Rezdy\Endpoints\Products>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
140
141
        return $this;
142
    }
143
144
}
145