Skip to content

Commit

Permalink
fix: comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Oct 11, 2023
1 parent 542b34e commit 5b3f210
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Support/Facades/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
/**
* @method static JsonResponse response($data = null, string $message = '', int $code = 200, $errors = null, array $headers = [], int $option = 0, string $from = 'success')
* @method static array data($data, ?string $message, int $code, $errors = null)
* @method static array paginator(AbstractPaginator|AbstractCursorPaginator $resource, $transformer = null, $resourceName = null)
* @method static array resourceCollection(ResourceCollection $collection, $transformer = null, $resourceName = null)
* @method static array jsonResource(JsonResource $resource, $transformer = null, $resourceName = null)
* @method static array paginator(AbstractPaginator|AbstractCursorPaginator $resource)
* @method static array resourceCollection(ResourceCollection $collection)
* @method static array jsonResource(JsonResource $resource)
*
* @see \Jiannei\Response\Laravel\Support\Format
*/
Expand Down
19 changes: 10 additions & 9 deletions src/Support/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource):
{
return [
'data' => $resource->toArray()['data'],
'meta' => $this->formatMeta($resource),
'meta' => $this->formatMeta($resource)
];
}

Expand All @@ -96,8 +96,8 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource):
public function resourceCollection(ResourceCollection $collection): array
{
return array_filter([
'data' => $collection->toArray(request()),
'meta' => $this->formatMeta($collection->resource),
'data' => $collection->resolve(),
'meta' => $this->formatMeta($collection->resource)
]);
}

Expand All @@ -109,7 +109,7 @@ public function resourceCollection(ResourceCollection $collection): array
*/
public function jsonResource(JsonResource $resource): array
{
return value($this->formatJsonResource(), $resource);
return value($this->formatJsonResource(),$resource);
}

/**
Expand All @@ -121,7 +121,7 @@ public function jsonResource(JsonResource $resource): array
*/
protected function formatMessage(int $code, ?string $message): ?string
{
if (! $message && class_exists($enumClass = Config::get('response.enum'))) {
if (!$message && class_exists($enumClass = Config::get('response.enum'))) {
$message = $enumClass::fromValue($code)->description;
}

Expand Down Expand Up @@ -175,8 +175,9 @@ protected function formatJsonResource(): \Closure
* Format paginator data.
*
* @param $collection
* @return array
*/
protected function formatMeta($collection)
protected function formatMeta($collection): array
{
return match (true) {
$collection instanceof CursorPaginator => [
Expand All @@ -185,7 +186,7 @@ protected function formatMeta($collection)
'prev' => $collection->previousCursor()?->encode(),
'next' => $collection->nextCursor()?->encode(),
'count' => count($collection->items()),
],
]
],
$collection instanceof LengthAwarePaginator => [
'pagination' => [
Expand Down Expand Up @@ -226,7 +227,7 @@ protected function formatDataFields(array $data): array
$formatConfig = \config('response.format.config', []);

foreach ($formatConfig as $key => $config) {
if (! Arr::has($data, $key)) {
if (!Arr::has($data, $key)) {
continue;
}

Expand All @@ -239,7 +240,7 @@ protected function formatDataFields(array $data): array
$key = $alias;
}

if (! $show) {
if (!$show) {
$data = Arr::except($data, $key);
}
}
Expand Down

0 comments on commit 5b3f210

Please sign in to comment.