diff --git a/README.md b/README.md index d7eca5d..9bfc33a 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,10 @@ An easy-to-use API Wrapper for [Googles PageSpeed Insights](https://developers.g ### Simple Usage ```php -$uri = 'http://example.com'; +$url = 'http://example.com'; + $caller = new \PhpInsights\InsightsCaller('your-google-api-key-here', 'de'); -$response = $caller->getResponse($uri, \PhpInsights\InsightsCaller::STRATEGY_MOBILE); +$response = $caller->getResponse($url, \PhpInsights\InsightsCaller::STRATEGY_MOBILE); $result = $response->getMappedResult(); var_dump($result->getSpeedScore()); // 100 diff --git a/composer.json b/composer.json index 1696670..d8aeaa1 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "dsentker/phpinsights", "description": "A php wrapper for Googles page speed insights", + "version": "0.2.2", "require": { "php": "^5.4 || ^7.0", "netresearch/jsonmapper": "^1.1", diff --git a/src/InsightsCaller.php b/src/InsightsCaller.php index 9e31b29..b781734 100644 --- a/src/InsightsCaller.php +++ b/src/InsightsCaller.php @@ -100,6 +100,7 @@ public function setCaptureScreenshot($captureScreenshot) protected function createApiEndpointUrl($url, $strategy = 'mobile') { $screenshot = ($this->isCaptureScreenshot()) ? 'true' : 'false'; + return sprintf(self::GI_API_ENDPOINT, $url, $strategy, $this->apiKey, $this->locale, $screenshot); } diff --git a/src/InsightsResponse.php b/src/InsightsResponse.php index ef83f55..c0c2b16 100644 --- a/src/InsightsResponse.php +++ b/src/InsightsResponse.php @@ -32,7 +32,8 @@ private function __construct($jsonResponse) * * @throws InvalidJsonException */ - public static function validateResponse($json) { + public static function validateResponse($json) + { $result = json_decode($json); diff --git a/src/Result/InsightsException.php b/src/Result/InsightsException.php index 5dedeb2..9f20de3 100644 --- a/src/Result/InsightsException.php +++ b/src/Result/InsightsException.php @@ -1,5 +1,4 @@ getRuleGroups(); - if(!array_key_exists(RuleGroup::GROUP_USABILITY, $ruleGroups)) { + if (!array_key_exists(RuleGroup::GROUP_USABILITY, $ruleGroups)) { throw new UsabilityScoreNotAvailableException('Usability score is only available with mobile strategy API call.'); } @@ -162,6 +163,7 @@ public function getUsabilityScore() public function getSpeedScore() { $ruleGroups = $this->getRuleGroups(); + return $ruleGroups[RuleGroup::GROUP_SPEED]->getScore(); } @@ -182,8 +184,8 @@ public function hasScreenshot() public function getScreenshot() { - if(!$this->hasScreenshot()) { - ScreenshotNotAvailableException::raise(); + if (!$this->hasScreenshot()) { + ScreenshotNotAvailableException::raise(); } return $this->screenshot; diff --git a/src/Result/InsightsResultException.php b/src/Result/InsightsResultException.php index 88b382c..d045d92 100644 --- a/src/Result/InsightsResultException.php +++ b/src/Result/InsightsResultException.php @@ -1,7 +1,6 @@ getRuleResults() as $rule => $ruleResult) { - if(in_array($group, $ruleResult->getGroups())) { + foreach ($this->getRuleResults() as $rule => $ruleResult) { + if (in_array($group, $ruleResult->getGroups())) { $results[$rule] = $ruleResult; } } diff --git a/src/Result/Map/Screenshot.php b/src/Result/Map/Screenshot.php index 4806d91..ecc13d0 100644 --- a/src/Result/Map/Screenshot.php +++ b/src/Result/Map/Screenshot.php @@ -1,7 +1,6 @@