Issues (85)

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/BookingInfo.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 CultuurNet\UDB3;
4
5
use CultuurNet\UDB3\Model\ValueObject\Contact\BookingInfo as Udb3ModelBookingInfo;
6
use CultuurNet\UDB3\ValueObject\MultilingualString;
7
use DateTimeImmutable;
8
9
final class BookingInfo implements JsonLdSerializableInterface
10
{
11
    /**
12
     * @var string|null
13
     */
14
    protected $phone;
15
16
    /**
17
     * @var string|null
18
     */
19
    protected $email;
20
21
    /**
22
     * @var string|null
23
     */
24
    protected $url;
25
26
    /**
27
     * @var MultilingualString|null
28
     */
29
    protected $urlLabel;
30
31
    /**
32
     * @var DateTimeImmutable|null
33
     */
34
    protected $availabilityStarts;
35
36
    /**
37
     * @var DateTimeImmutable|null
38
     */
39
    protected $availabilityEnds;
40
41
    public function __construct(
42
        ?string $url = null,
43
        ?MultilingualString $urlLabel = null,
44
        ?string $phone = null,
45
        ?string $email = null,
46
        ?DateTimeImmutable $availabilityStarts = null,
47
        ?DateTimeImmutable $availabilityEnds = null
48
    ) {
49
        // Workaround to maintain compatibility with older BookingInfo data.
50
        // Empty BookingInfo properties used to be stored as empty strings in the past.
51
        // Convert those to null in case they are injected via the constructor (via BookingInfo::deserialize()).
52
        // API clients are also allowed to send empty strings for BookingInfo properties via EntryAPI3, which should
53
        // also be treated as null.
54
        $url = $this->castEmptyStringToNull($url);
55
        $phone = $this->castEmptyStringToNull($phone);
56
        $email = $this->castEmptyStringToNull($email);
57
58
        $this->url = $url;
59
        $this->urlLabel = $urlLabel;
60
        $this->phone = $phone;
61
        $this->email = $email;
62
        $this->availabilityStarts = $availabilityStarts;
63
        $this->availabilityEnds = $availabilityEnds;
64
    }
65
66
    public function getPhone(): ?string
67
    {
68
        return $this->phone;
69
    }
70
71
    public function getEmail(): ?string
72
    {
73
        return $this->email;
74
    }
75
76
    public function getUrl(): ?string
77
    {
78
        return $this->url;
79
    }
80
81
    public function getUrlLabel(): ?MultilingualString
82
    {
83
        return $this->urlLabel;
84
    }
85
86
    public function getAvailabilityStarts(): ?DateTimeImmutable
87
    {
88
        return $this->availabilityStarts;
89
    }
90
91
    public function getAvailabilityEnds(): ?DateTimeImmutable
92
    {
93
        return $this->availabilityEnds;
94
    }
95
96
    public function serialize(): array
97
    {
98
        $serialized = array_filter(
99
            [
100
              'phone' => $this->phone,
101
              'email' => $this->email,
102
              'url' => $this->url,
103
            ]
104
        );
105
106
        if ($this->availabilityStarts) {
107
            $serialized['availabilityStarts'] = $this->availabilityStarts->format(\DATE_ATOM);
108
        }
109
110
        if ($this->availabilityEnds) {
111
            $serialized['availabilityEnds'] = $this->availabilityEnds->format(\DATE_ATOM);
112
        }
113
114
        if ($this->urlLabel) {
115
            $serialized['urlLabel'] = $this->urlLabel->serialize();
116
        }
117
118
        return $serialized;
119
    }
120
121
    public static function deserialize(array $data): BookingInfo
122
    {
123
        $defaults = [
124
            'url' => null,
125
            'urlLabel' => null,
126
            'phone' => null,
127
            'email' => null,
128
            'availabilityStarts' => null,
129
            'availabilityEnds' => null,
130
        ];
131
132
        $data = array_merge($defaults, $data);
133
134
        $availabilityStarts = null;
135
        if ($data['availabilityStarts']) {
136
            $availabilityStarts = DateTimeImmutable::createFromFormat(\DATE_ATOM, $data['availabilityStarts']);
137
        }
138
139
        $availabilityEnds = null;
140
        if ($data['availabilityEnds']) {
141
            $availabilityEnds = DateTimeImmutable::createFromFormat(\DATE_ATOM, $data['availabilityEnds']);
142
        }
143
144
        $urlLabel = null;
145
        if ($data['urlLabel']) {
146
            $urlLabel = MultilingualString::deserialize($data['urlLabel']);
0 ignored issues
show
$data['urlLabel'] is of type null, but the function expects a array.

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...
147
        }
148
149
        return new self(
150
            $data['url'],
151
            $urlLabel,
152
            $data['phone'],
153
            $data['email'],
154
            $availabilityStarts,
155
            $availabilityEnds
156
        );
157
    }
158
159
    public function toJsonLd(): array
160
    {
161
        return $this->serialize();
162
    }
163
164
    public function sameAs(BookingInfo $otherBookingInfo): bool
165
    {
166
        return $this->toJsonLd() === $otherBookingInfo->toJsonLd();
167
    }
168
169
    public static function fromUdb3ModelBookingInfo(Udb3ModelBookingInfo $udb3ModelBookingInfo): BookingInfo
170
    {
171
        $url = null;
172
        $urlLabel = null;
173
        $phone = null;
174
        $email = null;
175
        $availabilityStarts = null;
176
        $availabilityEnds = null;
177
178
        if ($udb3ModelWebsite = $udb3ModelBookingInfo->getWebsite()) {
179
            $url = $udb3ModelWebsite->getUrl()->toString();
180
            $urlLabel = MultilingualString::fromUdb3ModelTranslatedValueObject($udb3ModelWebsite->getLabel());
181
        }
182
183
        if ($udb3ModelPhone = $udb3ModelBookingInfo->getTelephoneNumber()) {
184
            $phone = $udb3ModelPhone->toString();
185
        }
186
187
        if ($udb3ModelEmail = $udb3ModelBookingInfo->getEmailAddress()) {
188
            $email = $udb3ModelEmail->toString();
189
        }
190
191
        if ($udb3ModelAvailability = $udb3ModelBookingInfo->getAvailability()) {
192
            $availabilityStarts = $udb3ModelAvailability->getFrom();
193
            $availabilityEnds = $udb3ModelAvailability->getTo();
194
        }
195
196
        return new self(
197
            $url,
198
            $urlLabel,
199
            $phone,
200
            $email,
201
            $availabilityStarts,
202
            $availabilityEnds
203
        );
204
    }
205
206
    private function castEmptyStringToNull(?string $string = null): ?string
207
    {
208
        return is_string($string) && $string === '' ? null : $string;
209
    }
210
}
211