Skip to content

Commit

Permalink
Improve docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Jan 2, 2024
1 parent 9c1aa88 commit a835702
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Paginations/AnyPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AnyPagination extends Pagination
];

/**
* Determine whether the configuration matches this pagination.
* Determine whether this pagination matches the configuration.
*/
public function matches(): bool
{
Expand Down
36 changes: 18 additions & 18 deletions src/Sources/AnySource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
namespace Cerbero\LazyJsonPages\Sources;

use Cerbero\LazyJsonPages\Exceptions\UnsupportedSourceException;
use Generator;
use Psr\Http\Message\RequestInterface;

/**
* The aggregator of sources.
*/
class AnySource extends Source
{
/**
* @var class-string<Source>[]
*/
protected array $supportedSources = [
CustomSource::class,
// CustomSource::class,
Endpoint::class,
LaravelClientRequest::class,
LaravelClientResponse::class,
LaravelRequest::class,
Psr7Request::class,
SymfonyRequest::class,
// LaravelClientRequest::class,
// LaravelClientResponse::class,
// LaravelRequest::class,
// Psr7Request::class,
// SymfonyRequest::class,
];

/**
Expand All @@ -29,13 +31,16 @@ class AnySource extends Source
protected ?Source $matchingSource;

/**
* Determine whether the JSON source can be handled
* Determine whether this class can handle the source
*/
public function matches(): bool
{
return true;
}

/**
* Retrieve the HTTP request
*/
public function request(): RequestInterface
{
return $this->matchingSource()->request();
Expand All @@ -52,7 +57,9 @@ protected function matchingSource(): Source
return $this->matchingSource;
}

foreach ($this->sources() as $source) {
foreach ($this->supportedSources as $class) {
$source = new $class($this->source);

if ($source->matches()) {
return $this->matchingSource = $source;
}
Expand All @@ -62,17 +69,10 @@ protected function matchingSource(): Source
}

/**
* Retrieve all available sources
* Retrieve the HTTP response or part of it
*
* @return Generator<int, Source>
* @return ($key is string ? mixed : \Cerbero\LazyJsonPages\ValueObjects\Response)
*/
protected function sources(): Generator
{
foreach ($this->supportedSources as $source) {
yield new $source($this->source);
}
}

public function response(?string $key = null): mixed
{
return $this->matchingSource()->response($key);
Expand Down
11 changes: 11 additions & 0 deletions src/Sources/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ final public function __construct(
protected readonly mixed $source,
) {}

/**
* Determine whether this class can handle the source
*/
abstract public function matches(): bool;

/**
* Retrieve the HTTP request
*/
abstract public function request(): RequestInterface;

/**
* Retrieve the HTTP response or part of it
*
* @return ($key is string ? mixed : \Cerbero\LazyJsonPages\ValueObjects\Response)
*/
abstract public function response(?string $key = null): mixed;
}

0 comments on commit a835702

Please sign in to comment.