Skip to content

Commit

Permalink
style: apply automated php-cs-fixer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Aug 22, 2024
1 parent 7380141 commit 4791f81
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 72 deletions.
1 change: 0 additions & 1 deletion src/Abstracts/Tests/PhpUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ protected function refreshTestDatabase(): void
$this->beginDatabaseTransaction();
}
}

3 changes: 2 additions & 1 deletion src/Contracts/HasResourceKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Apiato\Core\Contracts;

interface HasResourceKey {
interface HasResourceKey
{
public function getResourceKey(): string;
}
30 changes: 15 additions & 15 deletions src/Generator/Commands/ContainerApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,21 @@ public function getUserInputs(): array|null
}

$generateComposerFile = [
'path-parameters' => [
'section-name' => $this->sectionName,
'container-name' => $this->containerName,
],
'stub-parameters' => [
'_section-name' => $_sectionName,
'section-name' => $this->sectionName,
'_container-name' => $_containerName,
'container-name' => $containerName,
'class-name' => $this->fileName,
],
'file-parameters' => [
'file-name' => $this->fileName,
],
];
'path-parameters' => [
'section-name' => $this->sectionName,
'container-name' => $this->containerName,
],
'stub-parameters' => [
'_section-name' => $_sectionName,
'section-name' => $this->sectionName,
'_container-name' => $_containerName,
'container-name' => $containerName,
'class-name' => $this->fileName,
],
'file-parameters' => [
'file-name' => $this->fileName,
],
];

