Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ public function __construct(
* @var array<mixed>|null
*/
public readonly ?array $links = null,
) {
}
) {}
}
5 changes: 2 additions & 3 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class Handler implements ExceptionHandlerContract
public function __construct(
protected ExceptionHandlerContract $defaultHandler,
protected Repository $config
) {
}
) {}

/**
* Render an exception into an HTTP response.
Expand Down Expand Up @@ -49,7 +48,7 @@ public function render($request, Throwable $e): Response

protected function renderValidationException(ValidationException $e, Request $request): Response
{
$errors = new Collection();
$errors = new Collection;

foreach ($e->errors() as $field => $validationErrors) {
foreach ($validationErrors as $validationError) {
Expand Down
3 changes: 1 addition & 2 deletions src/Filters/ScopeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public function __construct(
protected ?array $options = null,
protected mixed $example = null,
protected ?string $scopeName = null,
) {
}
) {}

/**
* @return array<QueryParameter>
Expand Down
3 changes: 1 addition & 2 deletions src/Includes/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Relation implements Contracts\Relation
{
public function __construct(
protected string $name
) {
}
) {}

public function allowedInclude(): string
{
Expand Down
3 changes: 1 addition & 2 deletions src/Middleware/RenderJsonApiExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class RenderJsonApiExceptions
public function __construct(
protected Application $app,
protected Repository $config,
) {
}
) {}

/**
* Handle an incoming request.
Expand Down
16 changes: 8 additions & 8 deletions src/Resources/ErrorResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function __construct(Error $resource)
public function toArray($request): array
{
return [
'id' => $this->resource->id ?? new MissingValue(),
'status' => $this->resource->status ?? new MissingValue(),
'code' => $this->resource->code ?? new MissingValue(),
'title' => $this->resource->title ?? new MissingValue(),
'detail' => $this->resource->detail ?? new MissingValue(),
'source' => $this->resource->source ?? new MissingValue(),
'meta' => $this->resource->meta ?? new MissingValue(),
'links' => $this->resource->links ?? new MissingValue(),
'id' => $this->resource->id ?? new MissingValue,
'status' => $this->resource->status ?? new MissingValue,
'code' => $this->resource->code ?? new MissingValue,
'title' => $this->resource->title ?? new MissingValue,
'detail' => $this->resource->detail ?? new MissingValue,
'source' => $this->resource->source ?? new MissingValue,
'meta' => $this->resource->meta ?? new MissingValue,
'links' => $this->resource->links ?? new MissingValue,
];
}
}
2 changes: 1 addition & 1 deletion src/Resources/IncludesBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IncludesBag implements Arrayable

public function __construct()
{
$this->items = new Collection();
$this->items = new Collection;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/IncludesGathering.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait IncludesGathering

public function initializeIncludesBag(): void
{
$this->included = new IncludesBag();
$this->included = new IncludesBag;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/JsonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ final public function toArray($request): array
'id' => $this->getId(),
'type' => $this->getType(),
'attributes' => $this->getAttributes($request),
'relationships' => $this->discoverRelations($request) ?: new MissingValue(),
'links' => $this->getLinks($request) ?: new MissingValue(),
'relationships' => $this->discoverRelations($request) ?: new MissingValue,
'links' => $this->getLinks($request) ?: new MissingValue,
];
}

Expand Down
4 changes: 1 addition & 3 deletions src/Resources/RelationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class RelationType

public const ONE = 'one';

private function __construct()
{
}
private function __construct() {}
}
7 changes: 4 additions & 3 deletions src/Sorts/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Intermax\LaravelJsonApi\Sorts;

use Illuminate\Support\Str;
use Intermax\LaravelOpenApi\Generator\Parameters\QueryParameter;
use Spatie\QueryBuilder\AllowedSort;

Expand All @@ -12,12 +13,12 @@ class Sort implements Contracts\Sort
public function __construct(
protected string $name,
protected ?string $example = null,
) {
}
protected ?string $internalName = null,
) {}

public function allowedSort(): AllowedSort
{
return AllowedSort::field($this->name);
return AllowedSort::field($this->name, $this->internalName ?? Str::snake($this->name));
}

public function parameters(): array
Expand Down
4 changes: 2 additions & 2 deletions tests/Requests/CollectionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CollectionRequestTest extends TestCase
#[Test]
public function it_outputs_parameters(): void
{
$request = new class() extends CollectionRequest
$request = new class extends CollectionRequest
{
public function filters(): array
{
Expand Down Expand Up @@ -46,7 +46,7 @@ public function filters(): array
#[Test]
public function it_outputs_includes_and_sorts_and_filters_as_parameters()
{
$request = new class() extends CollectionRequest
$request = new class extends CollectionRequest
{
public function includes(): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Requests/MutationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MutationRequestTest extends TestCase
#[Test]
public function it_merges_attributes_and_relationship_rules_into_json_api_rules(): void
{
$request = new class() extends MutationRequest
$request = new class extends MutationRequest
{
public function type(): string
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public function relationshipRules(): array
#[Test]
public function it_rejects_the_request_if_the_json_api_content_type_is_not_used(): void
{
$formRequest = new class() extends MutationRequest
$formRequest = new class extends MutationRequest
{
public function type(): string
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Requests/QueryResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getPackageProviders($app)
#[Test]
public function it_adds_includes_to_the_query(): void
{
$request = new class() extends CollectionRequest
$request = new class extends CollectionRequest
{
public function includes(): array
{
Expand All @@ -48,7 +48,7 @@ public function includes(): array
#[Test]
public function it_adds_a_sort_to_the_query(): void
{
$request = new class() extends CollectionRequest
$request = new class extends CollectionRequest
{
public function sorts(): array
{
Expand All @@ -72,7 +72,7 @@ public function sorts(): array
#[Test]
public function it_adds_a_filter_to_the_query(): void
{
$request = new class() extends CollectionRequest
$request = new class extends CollectionRequest
{
public function filters(): array
{
Expand Down