Issues (2)

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/Query/Query.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
namespace DJStarCOM\BookingComSDK\Query;
4
5
use function count;
6
use DJStarCOM\BookingComSDK\Exceptions\BookingResponseException;
7
use DJStarCOM\BookingComSDK\Exceptions\ModelException;
8
use DJStarCOM\BookingComSDK\HttpClient\HttpClientInterface;
9
use DJStarCOM\BookingComSDK\Models\Model;
10
use DJStarCOM\BookingComSDK\Models\Result;
11
use function is_array;
12
13
/**
14
 * Class QueryAbstract
15
 * @package DJStarCOM\BookingComSDK\Query
16
 */
17
abstract class Query
18
{
19
    public const REQUEST_METHOD_POST = 'POST';
20
    public const REQUEST_METHOD_GET = 'GET';
21
22
    /**
23
     * @var string
24
     */
25
    protected static $uri;
26
27
    /**
28
     * @var string
29
     */
30
    protected $model;
31
32
    /**
33
     * @var string
34
     */
35
    protected $endpoint = 'https://{secure}distribution-xml.booking.com/2.4/json';
36
37
    /**
38
     * QueryAbstract constructor.
39
     * @throws ModelException
40
     */
41
    public function __construct()
42
    {
43
        $this->makeModel();
44
    }
45
46
    /**
47
     * @return Model
48
     * @throws ModelException
49
     */
50
    public function makeModel(): Model
51
    {
52
        $class = $this->model();
53
        $model = new $class;
54
55
        if (!$model instanceof Model) {
56
            throw new ModelException(sprintf('Class %s must be an instance of %s', $this->model(), Model::class));
57
        }
58
59
        return $this->model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model of type object<DJStarCOM\BookingComSDK\Models\Model> is incompatible with the declared type string of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    abstract protected function model(): string;
66
67
    /**
68
     * Returns a list of the bookings that have been made through your account or with one of your affiliate IDs.
69
     *
70
     * @param HttpClientInterface $client
71
     * @return Result
72
     * @throws BookingResponseException
73
     */
74
    public function execute(HttpClientInterface $client): Result
75
    {
76
        $data = $this->prepareRequestData();
77
78
        $uri = $this->getUri() ?? null;
79
        if ($uri === null) {
80
            throw new BookingResponseException('URI is not set');
81
        }
82
83
        $response = $client->call($this->getRequestMethod(), $this->getUrl($uri), $data);
84
85
        if (isset($response->message)) {
86
            throw new BookingResponseException($response->message);
87
        }
88
89
        return $this->prepareResponse($response->result);
90
    }
91
92
    /**
93
     * Prepare data for request.
94
     *
95
     * @return array
96
     */
97
    protected function prepareRequestData(): array
98
    {
99
        $data = array_filter(array_intersect_key(get_object_vars($this), $this->getAttributeMap()));
100
        if (count($data)) {
101
            foreach ($data as $key => $value) {
102
                if (is_array($value)) {
103
                    $data[$key] = implode(',', $value);
104
                }
105
            }
106
        }
107
108
        return $data;
109
    }
110
111
    /**
112
     * @return array
113
     */
114
    abstract protected function getAttributeMap(): array;
115
116
    /**
117
     * @return string
118
     */
119
    public function getUri(): ?string
120
    {
121
        return static::$uri;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    protected function getRequestMethod(): string
128
    {
129
        return self::REQUEST_METHOD_GET;
130
    }
131
132
    /**
133
     * @param $url
134
     * @return string
135
     */
136
    protected function getUrl($url): string
137
    {
138
        return str_replace('{secure}', $this->isSecure() ? 'secure-' : '', $this->endpoint) . $url;
139
    }
140
141
    /**
142
     * @return bool
143
     */
144
    abstract protected function isSecure(): bool;
145
146
    /**
147
     * @param $data
148
     * @return Result
149
     */
150
    protected function prepareResponse($data): Result
151
    {
152
        $collections = new Result();
153
154
        foreach ($data as $item) {
155
            $class = $this->model();
156
157
            /** @var Model $model */
158
            $model = new $class;
159
            $model->setAttributes((array)$item);
160
161
            $collections->addItem($model, $model->getPrimaryKey());
162
        }
163
164
        return $collections;
165
    }
166
167
    /**
168
     * @param array $data
169
     */
170
    public function setAttributes(array $data): void
171
    {
172
        $prepareData = array_intersect_key($data, $this->getAttributeMap());
173
174
        foreach ($prepareData as $key => $value) {
175
            if (!property_exists($this, $key)) {
176
                continue;
177
            }
178
179
            $this->$key = $value;
180
        }
181
    }
182
}
183