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 |
||
22 | final class ProductClient |
||
23 | { |
||
24 | const BASE_URL = 'https://products.izettle.com/organizations/%s'; |
||
25 | |||
26 | const POST_CATEGORY = self::BASE_URL . '/categories'; |
||
27 | const GET_CATEGORY = self::BASE_URL . '/categories/%s'; |
||
28 | const GET_CATEGORIES = self::BASE_URL . '/categories'; |
||
29 | |||
30 | const POST_DISCOUNT = self::BASE_URL . '/discounts'; |
||
31 | const GET_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
32 | const PUT_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
33 | const DELETE_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
34 | const GET_DISCOUNTS = self::BASE_URL . '/discounts'; |
||
35 | |||
36 | const GET_EXPORT = self::BASE_URL . '/products/%s'; |
||
37 | const GET_EXPORT_TEMPLATE = self::BASE_URL . '/products/%s/template'; |
||
38 | |||
39 | const GET_LIBRARY = self::BASE_URL . '/library'; |
||
40 | |||
41 | const POST_PRODUCT = self::BASE_URL . '/products'; |
||
42 | const GET_PRODUCT = self::BASE_URL . '/products/%s'; |
||
43 | const PUT_PRODUCT = self::BASE_URL . '/products/v2/%s'; |
||
44 | const DELETE_PRODUCT = self::BASE_URL . '/products/%s'; |
||
45 | const POST_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants'; |
||
46 | const PUT_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants/%s'; |
||
47 | const DELETE_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants/%s'; |
||
48 | const GET_PRODUCTS = self::BASE_URL . '/products'; |
||
49 | const DELETE_PRODUCTS = self::BASE_URL . '/products'; |
||
50 | |||
51 | private $client; |
||
52 | private $organizationUuid = 'self'; |
||
53 | private $categoryBuilder; |
||
54 | private $discountBuilder; |
||
55 | private $libraryBuilder; |
||
56 | private $productBuilder; |
||
57 | |||
58 | 9 | public function __construct( |
|
73 | |||
74 | 1 | View Code Duplication | public function getCategories(): array |
81 | |||
82 | 1 | public function createCategory(Category $category): void |
|
87 | |||
88 | 1 | View Code Duplication | public function getDiscounts(): array |
95 | |||
96 | 1 | public function createDiscount(Discount $discount): void |
|
102 | |||
103 | 1 | public function deleteDiscount(Discount $discount): void |
|
109 | |||
110 | 1 | View Code Duplication | public function getLibrary(): Library |
117 | |||
118 | 1 | View Code Duplication | public function getProducts(): array |
125 | |||
126 | 1 | public function createProduct(Product $product): void |
|
132 | |||
133 | 1 | public function deleteProduct(Product $product): void |
|
139 | } |
||
140 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..