Skip to content

Commit

Permalink
Apply fixes from StyleCI (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Lichter <[email protected]>
  • Loading branch information
TheAlexLichter and manniL committed Sep 10, 2020
1 parent d6a3b16 commit 9a103a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
29 changes: 13 additions & 16 deletions src/NpmStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class NpmStats
/** @var string */
protected $baseUrl;

const LAST_DAY = "last-day";
const LAST_WEEK = "last-week";
const LAST_MONTH = "last-month";
const LAST_YEAR = "last-year";
const TOTAL = "total";
const LAST_DAY = 'last-day';
const LAST_WEEK = 'last-week';
const LAST_MONTH = 'last-month';
const LAST_YEAR = 'last-year';
const TOTAL = 'total';

/**
* @param \GuzzleHttp\Client $client
Expand All @@ -32,7 +32,7 @@ public function __construct(Client $client, $baseUrl = 'https://api.npmjs.org/do
* @param string $pointValue
* @return array
*/
private function getStatsByPoint($packageName, $pointValue = "last-day")
private function getStatsByPoint($packageName, $pointValue = 'last-day')
{
return $this->makeRequest("/point/{$pointValue}/{$packageName}");
}
Expand All @@ -42,7 +42,7 @@ private function getStatsByPoint($packageName, $pointValue = "last-day")
* @param string $rangeValue
* @return array
*/
private function getStatsByRange($packageName, $rangeValue = "last-day")
private function getStatsByRange($packageName, $rangeValue = 'last-day')
{
return $this->makeRequest("/range/{$rangeValue}/{$packageName}");
}
Expand All @@ -54,7 +54,7 @@ private function getStatsByRange($packageName, $rangeValue = "last-day")
* @return array
* @throws \Exception
*/
public function getStats($packageName, $period = "last-day", $asRange = false)
public function getStats($packageName, $period = 'last-day', $asRange = false)
{
if (empty($packageName)) {
throw new \Exception("Package name can't be empty");
Expand All @@ -69,7 +69,6 @@ public function getStats($packageName, $period = "last-day", $asRange = false)
return $this->getStatsByPoint($packageName, $period);
}


/**
* @param string $resource
* @param array $query
Expand All @@ -89,14 +88,12 @@ private function makeRequest($resource, array $query = [])
private function replaceSpecialPeriodsIfApplicable(&$period)
{
if ($period === self::TOTAL) {
$currentDate = (new \DateTime)->format("Y-m-d");
$currentDate = (new \DateTime)->format('Y-m-d');
$period = "2015-01-01:{$currentDate}";
} else if ($period === self::LAST_YEAR) {
$currentDate = (new \DateTime)->format("Y-m-d");
$beforeDate = (new \DateTime)->modify("-365 days")->format("Y-m-d");
} elseif ($period === self::LAST_YEAR) {
$currentDate = (new \DateTime)->format('Y-m-d');
$beforeDate = (new \DateTime)->modify('-365 days')->format('Y-m-d');
$period = "{$beforeDate}:{$currentDate}";
}

return;
}
}
}
17 changes: 8 additions & 9 deletions tests/NpmStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NpmStatsTest extends TestCase
/** @var \Developmint\NpmStats\NpmStats */
protected $npmStats;

public function setUp() : void
public function setUp(): void
{
$client = new Client();

Expand All @@ -30,7 +30,7 @@ public function testItCanRetrievePointStats()
$this->assertArrayHasKey('downloads', $result);
$this->assertArrayHasKey('start', $result);
$this->assertArrayHasKey('end', $result);
$this->assertEquals($packageName, $result["package"]);
$this->assertEquals($packageName, $result['package']);
}

public function testItCanRetrievePointBulkStats()
Expand All @@ -51,10 +51,10 @@ public function testItCanRetrieveRangeStats()

$this->assertArrayHasKey('start', $result);
$this->assertArrayHasKey('end', $result);
$this->assertEquals($packageName, $result["package"]);
$this->assertEquals($packageName, $result['package']);
$this->assertArrayHasKey('downloads', $result);
$this->assertArrayHasKey('downloads', $result["downloads"][0]);
$this->assertArrayHasKey('day', $result["downloads"][0]);
$this->assertArrayHasKey('downloads', $result['downloads'][0]);
$this->assertArrayHasKey('day', $result['downloads'][0]);
}

public function testItCanRetrieveYearlyStats()
Expand All @@ -63,11 +63,10 @@ public function testItCanRetrieveYearlyStats()
$result = $this->npmStats->getStats($packageName, NpmStats::LAST_YEAR);
$this->assertArrayHasKey('start', $result);
$this->assertArrayHasKey('end', $result);
$this->assertEquals((new \DateTime)->modify("-365 days")->format("Y-m-d"), $result["start"]);
$this->assertEquals((new \DateTime)->modify('-365 days')->format('Y-m-d'), $result['start']);

$this->assertEquals($packageName, $result["package"]);
$this->assertEquals($packageName, $result['package']);
$this->assertArrayHasKey('downloads', $result);

}

public function testItCanRetrieveYearlyStatsForBulk()
Expand All @@ -84,7 +83,7 @@ public function testItCanRetrieveAllTimeStats()
$result = $this->npmStats->getStats($packageName, NpmStats::TOTAL);
$this->assertArrayHasKey('start', $result);
$this->assertArrayHasKey('end', $result);
$this->assertEquals($packageName, $result["package"]);
$this->assertEquals($packageName, $result['package']);
$this->assertArrayHasKey('downloads', $result);
}

Expand Down

0 comments on commit 9a103a2

Please sign in to comment.