Issues (1)

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/ApiClientBuilder.php (1 issue)

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
/*
4
 * This file is part of the php-shop-logistics.ru-api package.
5
 *
6
 * (c) Gennady Knyazkin <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gennadyx\ShopLogisticsRu;
13
14
use Http\Client\Curl\Client;
15
use Http\Client\HttpClient;
16
use Http\Message\MessageFactory\DiactorosMessageFactory;
17
use Http\Message\RequestFactory;
18
use Http\Message\StreamFactory;
19
use Http\Message\StreamFactory\DiactorosStreamFactory;
20
use Symfony\Component\Serializer\Encoder\XmlEncoder;
21
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
22
23
/**
24
 * ApiClient builder.
25
 *
26
 * Building new instance of ApiClient with parameters:
27
 *  - requestFactory: Default is \Http\Message\MessageFactory\DiactorosMessageFactory
28
 *  - streamFactory: Default is \Http\Message\StreamFactory\DiactorosStreamFactory
29
 *  - httpClient: Defalt is \Http\Client\Curl\Client
30
 *  - encoder: Default is closure (using XmlEncoder from symfony serializer component)
31
 *  - decoder: Default is closure (using XmlEncoder from symfony serializer component)
32
 *  - key: Default is ApiClient::TEST_KEY
33
 *  - environment: Default is Environment::TEST()
34
 *
35
 * @author Gennady Knyazkin <[email protected]>
36
 */
37
class ApiClientBuilder
38
{
39
    /**
40
     * @var string|null
41
     */
42
    protected $key;
43
44
    /**
45
     * @var RequestFactory
46
     */
47
    protected $requestFactory;
48
49
    /**
50
     * @var Environment
51
     */
52
    protected $environment;
53
54
    /**
55
     * @var StreamFactory
56
     */
57
    protected $streamFactory;
58
59
    /**
60
     * @var HttpClient
61
     */
62
    protected $httpClient;
63
64
    /**
65
     * @var callable
66
     */
67
    protected $encoder;
68
69
    /**
70
     * @var callable
71
     */
72
    protected $decoder;
73
74
    /**
75
     * Create builder
76
     *
77
     * @return static
78
     */
79 16
    public static function create()
80
    {
81 16
        return new static();
82
    }
83
84
    /**
85
     * Build api client instance
86
     *
87
     * @return ApiClient
88
     * @throws \Gennadyx\ShopLogisticsRu\Exception\InvalidArgumentException
89
     */
90 16
    public function build()
91
    {
92 16
        $fields = array_keys(get_class_vars(static::class));
93
94 16
        foreach ($fields as $field) {
95 16
            if (null === $this->{$field}) {
96 16
                $this->{sprintf('default%s', ucfirst($field))}();
97
            }
98
        }
99
100 16
        $apiClient = new ApiClient(
101 16
            $this->requestFactory,
102 16
            $this->streamFactory,
103 16
            $this->httpClient,
104 16
            $this->encoder,
105 16
            $this->decoder,
106 16
            $this->key,
107 16
            $this->environment
108
        );
109
110 16
        return $apiClient;
111
    }
112
113
    /**
114
     * @param string $key
115
     *
116
     * @return $this
117
     */
118 1
    public function withKey($key)
119
    {
120 1
        $this->key = (string) $key;
121
122 1
        return $this;
123
    }
124
125
    /**
126
     * @param Environment $environment
127
     *
128
     * @return $this
129
     */
130 1
    public function withEnvironment(Environment $environment)
131
    {
132 1
        $this->environment = $environment;
133
134 1
        return $this;
135
    }
136
137
    /**
138
     * @param RequestFactory $requestFactory
139
     *
140
     * @return $this
141
     */
142 1
    public function withRequestFactory(RequestFactory $requestFactory)
143
    {
144 1
        $this->requestFactory = $requestFactory;
145
146 1
        return $this;
147
    }
148
149
    /**
150
     * @param StreamFactory $streamFactory
151
     *
152
     * @return $this
153
     */
154 1
    public function withStreamFactory(StreamFactory $streamFactory)
155
    {
156 1
        $this->streamFactory = $streamFactory;
157
158 1
        return $this;
159
    }
160
161
    /**
162
     * @param HttpClient $httpClient
163
     *
164
     * @return $this
165
     */
166 14
    public function withHttpClient(HttpClient $httpClient)
167
    {
168 14
        $this->httpClient = $httpClient;
169
170 14
        return $this;
171
    }
172
173
    /**
174
     * @param callable $encoder
175
     *
176
     * @return $this
177
     */
178 1
    public function withEncoder(callable $encoder)
179
    {
180 1
        $this->encoder = $encoder;
181
182 1
        return $this;
183
    }
184
185
    /**
186
     * @param callable $decoder
187
     *
188
     * @return $this
189
     */
190 1
    public function withDecoder(callable $decoder)
191
    {
192 1
        $this->decoder = $decoder;
193
194 1
        return $this;
195
    }
196
197 15
    protected function defaultRequestFactory()
198
    {
199 15
        $this->requestFactory = new DiactorosMessageFactory();
200 15
    }
201
202 15
    protected function defaultStreamFactory()
203
    {
204 15
        $this->streamFactory = new DiactorosStreamFactory();
205 15
    }
206
207 2
    protected function defaultHttpClient()
208
    {
209 2
        $this->httpClient = new Client($this->requestFactory, $this->streamFactory);
0 ignored issues
show
$this->requestFactory is of type object<Http\Message\RequestFactory>, but the function expects a null|object<Http\Message\MessageFactory>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
210 2
    }
211
212
    protected function defaultEncoder()
213
    {
214 7
        $this->encoder = function (array $data) {
215
            try {
216 7
                $xml = (new XmlEncoder('request'))->encode($data, 'xml');
217
            } catch (UnexpectedValueException $e) {
218
                $xml = '';
219
            }
220
221 7
            return $xml;
222
        };
223 15
    }
224
225
    protected function defaultDecoder()
226
    {
227 7
        $this->decoder = function ($data) {
228
            try {
229 7
                $data = (new XmlEncoder('request'))->decode($data, 'xml');
230 3
            } catch (UnexpectedValueException $e) {
231 3
                $data = [];
232
            }
233
234 7
            return $data;
235
        };
236 15
    }
237
238 15
    protected function defaultKey()
239
    {
240 15
        $this->key = ApiClient::TEST_KEY;
241 15
    }
242
243 15
    protected function defaultEnvironment()
244
    {
245 15
        $this->environment = Environment::TEST();
246 15
    }
247
}
248