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 (3)

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/GoogleClient.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 Spatie\Analytics;
4
5
use Carbon\Carbon;
6
use Exception;
7
use Google_Client;
8
use Google_Service_Analytics;
9
10
class GoogleClient
11
{
12
    /**
13
     * @var Google_Service_Analytics
14
     */
15
    protected $service;
16
17
    /**
18
     * @var \Spatie\Analytics\Cache
19
     */
20
    protected $cache;
21
22
    /**
23
     * @var int
24
     */
25
    protected $cacheLifeTimeInMinutes;
26
27
    /**
28
     * @var int
29
     */
30
    protected $realTimeCacheLifeTimeInSeconds;
31
32
    /**
33
     * @param  Google_Client $client
34
     * @param  \Spatie\Analytics\Cache $cache
35
     * @param  int $cacheLifeTimeInMinutes
36
     * @param  int $realTimeCacheLifeTimeInSeconds
37
     */
38
    public function __construct(
39
        Google_Client $client,
40
        Cache $cache = null,
41
        $cacheLifeTimeInMinutes = 0,
42
        $realTimeCacheLifeTimeInSeconds = 0
43
    ) {
44
        $this->service = new Google_Service_Analytics($client);
45
        $this->cache = $cache;
46
47
        $this->cacheLifeTimeInMinutes = $cacheLifeTimeInMinutes;
48
        $this->realTimeCacheLifeTimeInSeconds = $realTimeCacheLifeTimeInSeconds;
49
    }
50
51
    /**
52
     * Query the Google Analytics Service with given parameters.
53
     *
54
     * @param  int    $id
55
     * @param  string $startDate
56
     * @param  string $endDate
57
     * @param  string $metrics
58
     * @param  array  $others
59
     * @return mixed
60
     */
61
    public function performQuery($id, $startDate, $endDate, $metrics, array $others = array())
62
    {
63
        $cacheName = $this->determineCacheName(func_get_args());
64
65
        if ($this->useCache() && $this->cache->has($cacheName)) {
66
            return $this->cache->get($cacheName);
67
        }
68
69
        $googleAnswer = $this->service->data_ga->get($id, $startDate, $endDate, $metrics, $others);
70
71
        if ($this->useCache()) {
72
            $this->cache->put($cacheName, $googleAnswer, $this->cacheLifeTimeInMinutes);
73
        }
74
75
        return $googleAnswer;
76
    }
77
    
78
    /**
79
     * Query the Google Analytics Real Time Reporting Service with given parameters.
80
     *
81
     * @param  int    $id
82
     * @param  string $metrics
83
     * @param  array  $others
84
     * @return mixed
85
     */
86
    public function performRealTimeQuery($id, $metrics, array $others = array())
87
    {
88
        $realTimeCacheName = $this->determineRealTimeCacheName(func_get_args());
89
90
        if ($this->useRealTimeCache() && $this->cache->has($realTimeCacheName)) {
91
            return $this->cache->get($realTimeCacheName);
92
        }
93
94
        $googleAnswer =  $this->service->data_realtime->get($id, $metrics, $others);
95
96
        if ($this->useRealTimeCache()) {
97
            $this->cache->put(
98
                $realTimeCacheName,
99
                $googleAnswer,
100
                Carbon::now()->addSeconds($this->realTimeCacheLifeTimeInSeconds)
0 ignored issues
show
\Carbon\Carbon::now()->a...CacheLifeTimeInSeconds) is of type object<Carbon\Carbon>, but the function expects a integer.

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...
101
            );
102
        }
103
104
        return $googleAnswer;
105
    }
106
107
    /**
108
     * Get a site Id by its URL.
109
     *
110
     * @param  string $url
111
     * @return mixed
112
     * @throws \Exception
113
     */
114
    public function getSiteIdByUrl($url)
115
    {
116
        $siteIds = $this->getAllSiteIds();
117
118
        if (isset($siteIds[$url])) {
119
            return $siteIds[$url];
120
        }
121
122
        throw new Exception("Site $url is not present in your Analytics account.");
123
    }
124
125
    /**
126
     * Get all siteIds.
127
     *
128
     * @return array
129
     */
130
    public function getAllSiteIds()
131
    {
132
        static $siteIds = null;
133
134
        if (! is_null($siteIds)) {
135
            return $siteIds;
136
        }
137
138
        foreach ($this->service->management_profiles->listManagementProfiles("~all", "~all") as $site) {
139
            $siteIds[$site['websiteUrl']] = 'ga:'.$site['id'];
140
        }
141
142
        return $siteIds;
143
    }
144
145
    /**
146
     * Determine the cache name for the set of query properties given.
147
     *
148
     * @param  array $properties
149
     * @return string
150
     */
151
    protected function determineCacheName(array $properties)
152
    {
153
        return 'spatie.laravel-analytics.'.md5(serialize($properties));
154
    }
155
156
    /**
157
     * Determine if request to Google should be cached.
158
     *
159
     * @return bool
160
     */
161
    protected function useCache()
162
    {
163
        return isset($this->cache) && $this->cacheLifeTimeInMinutes > 0;
164
    }
165
166
    /**
167
     * Set the cache time.
168
     *
169
     * @param  int $cacheLifeTimeInMinutes
170
     * @return self
171
     */
172
    public function setCacheLifeTimeInMinutes($cacheLifeTimeInMinutes)
173
    {
174
        $this->cacheLifeTimeInMinutes = $cacheLifeTimeInMinutes;
175
176
        return $this;
177
    }
178
179
    /**
180
     * Determine the cache name for RealTime function calls for the set of query properties given.
181
     *
182
     * @param  array $properties
183
     * @return string
184
     */
185
    protected function determineRealTimeCacheName(array $properties)
186
    {
187
        return 'spatie.laravel-analytics.RealTime.'.md5(serialize($properties));
188
    }
189
190
    /**
191
     * Determine if RealTime request to Google should be cached.
192
     *
193
     * @return bool
194
     */
195
    protected function useRealTimeCache()
196
    {
197
        return isset($this->cache) && $this->realTimeCacheLifeTimeInSeconds > 0;
198
    }
199
200
    /**
201
     * Set the cache time.
202
     *
203
     * @param  int $realTimeCacheLifeTimeInSeconds
204
     * @return self
205
     */
206
    public function setRealTimeCacheLifeTimeInMinutes($realTimeCacheLifeTimeInSeconds)
207
    {
208
        $this->realTimeCacheLifeTimeInSeconds = $realTimeCacheLifeTimeInSeconds;
209
210
        return $this;
211
    }
212
}
213