if (!$this->option('maincalled')) {
$this->printInfoMessage('Generating Composer File');
Expand Down
8 changes: 4 additions & 4 deletions src/Macros/Collection/ContainsDecodedHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
use Illuminate\Support\Collection;
use Vinkla\Hashids\Facades\Hashids;

class ContainsDecodedHash {
class ContainsDecodedHash
{
public function __invoke(): callable
{
return
/**
* Decodes a hashed value and checks if the decoded value exists in the collection under the specified key.
*/
function (string $hashedValue, string $key = 'id'): bool
{
/** @var Collection $this */
function (string $hashedValue, string $key = 'id'): bool {
/* @var Collection $this */
return $this->contains($key, Hashids::decode($hashedValue)[0]);
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/Macros/Config/UnsetKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Illuminate\Config\Repository;
use Illuminate\Support\Arr;

class UnsetKey {
class UnsetKey
{
public function __invoke(): callable
{
return function (array|string|int|float $key): void {
/** @var Repository $this */
/* @var Repository $this */
Arr::forget($this->items, $key);
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/Macros/Response/Accepted.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Apiato\Core\Macros\Response;

use Apiato\Core\Abstracts\Transformers\Transformer;
use Illuminate\Http\JsonResponse;
use Apiato\Core\Services\Response;
use Illuminate\Http\JsonResponse;

class Accepted {
class Accepted
{
public function __invoke(): callable
{
return
Expand All @@ -18,6 +19,7 @@ function (): JsonResponse {
if (is_null($this->getTransformer())) {
$this->transformWith(Transformer::empty());
}

return $this->respond(202);
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/Macros/Response/CreateFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use League\Fractal\Serializer\SerializerAbstract;
use League\Fractal\TransformerAbstract;

class CreateFrom {
class CreateFrom
{
public function __invoke(): callable
{
return
Expand Down
6 changes: 4 additions & 2 deletions src/Macros/Response/Created.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Apiato\Core\Macros\Response;

use Apiato\Core\Abstracts\Transformers\Transformer;
use Illuminate\Http\JsonResponse;
use Apiato\Core\Services\Response;
use Illuminate\Http\JsonResponse;

class Created {
class Created
{
public function __invoke(): callable
{
return
Expand All @@ -18,6 +19,7 @@ function (): JsonResponse {
if (is_null($this->getTransformer())) {
$this->transformWith(Transformer::empty());
}

return $this->respond(201);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Response/GetTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GetTransformer
public function __invoke(): callable
{
return function (): string|callable|TransformerAbstract|null {
/** @var Response $this */
/* @var Response $this */
// The warning is false positive. We will be in the context of Fractal class when this is called.
return $this->transformer;
};
Expand Down
8 changes: 5 additions & 3 deletions src/Macros/Response/NoContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
namespace Apiato\Core\Macros\Response;

use Apiato\Core\Abstracts\Transformers\Transformer;
use Illuminate\Http\JsonResponse;
use Apiato\Core\Services\Response;
use Illuminate\Http\JsonResponse;

class NoContent {
class NoContent
{
public function __invoke(): callable
{
return
/**
* Returns a 204 No Content response.
*/
function (): JsonResponse {
/** @var Response $this */
/* @var Response $this */
$this->transformWith(Transformer::empty());

return $this->respond(204);
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/Macros/Response/Ok.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Apiato\Core\Macros\Response;

use Apiato\Core\Abstracts\Transformers\Transformer;
use Illuminate\Http\JsonResponse;
use Apiato\Core\Services\Response;
use Illuminate\Http\JsonResponse;

class Ok {
class Ok
{
public function __invoke(): callable
{
return
Expand All @@ -18,6 +19,7 @@ function (): JsonResponse {
if (is_null($this->getTransformer())) {
$this->transformWith(Transformer::empty());
}

return $this->respond(200);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Apiato\Core\Macros\Collection\ContainsDecodedHash;
use Illuminate\Support\Collection;

final class CollectionMacroServiceProvider extends AbstractMainServiceProvider {
final class CollectionMacroServiceProvider extends AbstractMainServiceProvider
{
public function boot(): void
{
parent::boot();

Collection::make($this->macros())
->reject(static fn ($class, $macro) => Collection::hasMacro($macro))
->each(static fn ($class, $macro) => Collection::macro($macro, app($class)()));
->each(static fn ($class, $macro) => Collection::macro($macro, app($class)()));
}

private function macros(): array
Expand Down
7 changes: 4 additions & 3 deletions src/Providers/MacroProviders/ConfigMacroServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace Apiato\Core\Providers\MacroProviders;

use Apiato\Core\Macros\Config\UnsetKey;
use Apiato\Core\Abstracts\Providers\MainServiceProvider as AbstractMainServiceProvider;
use Apiato\Core\Macros\Config\UnsetKey;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;

final class ConfigMacroServiceProvider extends AbstractMainServiceProvider {
final class ConfigMacroServiceProvider extends AbstractMainServiceProvider
{
public function boot(): void
{
parent::boot();

Collection::make($this->macros())
->reject(static fn ($class, $macro) => Config::hasMacro($macro))
->each(static fn ($class, $macro) => Config::macro($macro, app($class)()));
->each(static fn ($class, $macro) => Config::macro($macro, app($class)()));
}

private function macros(): array
Expand Down
11 changes: 6 additions & 5 deletions src/Providers/MacroProviders/ResponseMacroServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

namespace Apiato\Core\Providers\MacroProviders;

use Apiato\Core\Macros\Response\GetRequestedIncludes;
use Apiato\Core\Services\Response;
use Apiato\Core\Abstracts\Providers\MainServiceProvider as AbstractMainServiceProvider;
use Apiato\Core\Macros\Response\Accepted;
use Apiato\Core\Macros\Response\Created;
use Apiato\Core\Macros\Response\CreateFrom;
use Apiato\Core\Macros\Response\GetRequestedIncludes;
use Apiato\Core\Macros\Response\GetTransformer;
use Apiato\Core\Macros\Response\NoContent;
use Apiato\Core\Macros\Response\Ok;
use Apiato\Core\Abstracts\Providers\MainServiceProvider as AbstractMainServiceProvider;
use Apiato\Core\Services\Response;
use Illuminate\Support\Collection;

final class ResponseMacroServiceProvider extends AbstractMainServiceProvider {
final class ResponseMacroServiceProvider extends AbstractMainServiceProvider
{
public function boot(): void
{
parent::boot();

Collection::make($this->macros())
->reject(static fn ($class, $macro) => Response::hasMacro($macro))
->each(static fn ($class, $macro) => Response::macro($macro, app($class)()));
->each(static fn ($class, $macro) => Response::macro($macro, app($class)()));
}

private function macros(): array
Expand Down
10 changes: 5 additions & 5 deletions src/Services/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Spatie\Fractal\Fractal as SpatieFractal;

/**
* A wrapper class for Spatie\Fractal\Fractal
* A wrapper class for Spatie\Fractal\Fractal.
*
* @see \Spatie\Fractal\Fractal
* @see SpatieFractal
*/
class Response extends SpatieFractal
{
Expand All @@ -27,18 +27,18 @@ public function createData(): Scope
private function setAvailableIncludesMeta(): void
{
$this->addMeta([
'include' => $this->getTransformerAvailableIncludes()
'include' => $this->getTransformerAvailableIncludes(),
]);
}

private function getTransformerAvailableIncludes(): array
{
if(is_null($this->transformer) || is_callable($this->transformer)) {
if (is_null($this->transformer) || is_callable($this->transformer)) {
return [];
}

if (is_string($this->transformer)) {
return (new $this->transformer)->getAvailableIncludes();
return (new $this->transformer())->getAvailableIncludes();
}

return $this->transformer->getAvailableIncludes();
Expand Down
7 changes: 4 additions & 3 deletions src/Traits/CanEagerLoadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;

trait CanEagerLoadTrait {
trait CanEagerLoadTrait
{
/**
* Eager load relations if requested by the client via ?include=... in the URL.
* This is a workaround for incompatible third-party packages. (Fractal, L5Repo)
* This is a workaround for incompatible third-party packages. (Fractal, L5Repo).
*
* @link https://apiato.atlassian.net/browse/API-905
* @see https://apiato.atlassian.net/browse/API-905
*/
protected function eagerLoadRequestedRelations(): void
{
Expand Down
1 change: 0 additions & 1 deletion tests/Infrastructure/Doubles/BookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Apiato\Core\Tests\Infrastructure\Doubles;


use Apiato\Core\Abstracts\Factories\Factory as CoreFactory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
return new class extends Migration {
public function up(): void
{
Schema::table('users', static function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
return new class extends Migration {
public function up(): void
{
Schema::create('books', function (Blueprint $table) {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function setUp(): void
{
parent::setUp();

foreach((app(ApiatoServiceProvider::class, ['app' => $this->app]))->serviceProviders as $provider) {
foreach ((app(ApiatoServiceProvider::class, ['app' => $this->app]))->serviceProviders as $provider) {
App::register($provider);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Abstracts/Repositories/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testEagerLoadSingleRelationRequestedViaRequest(string $includes,
request()->offsetSet(config('apiato.requests.params.include', 'include'), $includes);
$parent = UserFactory::new()->has(
UserFactory::new()->count(3),
'children'
'children',
)->count(3)->create();
$repository = app(UserRepository::class);

Expand Down
Loading

0 comments on commit 4791f81

Please sign in to comment.