1
|
|
|
<?php |
2
|
|
|
namespace agoalofalife\bpm\Actions; |
3
|
|
|
|
4
|
|
|
use agoalofalife\bpm\Assistants\AuthenticationHelper; |
5
|
|
|
use agoalofalife\bpm\Assistants\QueryBuilder; |
6
|
|
|
use agoalofalife\bpm\Contracts\Action; |
7
|
|
|
use agoalofalife\bpm\Contracts\ActionSet; |
8
|
|
|
use agoalofalife\bpm\KernelBpm; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Create |
13
|
|
|
* Class to create a new object in the BPM |
14
|
|
|
* |
15
|
|
|
* @property KernelBpm kernel |
16
|
|
|
* @property string HTTP_TYPE |
17
|
|
|
* @property array data |
18
|
|
|
* @package agoalofalife\bpm\Actions |
19
|
|
|
*/ |
20
|
|
|
class Create implements Action, ActionSet |
21
|
|
|
{ |
22
|
|
|
use QueryBuilder, AuthenticationHelper; |
23
|
|
|
|
24
|
|
|
protected $kernel; |
25
|
|
|
protected $url = '/'; |
26
|
|
|
/** |
27
|
|
|
* Request type to created |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $HTTP_TYPE = 'POST'; |
31
|
|
|
protected $data = []; |
32
|
|
|
|
33
|
3 |
|
public function injectionKernel(KernelBpm $bpm) |
34
|
|
|
{ |
35
|
3 |
|
$this->kernel = $bpm; |
36
|
3 |
|
} |
37
|
|
|
|
38
|
1 |
|
public function getUrl() |
39
|
|
|
{ |
40
|
1 |
|
return $this->url; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function processData() |
44
|
|
|
{ |
45
|
1 |
|
$this->query(); |
46
|
1 |
|
return $this->kernel->getHandler(); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function setData(array $data) |
50
|
|
|
{ |
51
|
1 |
|
$this->data = $data; |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
private function query() |
55
|
|
|
{ |
56
|
1 |
|
$parameters = str_replace(' ', '%20', $this->url); |
57
|
|
|
|
58
|
1 |
|
$url = $this->kernel->getCollection() . $parameters; |
59
|
1 |
|
$urlHome = config($this->kernel->getPrefixConfig() . '.UrlHome'); |
60
|
|
|
|
61
|
1 |
|
$this->headers()->getCookie()->body()->httpErrorsFalse()->get(); |
|
|
|
|
62
|
1 |
|
$response = $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url, |
63
|
1 |
|
$this->headers()->getCookie()->body()->httpErrorsFalse()->get() |
64
|
1 |
|
); |
65
|
1 |
|
$body = $response->getBody(); |
66
|
1 |
|
$this->kernel->getHandler()->parse($body->getContents()); |
|
|
|
|
67
|
1 |
|
$this->checkResponseUnauthorized($response); |
68
|
|
|
} |
69
|
|
|
} |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: