Skip to content

Commit

Permalink
psr2
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Oct 8, 2015
1 parent 75a9923 commit ea64fb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
9 changes: 6 additions & 3 deletions src/GoogleApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -154,7 +155,8 @@ private function useCache()
/**
* Set the cache time.
*
* @param int $cacheLifeTimeInMinutes
* @param int $cacheLifeTimeInMinutes
*
* @return self
*/
public function setCacheLifeTimeInMinutes($cacheLifeTimeInMinutes)
Expand Down Expand Up @@ -189,7 +191,8 @@ private function useRealTimeCache()
/**
* Set the cache time.
*
* @param int $realTimeCacheLifeTimeInSeconds
* @param int $realTimeCacheLifeTimeInSeconds
*
* @return self
*/
public function setRealTimeCacheLifeTimeInMinutes($realTimeCacheLifeTimeInSeconds)
Expand Down
24 changes: 11 additions & 13 deletions src/LaravelAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -302,16 +302,16 @@ 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
*/
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.
*
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelAnalyticsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function guardAgainstMissingP12()
}

/**
* Get a configured GoogleClient
* Get a configured GoogleClient.
*
* @return Google_Client
*/
Expand All @@ -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');
Expand Down
27 changes: 13 additions & 14 deletions tests/LaravelAnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class LaravelAnalyticsTest extends PHPUnit_Framework_TestCase
{

protected $client;
protected $laravelAnalytics;
protected $siteId;
Expand All @@ -18,7 +17,7 @@ public function setUp()
}

/**
* Test method getVisitorsAndPageViews()
* Test method getVisitorsAndPageViews().
*/
public function testGetVisitorsAndPageViews()
{
Expand All @@ -42,7 +41,7 @@ public function testGetVisitorsAndPageViews()
}

/**
* Test method getTopKeywords()
* Test method getTopKeywords().
*/
public function testGetTopKeywords()
{
Expand All @@ -60,7 +59,7 @@ public function testGetTopKeywords()
}

/**
* Test method getTopReferrers()
* Test method getTopReferrers().
*/
public function testGetTopReferrers()
{
Expand All @@ -78,7 +77,7 @@ public function testGetTopReferrers()
}

/**
* Test method getTopReferrers()
* Test method getTopReferrers().
*/
public function testGetTopBrowsers()
{
Expand All @@ -96,7 +95,7 @@ public function testGetTopBrowsers()
}

/**
* Test method getTopReferrers()
* Test method getTopReferrers().
*/
public function testGetMostVisitedPages()
{
Expand All @@ -114,7 +113,7 @@ public function testGetMostVisitedPages()
}

/**
* Test method getSiteIdByUrl()
* Test method getSiteIdByUrl().
*/
public function testGetSiteIdByUrl()
{
Expand All @@ -129,7 +128,7 @@ public function testGetSiteIdByUrl()
}

/**
* Test method performQuery()
* Test method performQuery().
*/
public function testPerformQuery()
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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']]]);
Expand Down

0 comments on commit ea64fb2

Please sign in to comment.