Skip to content

Commit

Permalink
Merge pull request #12 from schulzefelix/analysis-8Q4K93
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
schulzefelix committed Nov 27, 2017
2 parents 4a0eca0 + d35b83c commit 14a6059
Show file tree
Hide file tree
Showing 47 changed files with 624 additions and 619 deletions.
9 changes: 5 additions & 4 deletions src/Api/BaseStat.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php namespace SchulzeFelix\Stat\Api;
<?php

namespace SchulzeFelix\Stat\Api;

use Carbon\Carbon;
use SchulzeFelix\Stat\StatClient;
use GuzzleHttp\Exception\ClientException;
use SchulzeFelix\Stat\Exceptions\ApiException;
use SchulzeFelix\Stat\Exceptions\RequestException;
use SchulzeFelix\Stat\Objects\StatEngineRankDistribution;
use SchulzeFelix\Stat\Objects\StatRankDistribution;
use SchulzeFelix\Stat\StatClient;
use SchulzeFelix\Stat\Objects\StatEngineRankDistribution;

class BaseStat
{
Expand All @@ -24,7 +26,6 @@ public function __construct(StatClient $statClient)
$this->statClient = $statClient;
}


/**
* @param $method
* @param array $parameters
Expand Down
20 changes: 9 additions & 11 deletions src/Api/StatBilling.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace SchulzeFelix\Stat\Api;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use SchulzeFelix\Stat\Objects\StatBill;
use SchulzeFelix\Stat\Objects\StatSite;
use SchulzeFelix\Stat\Objects\StatSubAccount;
use SchulzeFelix\Stat\Objects\StatBillSummary;
use SchulzeFelix\Stat\Objects\StatBillServices;
use SchulzeFelix\Stat\Objects\StatBillKeywordType;
use SchulzeFelix\Stat\Objects\StatBillKeywordTypes;
use SchulzeFelix\Stat\Objects\StatBillOptionalServiceType;
use SchulzeFelix\Stat\Objects\StatBillServices;
use SchulzeFelix\Stat\Objects\StatBillSummary;
use SchulzeFelix\Stat\Objects\StatSite;
use SchulzeFelix\Stat\Objects\StatSubAccount;
use SchulzeFelix\Stat\Objects\StatTag;

class StatBilling extends BaseStat
{
Expand Down Expand Up @@ -115,11 +113,11 @@ private function extractSummary($response)
$statBillSummary = new StatBillSummary([
'start_date' => $response['Summary']['StartDate'],
'end_date' => $response['Summary']['EndDate'],
'min_committed_charge' => (float)array_get($response, 'Summary.MinCommittedCharge', 0.0),
'tracked_keywords' => (int)$response['Summary']['TrackedKeywords'],
'tracked_keywords_total' => (float)$response['Summary']['TrackedKeywordsTotal'],
'optional_service_total' => (float)$response['Summary']['OptionalServiceTotal'],
'total' => (float)$response['Summary']['Total'],
'min_committed_charge' => (float) array_get($response, 'Summary.MinCommittedCharge', 0.0),
'tracked_keywords' => (int) $response['Summary']['TrackedKeywords'],
'tracked_keywords_total' => (float) $response['Summary']['TrackedKeywordsTotal'],
'optional_service_total' => (float) $response['Summary']['OptionalServiceTotal'],
'total' => (float) $response['Summary']['Total'],
]);

return $statBillSummary;
Expand Down
30 changes: 14 additions & 16 deletions src/Api/StatBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace SchulzeFelix\Stat\Api;

use Carbon\Carbon;
use SchulzeFelix\Stat\Exceptions\ApiException;
use SchulzeFelix\Stat\Objects\StatTag;
use SchulzeFelix\Stat\Objects\StatSite;
use SchulzeFelix\Stat\Objects\StatBulkJob;
use SchulzeFelix\Stat\Objects\StatKeyword;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;
use SchulzeFelix\Stat\Objects\StatKeywordRanking;
use SchulzeFelix\Stat\Objects\StatProject;
use SchulzeFelix\Stat\Exceptions\ApiException;
use SchulzeFelix\Stat\Objects\StatKeywordStats;
use SchulzeFelix\Stat\Objects\StatKeywordRanking;
use SchulzeFelix\Stat\Objects\StatLocalSearchTrend;
use SchulzeFelix\Stat\Objects\StatProject;
use SchulzeFelix\Stat\Objects\StatSite;
use SchulzeFelix\Stat\Objects\StatTag;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;

class StatBulk extends BaseStat
{
Expand Down Expand Up @@ -61,7 +61,6 @@ public function ranks(Carbon $date, array $sites = null, $rankType = 'highest',

if (! is_null($sites) && count($sites) > 0) {
$arguments['site_id'] = implode(',', $sites);
;
}
if (! is_null($engines) && count($engines) > 0) {
$arguments['engines'] = implode(',', $engines);
Expand All @@ -82,22 +81,24 @@ public function delete($bulkJobID)
{
$response = $this->performQuery('bulk/delete', ['id' => $bulkJobID]);

return (int)$response['Result']['Id'];
return (int) $response['Result']['Id'];
}

public function siteRankingDistributions($date)
{
$this->validateBulkDate($date);

$response = $this->performQuery('bulk/site_ranking_distributions', ['date' => $date->toDateString()]);
return (int)$response['Result']['Id'];

return (int) $response['Result']['Id'];
}

public function tagRankingDistributions($date)
{
$this->validateBulkDate($date);

$response = $this->performQuery('bulk/tag_ranking_distributions', ['date' => $date->toDateString()]);

return (int) $response['Result']['Id'];
}

Expand All @@ -106,7 +107,7 @@ public function get($bulkJobID)
$bulkStatus = $this->status($bulkJobID);

if ($bulkStatus['status'] != 'Completed') {
throw ApiException::resultError('Bulk Job is not completed. Current status: ' . $bulkJobID['status'] . '.');
throw ApiException::resultError('Bulk Job is not completed. Current status: '.$bulkJobID['status'].'.');
}

$bulkStream = $this->statClient->downloadBulkJobStream($bulkStatus['stream_url']);
Expand All @@ -125,7 +126,6 @@ private function validateBulkDate(Carbon $date)
}
}


private function parseBulkJob($bulkStream)
{
$projects = $this->getCollection($bulkStream['Project']);
Expand Down Expand Up @@ -161,7 +161,6 @@ private function transformProject($project)
return $transformedProject;
}


private function transformSite($site)
{
$transformedSite = new StatSite();
Expand All @@ -186,7 +185,6 @@ private function transformSite($site)
});
}


return $transformedSite;
}

Expand Down Expand Up @@ -229,7 +227,7 @@ private function transformKeyword($keyword)

$modifiedKeyword->ranking = new StatKeywordRanking([
'date' => $keyword['Ranking']['date'],
'type' => $keyword['Ranking']['type']
'type' => $keyword['Ranking']['type'],
]);

if (array_key_exists('Google', $keyword['Ranking'])) {
Expand All @@ -250,7 +248,7 @@ private function analyzeRanking($rankingForEngine, $rankingType)
}

if (is_null($rankingForEngine['Result'])) {
return null;
return;
}

$rankings = $this->getCollection($rankingForEngine['Result'], 'Rank');
Expand Down Expand Up @@ -309,7 +307,7 @@ private function transformBulkJobStatus($job)
if (array_has($job, 'SiteId')) {
$bulkJob->sites = collect(explode(',', $job['SiteId']))
->transform(function ($site, $key) {
return (int)$site;
return (int) $site;
});
}
$bulkJob->status = $job['Status'];
Expand Down
17 changes: 7 additions & 10 deletions src/Api/StatKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Illuminate\Support\Collection;
use SchulzeFelix\Stat\Objects\StatKeyword;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;
use SchulzeFelix\Stat\Objects\StatKeywordRanking;
use SchulzeFelix\Stat\Objects\StatKeywordStats;
use SchulzeFelix\Stat\Objects\StatKeywordRanking;
use SchulzeFelix\Stat\Objects\StatLocalSearchTrend;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;

class StatKeywords extends BaseStat
{
Expand All @@ -21,7 +21,7 @@ public function list($siteID) : Collection
$keywords = collect();

do {
$response = $this->performQuery('keywords/list', ['site_id' => $siteID, 'start' => $start, 'results' => 5000 ]);
$response = $this->performQuery('keywords/list', ['site_id' => $siteID, 'start' => $start, 'results' => 5000]);
$start += 5000;

if ($response['totalresults'] == 0) {
Expand All @@ -35,12 +35,11 @@ public function list($siteID) : Collection

$keywords = $keywords->merge($response['Result']);

if (!isset($response['nextpage'])) {
if (! isset($response['nextpage'])) {
break;
}
} while ($response['resultsreturned'] < $response['totalresults']);


$keywords = $keywords->transform(function ($keyword) {
return $this->transformListedKeyword($keyword);
});
Expand All @@ -67,6 +66,7 @@ public function create($siteID, $market, array $keywords, array $tags = null, $l
$keywords = array_map(function ($keyword) {
$keyword = str_replace(',', '\,', $keyword);
$keyword = rawurlencode($keyword);

return $keyword;
}, $keywords);
$arguments['keyword'] = implode(',', $keywords);
Expand All @@ -75,6 +75,7 @@ public function create($siteID, $market, array $keywords, array $tags = null, $l
$tags = array_map(function ($tag) {
$tag = str_replace(',', '-', $tag);
$tag = rawurlencode($tag);

return $tag;
}, $tags);

Expand Down Expand Up @@ -109,7 +110,7 @@ public function create($siteID, $market, array $keywords, array $tags = null, $l
*/
public function delete($id)
{
if (!is_array($id)) {
if (! is_array($id)) {
$id = [$id];
}

Expand All @@ -121,13 +122,11 @@ public function delete($id)
return collect($response['Result']['Id']);
}


return collect($response['Result'])->transform(function ($keywordID) {
return $keywordID['Id'];
});
}


