Passed
Push — master ( a4b6fc...ae32ac )
by Laurens
02:56
created

ApiScope::getUrlParameters()   C

Complexity

Conditions 11
Paths 243

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 23
cts 23
cp 1
rs 5.9458
c 0
b 0
f 0
cc 11
nc 243
nop 0
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client;
6
7
use LauLamanApps\IzettleApi\Client\ApiScope\Rights;
8
9
final class ApiScope
10
{
11
    private const FINANCE = 'FINANCE';
12
    private const PURCHASE = 'PURCHASE';
13
    private const PRODUCT = 'PRODUCT';
14
    private const INVENTORY = 'INVENTORY';
15
    private const IMAGE = 'IMAGE';
16
17
    /**
18
     * @var Rights
19
     */
20
    private $finance;
21
22
    /**
23
     * @var Rights
24
     */
25
    private $purchase;
26
27
    /**
28
     * @var Rights
29
     */
30
    private $product;
31
32
    /**
33
     * @var Rights
34
     */
35
    private $inventory;
36
37
    /**
38
     * @var Rights
39
     */
40
    private $image;
41
42 2
    public function setFinancesScope(Rights $rights): void
43
    {
44 2
        $this->finance = $rights;
45 2
    }
46
47 2
    public function setPurchaseScope(Rights $rights): void
48
    {
49 2
        $this->purchase = $rights;
50 2
    }
51
52 2
    public function setProductScope(Rights $rights): void
53
    {
54 2
        $this->product = $rights;
55 2
    }
56
57 2
    public function setInventoryScope(Rights $rights): void
58
    {
59 2
        $this->inventory = $rights;
60 2
    }
61
62 2
    public function setImageScope(Rights $rights): void
63
    {
64 2
        $this->image = $rights;
65 2
    }
66
67 11
    public function getUrlParameters(): string
68
    {
69 11
        $scope = [];
70 11
        if ($this->finance !== null) {
71 2
		$scope[] = $this->finance->getValue().':'.self::FINANCE;
72 2
		if($this->finance->getValue() == Rights::WRITE)
73 1
			$scope[] = Rights::READ.':'.self::FINANCE;
74
        }
75 11
        if ($this->purchase !== null) {
76 2
		$scope[] = $this->purchase->getValue().':'.self::PURCHASE;
77 2
		if($this->purchase->getValue() == Rights::WRITE)
78 1
			$scope[] = Rights::READ.':'.self::PURCHASE;
79
        }
80 11
        if ($this->product !== null) {
81 2
        	$scope[] = $this->product->getValue().':'.self::PRODUCT;
82 2
		if($this->product->getValue() == Rights::WRITE)
83 1
			$scope[] = Rights::READ.':'.self::PRODUCT;
84
        }
85 11
        if ($this->inventory !== null) {
86 2
		$scope[] = $this->inventory->getValue().':'.self::INVENTORY;
87 2
		if($this->inventory->getValue() == Rights::WRITE)
88 1
			$scope[] = Rights::READ.':'.self::INVENTORY;
89
        }
90 11
        if ($this->image !== null) {
91 2
		$scope[] = $this->image->getValue().':'.self::IMAGE;
92 2
		if($this->image->getValue() == Rights::WRITE)
93 1
			$scope[] = Rights::READ.':'.self::IMAGE;
94
        }
95 11
        return implode(' ', $scope);
96
    }
97
}
98