Issues (9)

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/Builder.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of Swap.
7
 *
8
 * (c) Florian Voutzinos <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Swap;
15
16
use Exchanger\Exchanger;
17
use Exchanger\Service\Chain;
18
use Http\Client\HttpClient;
19
use Http\Message\RequestFactory;
20
use Psr\SimpleCache\CacheInterface;
21
use Swap\Service\Factory;
22
use Psr\Http\Client\ClientInterface;
23
use Psr\Http\Message\RequestFactoryInterface;
24
25
/**
26
 * Helps building Swap.
27
 *
28
 * @author Florian Voutzinos <[email protected]>
29
 */
30
final class Builder
31
{
32
    /**
33
     * The services.
34
     *
35
     * @var array
36
     */
37
    private $services = [];
38
39
    /**
40
     * The options.
41
     *
42
     * @var array
43
     */
44
    private $options = [];
45
46
    /**
47
     * The http client.
48
     *
49
     * @var HttpClient
50
     */
51
    private $httpClient;
52
53
    /**
54
     * The request factory.
55
     *
56
     * @var RequestFactory
57
     */
58
    private $requestFactory;
59
60
    /**
61
     * The cache.
62
     *
63
     * @var CacheInterface
64
     */
65
    private $cache;
66
67
    /**
68
     * Constructor.
69
     *
70
     * @param array $options
71
     */
72
    public function __construct(array $options = [])
73
    {
74
        $this->options = $options;
75
    }
76
77
    /**
78
     * Adds a service.
79
     *
80
     * @param string $serviceName
81
     * @param array  $options
82
     *
83
     * @return Builder
84
     */
85
    public function add(string $serviceName, array $options = []): self
86
    {
87
        $this->services[$serviceName] = $options;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Uses the given http client.
94
     *
95
     * @param HttpClient|ClientInterface $httpClient
96
     *
97
     * @return Builder
98
     */
99 View Code Duplication
    public function useHttpClient($httpClient): self
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...
100
    {
101
        if (!$httpClient instanceof ClientInterface && !$httpClient instanceof HttpClient) {
102
            throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface');
103
        }
104
105
        $this->httpClient = $httpClient;
0 ignored issues
show
Documentation Bug introduced by florianv
$httpClient is of type object<Psr\Http\Client\ClientInterface>, but the property $httpClient was declared to be of type object<Http\Client\HttpClient>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
106
107
        return $this;
108
    }
109
110
    /**
111
     * Uses the given request factory.
112
     *
113
     * @param RequestFactoryInterface $requestFactory
114
     *
115
     * @return Builder
116
     */
117
    public function useRequestFactory(RequestFactoryInterface $requestFactory): self
118
    {
119
        $this->requestFactory = $requestFactory;
120
121
        return $this;
122
    }
123
124
    /**
125
     * Uses the given simple cache.
126
     *
127
     * @param CacheInterface $cache
128
     *
129
     * @return Builder
130
     */
131
    public function useSimpleCache(CacheInterface $cache): self
132
    {
133
        $this->cache = $cache;
134
135
        return $this;
136
    }
137
138
    /**
139
     * Builds Swap.
140
     *
141
     * @return Swap
142
     */
143
    public function build(): Swap
144
    {
145
        $serviceFactory = new Factory($this->httpClient, $this->requestFactory);
0 ignored issues
show
$this->requestFactory is of type object<Http\Message\RequestFactory>, but the function expects a null|object<Psr\Http\Mes...equestFactoryInterface>.

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...
146
        $services = [];
147
148
        foreach ($this->services as $name => $options) {
149
            $services[] = $serviceFactory->create($name, $options);
150
        }
151
152
        $service = new Chain($services);
153
        $exchanger = new Exchanger($service, $this->cache, $this->options);
154
155
        return new Swap($exchanger);
156
    }
157
}
158