GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (29)

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/Repository/Target/AudienceRepository.php (9 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
namespace Audiens\AdobeClient\Repository\Target;
4
5
use Audiens\AdobeClient\CachableTrait;
6
use Audiens\AdobeClient\CacheableInterface;
7
use Audiens\AdobeClient\Entity\Target\Audience;
8
use Audiens\AdobeClient\Exceptions\RepositoryException;
9
use Audiens\AdobeClient\Repository\RepositoryResponse;
10
use Doctrine\Common\Cache\Cache;
11
use GuzzleHttp\Client;
12
use GuzzleHttp\ClientInterface;
13
use GuzzleHttp\RequestOptions;
14
15
/**
16
 * Class AudienceRepository
17
 */
18
class AudienceRepository implements CacheableInterface
19
{
20
    use CachableTrait;
21
22
    const BASE_URL = 'https://mc.adobe.io/%s/target/audiences/';
23
24
    /** @var Client */
25
    protected $client;
26
27
    /** @var  Cache */
28
    protected $cache;
29
30
    /** @var  string */
31
    protected $baseUrl;
32
33
    const CACHE_NAMESPACE = 'adobe_target_repository_find_all';
34
35
    const CACHE_EXPIRATION = 3600;
36
37
    /**
38
     * AudienceRepository constructor.
39
     *
40
     * @param ClientInterface $client
41
     * @param Cache|null      $cache
42
     */
43 View Code Duplication
    public function __construct(ClientInterface $client, Cache $cache = null)
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...
44
    {
45
        $this->client       = $client;
0 ignored issues
show
Documentation Bug introduced by
$client is of type object<GuzzleHttp\ClientInterface>, but the property $client was declared to be of type object<GuzzleHttp\Client>. 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...
46
        $this->cache        = $cache;
47
        $this->cacheEnabled = $cache instanceof Cache;
48
        $this->baseUrl      = self::BASE_URL;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getBaseUrl()
55
    {
56
        return $this->baseUrl;
57
    }
58
59
    /**
60
     * @param string $baseUrl
61
     */
62
    public function setBaseUrl($baseUrl)
63
    {
64
        $this->baseUrl = $baseUrl;
65
    }
66
67
    public function create(Audience $audience, $tenant)
68
    {
69
        $compiledUrl = sprintf($this->baseUrl, $tenant);
70
71
        if (empty($audience->getName())) {
72
            return;
73
        }
74
75
        $response = $this->client->request(
76
            'POST',
77
            $compiledUrl,
78
            [
79
                                               RequestOptions::JSON => [$audience->toArray()],
80
81
            ]
82
        );
83
84
        $repositoryResponse = RepositoryResponse::fromResponse($response);
0 ignored issues
show
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
85
86
        if (!$repositoryResponse->isSuccessful()) {
87
            return null;
88
        }
89
90
        $stream          = $response->getBody();
91
        $responseContent = \json_decode($stream->getContents(), true);
92
        $stream->rewind();
93
94
        return Audience::fromArray($responseContent);
95
    }
96
97
    public function update(Audience $audience, $tenant)
98
    {
99
        $compiledUrl = sprintf($this->baseUrl, $tenant);
100
101
        $compiledUrl = $compiledUrl. $audience->getId();
102
103
        if (empty($audience->getId())) {
104
            return;
105
        }
106
107
        $response = $this->client->request(
108
            'PUT',
109
            $compiledUrl,
110
            [
111
                                               RequestOptions::JSON => [$audience->toArray()],
112
113
            ]
114
        );
115
116
        $repositoryResponse = RepositoryResponse::fromResponse($response);
0 ignored issues
show
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
117
118
        if (!$repositoryResponse->isSuccessful()) {
119
            return null;
120
        }
121
122
        $stream          = $response->getBody();
123
        $responseContent = \json_decode($stream->getContents(), true);
124
        $stream->rewind();
125
126
        return Audience::fromArray($responseContent);
127
    }
128
129
    public function findOneById($id, $tenant)
130
    {
131
        if (empty($tenant)) {
132
            RepositoryException::genericFailed('Missing tenant params');
133
        }
134
135
        $baseUrl = sprintf($this->baseUrl, $tenant);
136
137
        $compiledUrl = $baseUrl . '?id=' . $id;
138
139
        $response = $this->client->request('GET', $compiledUrl);
140
141
        $repositoryResponse = RepositoryResponse::fromResponse($response);
0 ignored issues
show
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
142
143
        if (!$repositoryResponse->isSuccessful()) {
144
            return null;
145
        }
146
147
        $stream          = $response->getBody();
148
        $responseContent = \json_decode($stream->getContents(), true);
149
        $stream->rewind();
150
151 View Code Duplication
        if (!isset($responseContent['audiences']) || count($responseContent['audiences']) == 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
152
            return null;
153
        }
154
155
        if (count($responseContent['audiences']) > 1) {
156
            RepositoryException::genericFailed('Adobe Target returned more that one audiences...please check your id');
157
        }
158
159
        return Audience::fromArray($responseContent['audiences'][0]);
160
    }
161
162
    public function findAll($tenant)
163
    {
164
        if (empty($tenant)) {
165
            RepositoryException::genericFailed('Missing tenant params');
166
        }
167
168
        $date = date('Y_m_d_H');
169
170
        $cacheKey = self::CACHE_NAMESPACE . sha1($date);
171
172
        if ($this->isCacheEnabled()) {
173
            if ($this->cache->contains($cacheKey)) {
174
                return $this->cache->fetch($cacheKey);
175
            }
176
        }
177
178
        $compiledUrl = sprintf($this->baseUrl, $tenant);
179
180
        $response = $this->client->request('GET', $compiledUrl);
181
182
        $repositoryResponse = RepositoryResponse::fromResponse($response);
0 ignored issues
show
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
183
184
        if (!$repositoryResponse->isSuccessful()) {
185
            throw RepositoryException::genericFailed($repositoryResponse);
0 ignored issues
show
$repositoryResponse is of type object<Audiens\AdobeClie...ory\RepositoryResponse>, but the function expects a string.

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...
186
        }
187
188
        $stream          = $response->getBody();
189
        $responseContent = \json_decode($stream->getContents(), true);
190
        $stream->rewind();
191
192
        $result = [];
193
194 View Code Duplication
        if (!isset($responseContent['audiences']) || count($responseContent['audiences']) == 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
195
            return $result;
196
        }
197
198
        $audiences = $responseContent['audiences'];
199
200
        foreach ($audiences as $audience) {
201
            $result[] = Audience::fromArray($audience);
202
        }
203
204
        if ($this->isCacheEnabled()) {
205
            $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
206
        }
207
208
        return $result;
209
    }
210
}
211