Issues (56)

Security Analysis    not enabled

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/Model/ProfileSettings/TargetAudience.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
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\ProfileSettings;
6
7
use Kerox\Messenger\Exception\InvalidTypeException;
8
use Kerox\Messenger\Helper\UtilityTrait;
9
use Kerox\Messenger\Helper\ValidatorTrait;
10
11
/**
12
 * @deprecated Since version 3.3.0 and will be removed in version 4.0.0.
13
 */
14
class TargetAudience implements \JsonSerializable
15
{
16
    use UtilityTrait;
17
    use ValidatorTrait;
18
19
    private const AUDIENCE_TYPE_ALL = 'all';
20
    private const AUDIENCE_TYPE_CUSTOM = 'custom';
21
    private const AUDIENCE_TYPE_NONE = 'none';
22
23
    /**
24
     * @var string
25
     */
26
    protected $audienceType;
27
28
    /**
29
     * @var array
30
     */
31
    protected $whitelistCountries;
32
33
    /**
34
     * @var array
35
     */
36
    protected $blacklistCountries;
37
38
    /**
39
     * TargetAudience constructor.
40
     *
41
     * @throws \Kerox\Messenger\Exception\MessengerException
42
     */
43 2
    public function __construct(
44
        string $audienceType = self::AUDIENCE_TYPE_ALL,
45
        array $whitelistCountries = [],
46
        array $blacklistCountries = []
47
    ) {
48 2
        $this->isValidAudienceType($audienceType);
49 1
        $this->isValidCountries($whitelistCountries);
50 1
        $this->isValidCountries($blacklistCountries);
51
52 1
        $this->audienceType = $audienceType;
53 1
        $this->whitelistCountries = $whitelistCountries;
54 1
        $this->blacklistCountries = $blacklistCountries;
55 1
    }
56
57
    /**
58
     * @throws \Kerox\Messenger\Exception\MessengerException
59
     *
60
     * @return \Kerox\Messenger\Model\ProfileSettings\TargetAudience
61
     */
62 2
    public static function create(
63
        string $audienceType = self::AUDIENCE_TYPE_ALL,
64
        array $whitelistCountries = [],
65
        array $blacklistCountries = []
66
    ): self {
67 2
        return new self($audienceType, $whitelistCountries, $blacklistCountries);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Model\Pr...Settings\TargetAudience has been deprecated with message: Since version 3.3.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
68
    }
69
70
    /**
71
     * @throws \Kerox\Messenger\Exception\MessengerException
72
     *
73
     * @return \Kerox\Messenger\Model\ProfileSettings\TargetAudience
74
     */
75 1
    public function addWhitelistCountry(string $country): self
76
    {
77 1
        $this->isValidCountry($country);
78
79 1
        $this->whitelistCountries[] = $country;
80
81 1
        return $this;
82
    }
83
84
    /**
85
     * @throws \Kerox\Messenger\Exception\MessengerException
86
     *
87
     * @return \Kerox\Messenger\Model\ProfileSettings\TargetAudience
88
     */
89 1
    public function addBlacklistCountry(string $country): self
90
    {
91 1
        $this->isValidCountry($country);
92
93 1
        $this->blacklistCountries[] = $country;
94
95 1
        return $this;
96
    }
97
98
    /**
99
     * @throws \Kerox\Messenger\Exception\MessengerException
100
     */
101 1
    private function isValidCountries(array $countries): void
102
    {
103 1
        if (!empty($countries)) {
104 1
            foreach ($countries as $country) {
105 1
                $this->isValidCountry($country);
106
            }
107
        }
108 1
    }
109
110
    /**
111
     * @throws \Kerox\Messenger\Exception\MessengerException
112
     */
113 2
    private function isValidAudienceType(string $audienceType): void
114
    {
115 2
        $allowedAudienceType = $this->getAllowedAudienceType();
116 2
        if (!\in_array($audienceType, $allowedAudienceType, true)) {
117 1
            throw new InvalidTypeException(sprintf('audienceType must be either "%s".', implode(', ', $allowedAudienceType)));
118
        }
119 1
    }
120
121 2
    private function getAllowedAudienceType(): array
122
    {
123
        return [
124 2
            self::AUDIENCE_TYPE_ALL,
125 2
            self::AUDIENCE_TYPE_CUSTOM,
126 2
            self::AUDIENCE_TYPE_NONE,
127
        ];
128
    }
129
130 1
    public function toArray(): array
131
    {
132
        $array = [
133 1
            'audience_type' => $this->audienceType,
134
            'countries' => [
135 1
                'whitelist' => $this->whitelistCountries,
136 1
                'blacklist' => $this->blacklistCountries,
137
            ],
138
        ];
139
140 1
        return $this->arrayFilter($array);
141
    }
142
143 1
    public function jsonSerialize(): array
144
    {
145 1
        return $this->toArray();
146
    }
147
}
148