diff --git a/src/GoogleApiHelper.php b/src/GoogleApiHelper.php index 616f08e..217f180 100644 --- a/src/GoogleApiHelper.php +++ b/src/GoogleApiHelper.php @@ -63,7 +63,7 @@ public function performQuery($siteId, $startDate, $endDate, $metrics, array $oth return $googleAnswer; } - + /** * Query the Google Analytics Real Time Reporting Service with given parameters. * @@ -86,6 +86,7 @@ public function performRealTimeQuery($id, $metrics, array $others = []) if ($this->useRealTimeCache()) { $this->cache->put($realTimeCacheName, $googleAnswer, Carbon::now()->addSeconds($this->realTimeCacheLifeTimeInSeconds)); } + return $googleAnswer; } @@ -154,7 +155,8 @@ private function useCache() /** * Set the cache time. * - * @param int $cacheLifeTimeInMinutes + * @param int $cacheLifeTimeInMinutes + * * @return self */ public function setCacheLifeTimeInMinutes($cacheLifeTimeInMinutes) @@ -189,7 +191,8 @@ private function useRealTimeCache() /** * Set the cache time. * - * @param int $realTimeCacheLifeTimeInSeconds + * @param int $realTimeCacheLifeTimeInSeconds + * * @return self */ public function setRealTimeCacheLifeTimeInMinutes($realTimeCacheLifeTimeInSeconds) diff --git a/src/LaravelAnalytics.php b/src/LaravelAnalytics.php index 28b6e5b..7dd5936 100644 --- a/src/LaravelAnalytics.php +++ b/src/LaravelAnalytics.php @@ -27,10 +27,10 @@ public function __construct(GoogleApiHelper $client, $siteId = '') } /** - * Set the siteId + * Set the siteId. * * @param string $siteId - + * * @return $this */ public function setSiteId($siteId) @@ -227,23 +227,23 @@ public function getMostVisitedPages($numberOfDays = 365, $maxResults = 20) } /** - * Get the number of active users currently on the site + * Get the number of active users currently on the site. + * + * @param array $others * - * @param array $others - * * @return int */ public function getActiveUsers($others = array()) { $answer = $this->performRealTimeQuery('rt:activeUsers', $others); - + if (is_null($answer->rows)) { return 0; } - + return $answer->rows[0][0]; } - + /** * Get the most visited pages for the given period. * @@ -302,8 +302,8 @@ public function performQuery(DateTime $startDate, DateTime $endDate, $metrics, $ /** * Call the real time query method on the authenticated client. * - * @param string $metrics - * @param array $others + * @param string $metrics + * @param array $others * * @return mixed */ @@ -311,7 +311,7 @@ public function performRealTimeQuery($metrics, $others = array()) { return $this->client->performRealTimeQuery($this->siteId, $metrics, $others); } - + /** * Return true if this site is configured to use Google Analytics. * @@ -321,8 +321,6 @@ public function isEnabled() { return $this->siteId != ''; } - - /** * Returns an array with the current date and the date minus the number of days specified. diff --git a/src/LaravelAnalyticsServiceProvider.php b/src/LaravelAnalyticsServiceProvider.php index c337f38..cab59d3 100644 --- a/src/LaravelAnalyticsServiceProvider.php +++ b/src/LaravelAnalyticsServiceProvider.php @@ -66,7 +66,7 @@ protected function guardAgainstMissingP12() } /** - * Get a configured GoogleClient + * Get a configured GoogleClient. * * @return Google_Client */ @@ -78,7 +78,7 @@ protected function getGoogleClient() 'use_objects' => true, ] ); - + $client->setClassConfig('Google_Cache_File', 'directory', storage_path('app/laravel-analytics-cache')); $client->setAccessType('offline'); diff --git a/tests/LaravelAnalyticsTest.php b/tests/LaravelAnalyticsTest.php index 2dc328d..0e84bbd 100644 --- a/tests/LaravelAnalyticsTest.php +++ b/tests/LaravelAnalyticsTest.php @@ -4,7 +4,6 @@ class LaravelAnalyticsTest extends PHPUnit_Framework_TestCase { - protected $client; protected $laravelAnalytics; protected $siteId; @@ -18,7 +17,7 @@ public function setUp() } /** - * Test method getVisitorsAndPageViews() + * Test method getVisitorsAndPageViews(). */ public function testGetVisitorsAndPageViews() { @@ -42,7 +41,7 @@ public function testGetVisitorsAndPageViews() } /** - * Test method getTopKeywords() + * Test method getTopKeywords(). */ public function testGetTopKeywords() { @@ -60,7 +59,7 @@ public function testGetTopKeywords() } /** - * Test method getTopReferrers() + * Test method getTopReferrers(). */ public function testGetTopReferrers() { @@ -78,7 +77,7 @@ public function testGetTopReferrers() } /** - * Test method getTopReferrers() + * Test method getTopReferrers(). */ public function testGetTopBrowsers() { @@ -96,7 +95,7 @@ public function testGetTopBrowsers() } /** - * Test method getTopReferrers() + * Test method getTopReferrers(). */ public function testGetMostVisitedPages() { @@ -114,7 +113,7 @@ public function testGetMostVisitedPages() } /** - * Test method getSiteIdByUrl() + * Test method getSiteIdByUrl(). */ public function testGetSiteIdByUrl() { @@ -129,7 +128,7 @@ public function testGetSiteIdByUrl() } /** - * Test method performQuery() + * Test method performQuery(). */ public function testPerformQuery() { @@ -161,9 +160,9 @@ public function testIsEnabled() $disabledAnalytics = new \Spatie\LaravelAnalytics\LaravelAnalytics($this->client); $this->assertFalse($disabledAnalytics->isEnabled()); } - + /** - * Test method performRealTimeQuery() + * Test method performRealTimeQuery(). */ public function testPerformRealTimeQuery() { @@ -183,14 +182,14 @@ public function testPerformRealTimeQuery() } /** - * Test method getActiveUsers() + * Test method getActiveUsers(). */ public function testGetActiveUsers() { - $others = ['first', 'second']; - $metrics = 'rt:activeUsers'; + $others = ['first', 'second']; + $metrics = 'rt:activeUsers'; - $this->client + $this->client ->shouldReceive('performRealTimeQuery') ->with($this->siteId, $metrics, $others) ->andReturn((object) ['rows' => [[0, '500']]]);