/**
* @param $keyword
* @return StatKeyword
Expand All @@ -144,7 +143,6 @@ protected function transformCreatedKeyword($keyword)
]);
}


/**
* @param $keyword
* @return StatKeyword
Expand All @@ -158,7 +156,6 @@ protected function transformListedKeyword($keyword)
$modifiedKeyword->keyword_location = $keyword['KeywordLocation'];
$modifiedKeyword->keyword_device = $keyword['KeywordDevice'];


if ($keyword['KeywordTags'] == 'none') {
$modifiedKeyword->keyword_tags = collect();
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/Api/StatProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class StatProjects extends BaseStat
{

/**
* @return Collection
*/
Expand Down Expand Up @@ -74,6 +73,6 @@ public function delete($id)
{
$response = $this->performQuery('projects/delete', ['id' => $id]);

return (int)$response['Result']['Id'];
return (int) $response['Result']['Id'];
}
}
6 changes: 2 additions & 4 deletions src/Api/StatRankings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Carbon\Carbon;
use Illuminate\Support\Collection;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;
use SchulzeFelix\Stat\Objects\StatKeywordRanking;
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking;

class StatRankings extends BaseStat
{
Expand All @@ -30,13 +30,11 @@ public function list($keywordID, Carbon $fromDate, Carbon $toDate) : Collection
$rankings = $rankings->merge($response['Result']);
}


if (!isset($response['nextpage'])) {
if (! isset($response['nextpage'])) {
break;
}
} while ($response['resultsreturned'] < $response['totalresults']);


$rankings = $rankings->transform(function ($ranking, $key) {
return new StatKeywordRanking([
'date' => $ranking['date'],
Expand Down
1 change: 0 additions & 1 deletion src/Api/StatSerps.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class StatSerps extends BaseStat
{

/**
* @param $keywordID
* @param Carbon $date
Expand Down
Loading

0 comments on commit 14a6059

Please sign in to comment.