Skip to content

Commit

Permalink
Refactoring: remove pagerfanta (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianaromagnoli committed Apr 6, 2020
1 parent bf7ff6d commit 8ed1c66
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 22 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"symfony/property-info": "^4.3",
"doctrine/annotations": "^1.8",
"ramsey/uuid": "^3.8",
"webgriffe/amp-elasticsearch": "dev-master",
"pagerfanta/pagerfanta": "^2.1"
"webgriffe/amp-elasticsearch": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Controller/FlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Promise;
use Webgriffe\Esb\Console\AmpElasticsearchUriSearchAdapter;
use Webgriffe\Esb\Console\AsyncPager;
use Webgriffe\Esb\Console\Pager\AmpElasticsearchUriSearchAdapter;
use Webgriffe\Esb\Console\Pager\AsyncPager;
use function Amp\call;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace Webgriffe\Esb\Console;
namespace Webgriffe\Esb\Console\Pager;

use Amp\Promise;
use Amp\Success;
use Webgriffe\AmpElasticsearch\Client;
use Webgriffe\Esb\Console\Pager\AsyncPagerAdapterInterface;
use function Amp\call;

class AmpElasticsearchUriSearchAdapter implements AsyncPagerAdapterInterface
final class AmpElasticsearchUriSearchAdapter implements AsyncPagerAdapterInterface
{
/**
* @var Client
Expand Down
31 changes: 16 additions & 15 deletions src/Console/AsyncPager.php → src/Console/Pager/AsyncPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

declare(strict_types=1);

namespace Webgriffe\Esb\Console;
namespace Webgriffe\Esb\Console\Pager;

use Amp\Promise;
use Pagerfanta\Exception\LessThan1CurrentPageException;
use Pagerfanta\Exception\LessThan1MaxPerPageException;
use Pagerfanta\Exception\LogicException;
use Pagerfanta\Exception\NotBooleanException;
use Pagerfanta\Exception\NotIntegerCurrentPageException;
use Pagerfanta\Exception\NotIntegerException;
use Pagerfanta\Exception\NotIntegerMaxPerPageException;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use function Amp\call;

/**
* @internal
*/
class AsyncPager
{
/**
Expand Down Expand Up @@ -296,7 +291,13 @@ private function normalizeOutOfRangeCurrentPage($currentPage)
return $this->getNbPages();
}

throw new OutOfRangeCurrentPageException(sprintf('Page "%d" does not exist. The currentPage must be inferior to "%d"', $currentPage, $this->getNbPages()));
throw new OutOfRangeCurrentPageException(
sprintf(
'Page "%d" does not exist. The currentPage must be inferior to "%d"',
$currentPage,
$this->getNbPages()
)
);
}

private function resetForCurrentPageChange()
Expand Down Expand Up @@ -428,12 +429,12 @@ public function hasPreviousPage()
*
* @return integer
*
* @throws LogicException If there is no previous page.
* @throws \LogicException If there is no previous page.
*/
public function getPreviousPage()
{
if (!$this->hasPreviousPage()) {
throw new LogicException('There is no previous page.');
throw new \LogicException('There is no previous page.');
}

return $this->currentPage - 1;
Expand All @@ -454,12 +455,12 @@ public function hasNextPage()
*
* @return integer
*
* @throws LogicException If there is no next page.
* @throws \LogicException If there is no next page.
*/
public function getNextPage()
{
if (!$this->hasNextPage()) {
throw new LogicException('There is no next page.');
throw new \LogicException('There is no next page.');
}

return $this->currentPage + 1;
Expand Down Expand Up @@ -538,7 +539,7 @@ public function getPageNumberForItemAtPosition($position)
}

if ($this->getNbResults() < $position) {
throw new OutOfBoundsException(sprintf(
throw new \OutOfBoundsException(sprintf(
'Item requested at position %d, but there are only %d items.',
$position,
$this->getNbResults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Webgriffe\Esb\Console;
namespace Webgriffe\Esb\Console\Pager;

use Amp\Promise;

Expand Down
7 changes: 7 additions & 0 deletions src/Console/Pager/LessThan1CurrentPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class LessThan1CurrentPageException extends NotValidCurrentPageException
{
}
7 changes: 7 additions & 0 deletions src/Console/Pager/LessThan1MaxPerPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class LessThan1MaxPerPageException extends NotValidMaxPerPageException
{
}
7 changes: 7 additions & 0 deletions src/Console/Pager/NotBooleanException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class NotBooleanException extends \InvalidArgumentException
{
}
8 changes: 8 additions & 0 deletions src/Console/Pager/NotIntegerCurrentPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class NotIntegerCurrentPageException extends NotValidCurrentPageException
{

}
7 changes: 7 additions & 0 deletions src/Console/Pager/NotIntegerException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class NotIntegerException extends \InvalidArgumentException
{
}
7 changes: 7 additions & 0 deletions src/Console/Pager/NotIntegerMaxPerPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class NotIntegerMaxPerPageException extends NotValidMaxPerPageException
{
}
10 changes: 10 additions & 0 deletions src/Console/Pager/NotValidCurrentPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

/**
* @internal
*/
class NotValidCurrentPageException extends \InvalidArgumentException
{
}
10 changes: 10 additions & 0 deletions src/Console/Pager/NotValidMaxPerPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

/**
* @internal
*/
class NotValidMaxPerPageException extends \InvalidArgumentException
{
}
7 changes: 7 additions & 0 deletions src/Console/Pager/OutOfRangeCurrentPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Webgriffe\Esb\Console\Pager;

final class OutOfRangeCurrentPageException extends NotValidCurrentPageException
{
}

0 comments on commit 8ed1c66

Please sign in to comment.