Issues (15)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/services/BaseService.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\EntityInterface;
6
use linkprofit\AmoCRM\RequestHandler;
7
8
/**
9
 * Class BaseService
10
 * @package linkprofit\AmoCRM\services
11
 */
12
abstract class BaseService implements ServiceInterface, ListableService
13
{
14
    /**
15
     * @var RequestHandler
16
     */
17
    protected $request;
18
19
    /**
20
     * @var array
21
     */
22
    protected $fields = [];
23
24
    /**
25
     * @var mixed
26
     */
27
    protected $response;
28
29
    /**
30
     * @var array EntityInterface
31
     */
32
    protected $entities = [];
33
34
    /**
35
     * LeadService constructor.
36
     * @param RequestHandler $requestHandler
37
     */
38 59
    public function __construct(RequestHandler $requestHandler)
39
    {
40 59
        $this->request = $requestHandler;
41 59
    }
42
43
    /**
44
     * @return bool|mixed
45
     */
46 36 View Code Duplication
    public function save()
0 ignored issues
show
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...
47
    {
48 36
        $this->composeFields();
49 36
        $this->request->performRequest($this->getLink(), $this->fields);
50 36
        $this->response = $this->request->getResponse();
51
52 36
        if ($this->checkResponse()) {
53 26
            return $this->getResponse();
54
        }
55
56 10
        return false;
57
    }
58
59
    /**
60
     * @return array|bool
61
     */
62 9
    public function getList()
63
    {
64 9
        $link = $this->composeListLink($this->getLink());
65
66 9
        $this->request->performRequest($link, [], 'application/json', 'GET');
67 9
        $this->response = $this->request->getResponse();
68
69 9
        return $this->parseResponseToEntities();
70
    }
71
72
    /**
73
     * @param $link
74
     *
75
     * @return mixed
76
     */
77
    protected function composeListLink($link)
78
    {
79
        return $link;
80
    }
81
82
    /**
83
     * @return mixed
84
     */
85 28
    public function getResponse()
86
    {
87 28
        return $this->response;
88
    }
89
90
    /**
91
     * @return array
92
     */
93 22
    public function getEntities()
94
    {
95 22
        return $this->entities;
96
    }
97
98
    /**
99
     * @return array|bool
100
     */
101 45 View Code Duplication
    public function parseResponseToEntities()
0 ignored issues
show
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...
102
    {
103 45
        if (!$this->checkResponse()) {
104 10
            return false;
105
        }
106 35
        $this->entities = [];
107
108 35
        foreach ($this->response['_embedded']['items'] as $item) {
109 35
            $this->entities[] = $this->parseArrayToEntity($item);
110 35
        }
111
112 35
        return $this->entities;
113
    }
114
115
    /**
116
     * @param $array
117
     * @return EntityInterface
118
     */
119
    abstract public function parseArrayToEntity($array);
120
121
    /**
122
     * @return bool
123
     */
124 45
    protected function checkResponse()
125
    {
126 45
        if (isset($this->response['_embedded']['items']) && count($this->response['_embedded']['items'])) {
127 35
            return true;
128
        }
129
130 10
        return false;
131
    }
132
133
    /**
134
     * Fill fields for save request
135
     */
136 36 View Code Duplication
    protected function composeFields()
0 ignored issues
show
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...
137
    {
138 36
        $addFields = [];
139 36
        $updateFields = [];
140
141 36
        foreach ($this->entities as $entity) {
142 36
            if ($entity->id) {
143 10
                $updateFields[] = $entity->get();
144 10
            } else {
145 26
                $addFields[] = $entity->get();
146
            }
147 36
        }
148
149 36
        if (count($addFields)) {
150 26
            $this->fields['add'] = $addFields;
151 26
        }
152
153 36
        if (count($updateFields)) {
154 10
            $this->fields['update'] = $updateFields;
155 10
        }
156 36
    }
157
158
    /**
159
     * @return string
160
     */
161
    abstract protected function getLink();
162
}