Skip to content

Commit

Permalink
feat: use jenssegers/model
Browse files Browse the repository at this point in the history
  • Loading branch information
jshah4517 committed May 24, 2024
1 parent d65418e commit 9258343
Show file tree
Hide file tree
Showing 133 changed files with 983 additions and 9,925 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^8.1",
"doctrine/cache": "^1.10",
"guzzlehttp/guzzle": "^7.0",
"illuminate/database": "^11.8",
"jenssegers/model": "^1.5",
"kevinrob/guzzle-cache-middleware": "^5.0",
"phpdocumentor/reflection-docblock": "^5.2",
"psr/http-message": "^1.0",
Expand Down
232 changes: 52 additions & 180 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 3 additions & 45 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\ApiClient\TicketApiClient;
use SupportPal\ApiClient\ApiClient\UserApiClient;
use SupportPal\ApiClient\Converter\ModelToArrayConverter;
use SupportPal\ApiClient\Factory\Collection\CollectionFactory;
use SupportPal\ApiClient\Factory\ModelCollectionFactory;
use Symfony\Component\Serializer\Encoder\DecoderInterface;

use function json_decode;

abstract class Api
{
Expand All @@ -20,53 +20,22 @@ abstract class Api
/** @var UserApiClient|SelfServiceApiClient|TicketApiClient|CoreApiClient|ApiClient */
protected $apiClient;

/** @var ModelToArrayConverter */
private $modelToArrayConverter;

/** @var string */
private $formatType;

/** @var ModelCollectionFactory */
private $modelCollectionFactory;

/** @var DecoderInterface */
private $decoder;

/** @var CollectionFactory */
private $collectionFactory;

public function __construct(
ModelToArrayConverter $modelToArrayConverter,
ModelCollectionFactory $modelCollectionFactory,
string $formatType,
DecoderInterface $decoder,
CollectionFactory $collectionFactory,
ApiClient $apiClient
) {
$this->modelToArrayConverter = $modelToArrayConverter;
$this->formatType = $formatType;
$this->modelCollectionFactory = $modelCollectionFactory;
$this->decoder = $decoder;
$this->collectionFactory = $collectionFactory;
$this->apiClient = $apiClient;
}

/**
* @inheritDoc
*/
protected function getModelToArrayConverter(): ModelToArrayConverter
{
return $this->modelToArrayConverter;
}

/**
* @inheritDoc
*/
protected function getFormatType(): string
{
return $this->formatType;
}

/**
* @inheritDoc
*/
Expand All @@ -75,24 +44,13 @@ protected function getModelCollectionFactory(): ModelCollectionFactory
return $this->modelCollectionFactory;
}

/**
* @inheritDoc
*/
protected function getDecoder(): DecoderInterface
{
return $this->decoder;
}

/**
* @param ResponseInterface $response
* @return array<mixed>
*/
protected function decodeBody(ResponseInterface $response): array
{
/** @var array<mixed> $body */
$body = $this->getDecoder()->decode((string) $response->getBody(), $this->getFormatType());

return $body;
return json_decode((string) $response->getBody(), true);
}

/**
Expand Down
Loading

0 comments on commit 9258343

Please sign in to comment.