Passed
Branch 2.0.0 (eaa7cb)
by Chubarov
02:44
created

Read::processData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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