Read   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 152
Duplicated Lines 9.87 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 15
loc 152
ccs 52
cts 52
cp 1
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 8

10 Methods

Rating   Name   Duplication   Size   Complexity  
A injectionKernel() 0 4 1
A getUrl() 0 4 1
A processData() 0 5 1
A getData() 0 4 1
A filterConstructor() 0 7 1
A orderBy() 0 15 4
A skip() 0 8 1
A amount() 0 7 1
A count() 0 7 1
A query() 15 15 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
namespace agoalofalife\bpm\Actions;
3
4
use agoalofalife\bpm\Assistants\AuthenticationHelper;
5
use agoalofalife\bpm\Assistants\ConstructorUrl;
6
use agoalofalife\bpm\Assistants\QueryBuilder;
7
use agoalofalife\bpm\Contracts\Action;
8
use agoalofalife\bpm\Contracts\ActionGet;
9
use agoalofalife\bpm\Contracts\Handler;
10
use agoalofalife\bpm\KernelBpm;
11
use Assert\Assert;
12
13
14
/**
15
 * Class Read
16
 * @property KernelBpm $kernel
17
 * @property string $HTTP_TYPE GET | POST | PUT | DELETE
18
 * @property string $url
19
 * @uses     ConstructorUrl trait
20
 * @package agoalofalife\bpm\Actions
21
 */
22
class Read implements Action, ActionGet
23
{
24
    use ConstructorUrl, QueryBuilder, AuthenticationHelper;
25
26
    protected $kernel;
27
28
    /**
29
     * Type HTTP_TYPE select
30
     * @var string
31
     */
32
    protected $HTTP_TYPE = 'GET';
33
34
    protected $url = '?';
35
36
    /**
37
     * @param KernelBpm $bpm
38
     * @return  void
39
     */
40 1
    public function injectionKernel(KernelBpm $bpm)
41
    {
42 1
        $this->kernel = $bpm;
43 1
    }
44
45
    /**
46
     * @return string url
47
     */
48 8
    public function getUrl()
49
    {
50 8
        return $this->url;
51
    }
52
53
    /**
54
     * @return Handler
55
     */
56 1
    public function processData()
57
    {
58 1
        $this->getData();
59 1
        return $this->kernel->getHandler();
60
    }
61
62 1
    public function getData()
63
    {
64 1
        $this->query();
65 1
    }
66
67
    /**
68
     * Request the type of filter
69
     * Design   filterConstructor allows you to build logical expressions the conditions selecting the desired object .
70
     * Expressions filterConstructor can be used to reference the properties and literals ,
71
     * as well as strings, numbers and Boolean expressions (true, false).
72
     * Expressions $ filter supports arithmetic , logical operations , and operations groups ,
73
     * strings , date and time of the operation.
74
     * @documentation
75
     * @param $strRequest
76
     * @return $this
77
     */
78 2
    public function filterConstructor($strRequest)
79
    {
80 2
        $ParameterQuery =  '$filter=';
81 2
        $ParameterQuery.=  $strRequest;
82 2
        $this->concatenationUrlCurl($ParameterQuery);
83 2
        return $this;
84
    }
85
86
    /**
87
     * Service resources can be obtained in the form of sort .
88
     * asc  ascending
89
     * desc descending
90
     * @param string $whatSort
91
     * @param string $param  asc | desc
92
     * @return $this
93
     * @throws \Exception
94
     */
95 2
    public function orderBy($whatSort, $param = 'asc')
96
    {
97 2
        $ParameterQuery = '$orderby=';
98 2
        $ParameterQuery.=  ucfirst($whatSort);
99
100 2
        if ( empty($param) === false ) {
101 2
            if ($param != 'desc' && $param != 'asc') {
102 1
                throw new \Exception('no valid orderby parameters');
103
            }
104 1
            $ParameterQuery.=  " ".$param;
105 1
        }
106 1
         $this->concatenationUrlCurl($ParameterQuery);
107
108 1
        return $this;
109
    }
110
111
    /**
112
     * In bpm'online support the use of parameter $ the skip ,
113
     * which allows you to query the service resources ,
114
     * skipping the specified number of entries.
115
     * @param $skip
116
     * @return $this
117
     */
118 2
    public function skip($skip)
119
    {
120 2
        Assert::that($skip, 'You must specify a numeric parameter for the amount of the method')->integer();
121 1
        $ParameterQuery = '$skip='.$skip;
122 1
        $this->concatenationUrlCurl($ParameterQuery);
123
124 1
        return $this;
125
    }
126
127
    /**
128
     * Restrictions in the sample query
129
     * If you want the request to return more than 40 records at a time, it can be implemented using the parameter $ top
130
     * @param $amountMax
131
     * @return $this
132
     */
133 2
    public function amount($amountMax = null)
134
    {
135 2
        Assert::that($amountMax,'You must specify a numeric parameter for the amount of the method')->integer();
136 1
        $ParameterQuery = '$top='.$amountMax;
137 1
        $this->concatenationUrlCurl($ParameterQuery);
138 1
        return $this;
139
    }
140
141
    /**
142
     * The number of records
143
     * example SomeCollection/$count or SomeCollection/$count?$filter=...
144
     * @return $this
145
     */
146 1
    public function count()
147
    {
148 1
        $this->url = '/';
149 1
        $ParameterQuery = '$count';
150 1
        $this->concatenationUrlCurl($ParameterQuery);
151 1
        return $this;
152
    }
153
154
    /**
155
     * TODO Requires refactoring of this method
156
     * @return void
157
     */
158 1 View Code Duplication
    private function query()
0 ignored issues
show
Duplication introduced by
This method 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...
159
    {
160 1
        $parameters   = str_replace(' ', '%20', $this->url);
161 1
        $url          = $this->kernel->getCollection() . $parameters;
162 1
        $urlHome      = config($this->kernel->getPrefixConfig() . '.UrlHome');
163
164 1
        $response     =  $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url,
165 1
                         $this->debug()->headers()->getCookie()->httpErrorsFalse()->get()
166 1
        );
167 1
        $body         = $response->getBody();
168
169 1
        $this->kernel->getHandler()->parse($body->getContents());
0 ignored issues
show
Bug introduced by
The method parse() does not seem to exist on object<Illuminate\Container\Container>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
170
171 1
        $this->checkResponseUnauthorized($response);
172
    }
173
}