Skip to content

Commit

Permalink
Merge 6749dc4 into ed644e1
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jul 31, 2019
2 parents ed644e1 + 6749dc4 commit db80a99
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 63 deletions.
7 changes: 4 additions & 3 deletions phpstan.neon
@@ -1,9 +1,10 @@
includes:
- vendor-bin/phpstan/vendor/jangregor/phpstan-prophecy/src/extension.neon

parameters:
autoload_files:
- vendor-bin/test/vendor/autoload.php

ignoreErrors:
# PHPUnit
-
message: '#Property .*::\$.* has no typehint specified.#'
path: tests/

6 changes: 3 additions & 3 deletions src/Crawler/AbstractCrawler.php
Expand Up @@ -42,7 +42,7 @@ public function __construct(ConnectionInterface $connection)
*/
final protected function crawl(string $url, array $params = []): ?Crawler
{
if ($content = $this->connection->getPageBody($url, $params)) {
if (null !== $content = $this->connection->getPageBody($url, $params)) {
return new Crawler($content);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ final protected function parseUrl(Crawler $node, string $attr = 'href'): ?string
return null;
}

if ($url = $node->attr($attr)) {
if (null !== $url = $node->attr($attr)) {
return preg_replace('/^\//', static::URL_PREFIX.'/', $url);
}

Expand All @@ -129,7 +129,7 @@ final protected function parseImage(Crawler $node): ?Image
{
$src = $this->parseUrl($node, 'src');

if (!$src) {
if (null === $src) {
return null;
}

Expand Down
18 changes: 7 additions & 11 deletions src/Crawler/ArtistEventCrawler.php
Expand Up @@ -69,26 +69,22 @@ public function getYearCount(string $artist, ?int $year, int $page = 1): int
$perPage = $this->countListEvents($node);
$pages = $this->countListPages($node);

if ($pages) {
$node = $this->crawlUrl($artist, $year, $pages);
$node = $this->crawlUrl($artist, $year, $pages);

if (null === $node) {
return $perPage;
}

$count = $this->countListEvents($node);

return ($pages - 1) * $perPage + $count;
if (null === $node) {
return $perPage;
}

return $perPage;
$count = $this->countListEvents($node);

return ($pages - 1) * $perPage + $count;
}

private function countListPages(Crawler $node): int
{
$pagination = $this->parseString($node->filter('.pagination .pagination-page')->last());

return $pagination ? (int) preg_replace('/.* of /', '', $pagination) : 1;
return null !== $pagination ? (int) preg_replace('/.* of /', '', $pagination) : 1;
}

private function countListEvents(Crawler $node): int
Expand Down
2 changes: 1 addition & 1 deletion src/Crawler/EventInfoCrawler.php
Expand Up @@ -57,7 +57,7 @@ private function readArtists(Crawler $node): array
return new Artist(
$this->parseString($node->filter('.grid-items-item-main-text')) ?? '',
null,
$image ? [$image] : [],
null !== $image ? [$image] : [],
$this->parseUrl($node->filter('.grid-items-item-main-text a'))
);
});
Expand Down
18 changes: 7 additions & 11 deletions src/Crawler/UserEventCrawler.php
Expand Up @@ -71,26 +71,22 @@ public function getYearCount(string $username, ?int $year, int $page = 1): int
$perPage = $this->countListEvents($node);
$pages = $this->countListPages($node);

if ($pages) {
$node = $this->crawlUrl($username, $year, $pages);
$node = $this->crawlUrl($username, $year, $pages);

if (null === $node) {
return $perPage;
}

$count = $this->countListEvents($node);

return ($pages - 1) * $perPage + $count;
if (null === $node) {
return $perPage;
}

return $perPage;
$count = $this->countListEvents($node);

return ($pages - 1) * $perPage + $count;
}

private function countListPages(Crawler $node): int
{
$pagination = $this->parseString($node->filter('.pagination .pages'));

return $pagination ? (int) preg_replace('/.* of /', '', $pagination) : 1;
return null !== $pagination ? (int) preg_replace('/.* of /', '', $pagination) : 1;
}

private function countListEvents(Crawler $node): int
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/RangeFilter.php
Expand Up @@ -32,8 +32,8 @@ public function __construct(?DateTime $start, ?DateTime $end)
public function getQuery(string $startKey, string $endKey): array
{
return [
$startKey => $this->start ? $this->start->getTimestamp() : null,
$endKey => $this->end ? $this->end->getTimestamp() : null,
$startKey => null !== $this->start ? $this->start->getTimestamp() : null,
$endKey => null !== $this->end ? $this->end->getTimestamp() : null,
];
}
}
7 changes: 6 additions & 1 deletion tests/Filter/RangeFilterTest.php
Expand Up @@ -17,7 +17,12 @@ final class RangeFilterTest extends TestCase
{
public function testItIsInstantiable(): void
{
static::assertNotNull(new RangeFilter(null, null));
$filter = new RangeFilter(null, null);

static::assertSame([
'foo' => null,
'bar' => null,
], $filter->getQuery('foo', 'bar'));
}

public function testGetQuery(): void
Expand Down
9 changes: 1 addition & 8 deletions tests/Service/AuthServiceTest.php
Expand Up @@ -17,18 +17,11 @@ final class AuthServiceTest extends TestCase
{
private $client;

protected function setUp()
protected function setUp(): void
{
$this->client = $this->prophesize(ApiClientInterface::class);
}

public function testItIsInstantiable(): void
{
$service = new AuthService($this->client->reveal());

static::assertNotNull($service);
}

public function testCreateSession(): void
{
$this->client->signedCall('auth.getSession', [
Expand Down
9 changes: 1 addition & 8 deletions tests/Service/GeoServiceTest.php
Expand Up @@ -17,18 +17,11 @@ final class GeoServiceTest extends TestCase
{
private $client;

protected function setUp()
protected function setUp(): void
{
$this->client = $this->prophesize(ApiClientInterface::class);
}

public function testItIsInstantiable(): void
{
$service = new GeoService($this->client->reveal());

static::assertNotNull($service);
}

public function testGetTopArtists(): void
{
$rawResponse = <<<'EOD'
Expand Down
9 changes: 1 addition & 8 deletions tests/Service/LibraryServiceTest.php
Expand Up @@ -17,18 +17,11 @@ final class LibraryServiceTest extends TestCase
{
private $client;

protected function setUp()
protected function setUp(): void
{
$this->client = $this->prophesize(ApiClientInterface::class);
}

public function testItIsInstantiable(): void
{
$service = new LibraryService($this->client->reveal());

static::assertNotNull($service);
}

public function testGetArtists(): void
{
$rawResponse = <<<'EOD'
Expand Down
6 changes: 0 additions & 6 deletions tests/Session/SessionTest.php
Expand Up @@ -10,16 +10,10 @@
namespace Core23\LastFm\Tests\Session;

use Core23\LastFm\Session\Session;
use Core23\LastFm\Session\SessionInterface;
use PHPUnit\Framework\TestCase;

final class SessionTest extends TestCase
{
public function testItIsInstantiable(): void
{
static::assertInstanceOf(SessionInterface::class, new Session('Username', 'key'));
}

public function testGetName(): void
{
$session = new Session('Username', 'key');
Expand Down
3 changes: 2 additions & 1 deletion vendor-bin/phpstan/composer.json
Expand Up @@ -4,7 +4,8 @@
"jangregor/phpstan-prophecy": "^0.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11"
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11"
},
"conflict": {
"phpunit/phpunit": ">=8.0"
Expand Down

0 comments on commit db80a99

Please sign in to comment.