From 64a2e64cdf4f235f03ac2411f8b89dd4a03ca9a8 Mon Sep 17 00:00:00 2001 From: GeorgeFourkas Date: Fri, 25 Aug 2023 01:42:05 +0000 Subject: [PATCH] Fix styling --- src/Constants.php | 10 +++--- src/CreateMany.php | 6 ++-- .../FileUrlDatabaseColumnIndexNotPresent.php | 2 +- src/FileHandler.php | 1 - src/Http/Middleware/ModelSearch.php | 2 +- src/Interfaces/FileManipulation.php | 1 - src/ManyToManyRelationshipHandler.php | 23 ------------ src/ModelResolver.php | 4 +-- src/Traits/HasModelRelationships.php | 4 +-- .../CreateModelWithRelatedTest.php | 35 +++++++++---------- 10 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/Constants.php b/src/Constants.php index 2f1a163..ad94e38 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -30,11 +30,11 @@ class Constants const DELETE_METHOD_NAME = 'DELETE'; -// const HAS_ONE = "HasOne"; -// const HAS_MANY = "HasMany"; -// const MORPH_ONE = "MorphOne"; -// const BELONGS_TO = "BelongsTo"; -// const BELONGS_TO_MANY = "BelongsToMany"; + // const HAS_ONE = "HasOne"; + // const HAS_MANY = "HasMany"; + // const MORPH_ONE = "MorphOne"; + // const BELONGS_TO = "BelongsTo"; + // const BELONGS_TO_MANY = "BelongsToMany"; public const IS_ELIGIBLE_FOR_ATTACH = [ self::BELONGS_TO_MANY, diff --git a/src/CreateMany.php b/src/CreateMany.php index ecf1974..8d53e9a 100644 --- a/src/CreateMany.php +++ b/src/CreateMany.php @@ -132,9 +132,9 @@ protected function saveRelatedModel(Model $created, array $values) $created->{$this->related->getFunctionName()}() ->create($values); } else { -// $created->{$this->related -// ->getFunctionName()}() -// ->createMany($values); + // $created->{$this->related + // ->getFunctionName()}() + // ->createMany($values); foreach ($values as $key => $value) { $created ->{$this->related->getFunctionName()}() diff --git a/src/Exceptions/FileUrlDatabaseColumnIndexNotPresent.php b/src/Exceptions/FileUrlDatabaseColumnIndexNotPresent.php index 32aa87a..7d83f18 100644 --- a/src/Exceptions/FileUrlDatabaseColumnIndexNotPresent.php +++ b/src/Exceptions/FileUrlDatabaseColumnIndexNotPresent.php @@ -11,7 +11,7 @@ class FileUrlDatabaseColumnIndexNotPresent extends \Exception use HasDevOrTestingResponse; - public function __construct(string $columnUrl, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(string $columnUrl, string $message = '', int $code = 0, Throwable $previous = null) { $this->columnUrl = $columnUrl; parent::__construct($message, $code, $previous); diff --git a/src/FileHandler.php b/src/FileHandler.php index 72020f1..6f58075 100644 --- a/src/FileHandler.php +++ b/src/FileHandler.php @@ -22,7 +22,6 @@ class FileHandler /** * @param UploadedFile|array $files * @param Request $request - * @param Model $model * @return array */ public function __construct(Model $model, string $urlColumn) diff --git a/src/Http/Middleware/ModelSearch.php b/src/Http/Middleware/ModelSearch.php index 17c868d..05ea9e6 100644 --- a/src/Http/Middleware/ModelSearch.php +++ b/src/Http/Middleware/ModelSearch.php @@ -48,7 +48,7 @@ public function handle(Request $request, Closure $next) /** * @throws \ReflectionException */ - protected function getRelationshipsReturnType($class, $method): string|null + protected function getRelationshipsReturnType($class, $method): ?string { $reflection = new \ReflectionMethod($class, $method); diff --git a/src/Interfaces/FileManipulation.php b/src/Interfaces/FileManipulation.php index f74d6fb..0e5e47c 100644 --- a/src/Interfaces/FileManipulation.php +++ b/src/Interfaces/FileManipulation.php @@ -7,7 +7,6 @@ interface FileManipulation { /** - * @param UploadedFile $file * @return array */ public function setAdditionalFileData(UploadedFile $file); diff --git a/src/ManyToManyRelationshipHandler.php b/src/ManyToManyRelationshipHandler.php index a342f72..f7e840f 100644 --- a/src/ManyToManyRelationshipHandler.php +++ b/src/ManyToManyRelationshipHandler.php @@ -12,36 +12,20 @@ class ManyToManyRelationshipHandler { - /** - * @var array|bool - */ protected array|bool $relationExists; - /** - * @var array - */ protected array $relations; - /** - * @var Request - */ protected Request $request; - /** - * @var Model - */ protected Model $model; - /** - * @var int - */ private int $modelId; use HasResponse; use HasPivotKeys; /** - * @param Request $aRequest * @return $this */ public function setRequest(Request $aRequest): static @@ -54,7 +38,6 @@ public function setRequest(Request $aRequest): static } /** - * @param Model $aModel * @return $this */ public function setModelClass(Model $aModel): static @@ -65,7 +48,6 @@ public function setModelClass(Model $aModel): static } /** - * @param $id * @return $this */ public function setModelID($id): static @@ -75,10 +57,6 @@ public function setModelID($id): static return $this; } - /** - * @param array $someRelations - * @return void - */ protected function setModelRelations(array $someRelations): void { $this->relations = $someRelations; @@ -111,7 +89,6 @@ public function attachTo(): static } /** - * @param Model $model * @return $this */ public function detachFrom(Model $model): static diff --git a/src/ModelResolver.php b/src/ModelResolver.php index 0afde13..69b1d17 100644 --- a/src/ModelResolver.php +++ b/src/ModelResolver.php @@ -18,7 +18,7 @@ class ModelResolver protected array $relations; - protected string|null $relatedModelRouteParam; + protected ?string $relatedModelRouteParam; protected Request $request; @@ -26,7 +26,7 @@ class ModelResolver protected int $id; - public function setRelatedFunctionNameFromSecondaryParam(string|null $relatedModelRouteParam): static + public function setRelatedFunctionNameFromSecondaryParam(?string $relatedModelRouteParam): static { $this->relatedModelRouteParam = $relatedModelRouteParam; diff --git a/src/Traits/HasModelRelationships.php b/src/Traits/HasModelRelationships.php index ee9391a..0b8a09d 100644 --- a/src/Traits/HasModelRelationships.php +++ b/src/Traits/HasModelRelationships.php @@ -26,8 +26,8 @@ public function getRelationships(Model $model): array 'model' => (new ReflectionClass($return->getRelated()))->getName(), ]; } - } catch(\ReflectionException $e) { - echo $e->getMessage(); + } catch (\ReflectionException $e) { + echo $e->getMessage(); } } diff --git a/tests/Feature/Relationships/CreateModelWithRelatedTest.php b/tests/Feature/Relationships/CreateModelWithRelatedTest.php index e676e6e..fe9a3ac 100644 --- a/tests/Feature/Relationships/CreateModelWithRelatedTest.php +++ b/tests/Feature/Relationships/CreateModelWithRelatedTest.php @@ -24,7 +24,7 @@ class CreateModelWithRelatedTest extends TestCase public function test_it_can_create_a_user_with_many_posts_containing_many_images_in_the_request() { - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('public'); $file = UploadedFile::fake()->image('avatar.jpg'); @@ -76,7 +76,7 @@ public function test_it_can_create_a_user_with_a_phone_with_file_attached_to_pho public function test_it_can_create_a_user_with_with_phone_without_an_uploaded_image_in_the_request_json_body() { - config()->set('apiautopilot.settings.' . Phone::class . '.database_file_url', 'provider_logo'); + config()->set('apiautopilot.settings.'.Phone::class.'.database_file_url', 'provider_logo'); $this->postJson('/api/aap/user/phone', [ 'name' => 'george fourkas', 'email' => 'email@somewhere.com', @@ -94,7 +94,7 @@ public function test_it_can_create_a_user_with_with_phone_without_an_uploaded_im */ public function test_it_can_create_post_with_many_tags_and_attach_it_to_the_table() { - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('aap'); $file = UploadedFile::fake()->image('avatar.jpg'); @@ -120,7 +120,7 @@ public function test_it_can_create_a_post_model_and_attach_related_tag_ids() Tag::create(['name' => 'tag 2']); Tag::create(['name' => 'tag 3']); - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('aap'); $file = UploadedFile::fake()->image('avatar.jpg'); @@ -135,7 +135,7 @@ public function test_it_can_create_a_post_model_and_attach_related_tag_ids() public function test_it_can_create_tag_and_assign_all_posts() { - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('aap'); $file1 = UploadedFile::fake()->image('avatar.jpg'); $file2 = UploadedFile::fake()->image('avatar.jpg'); @@ -192,7 +192,7 @@ public function test_it_throws_exception_when_trying_to_many_to_many_operations_ public function test_it_can_create_polymorphic_one_to_one_models_at_the_same_time() { - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg'); @@ -232,8 +232,8 @@ public function test_it_can_create_polymorphic_one_to_one_models_at_the_same_tim */ public function test_it_can_save_the_polymorphic_many_to_many_with_files() { - config()->set('apiautopilot.settings.' . Image::class . '.database_file_url', 'image_url'); - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Image::class.'.database_file_url', 'image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg'); @@ -248,7 +248,7 @@ public function test_it_can_save_the_polymorphic_many_to_many_with_files() 'images' => [ ['image_url' => $file1], ['image_url' => $file2], - ['image_url' => $file3],], + ['image_url' => $file3], ], ]); $this ->assertDatabaseCount('posts', 16) @@ -257,8 +257,8 @@ public function test_it_can_save_the_polymorphic_many_to_many_with_files() public function test_it_can_save_the_polymorphic_many_to_many_with_files_and_attach_existing_models() { - config()->set('apiautopilot.settings.' . Image::class . '.database_file_url', 'image_url'); - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Image::class.'.database_file_url', 'image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Image::create([ 'image_url' => fake()->url, 'size' => 1232, @@ -274,7 +274,6 @@ public function test_it_can_save_the_polymorphic_many_to_many_with_files_and_att Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg'); - $this->postJson('/api/aap/post/images', [ 'title' => 'lorem Ipsum', 'body' => 'post body', @@ -292,8 +291,8 @@ public function test_it_can_save_the_polymorphic_many_to_many_with_files_and_att public function test_it_can_attach_polymorphic_many_to_many() { - config()->set('apiautopilot.settings.' . Image::class . '.database_file_url', 'image_url'); - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Image::class.'.database_file_url', 'image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Image::create([ 'image_url' => fake()->url, 'size' => 1232, @@ -307,14 +306,14 @@ public function test_it_can_attach_polymorphic_many_to_many() 'original_name' => 'aname.jpg', ]); $this->postJson('/api/aap/post/1/images/attach', [ - 'ids' => [1, 2] + 'ids' => [1, 2], ])->assertOk(); $this->assertDatabaseCount('imageables', 2); } public function test_it_can_create_an_image_and_attach_a_single_user_to_it() { - config()->set('apiautopilot.settings.' . Image::class . '.database_file_url', 'image_url'); + config()->set('apiautopilot.settings.'.Image::class.'.database_file_url', 'image_url'); Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg'); @@ -329,7 +328,7 @@ public function test_it_can_create_an_image_and_attach_a_single_user_to_it() public function test_it_can_create_an_image_and_attach_a_many_user_to_it() { - config()->set('apiautopilot.settings.' . Image::class . '.database_file_url', 'image_url'); + config()->set('apiautopilot.settings.'.Image::class.'.database_file_url', 'image_url'); Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg'); @@ -344,7 +343,7 @@ public function test_it_can_create_an_image_and_attach_a_many_user_to_it() public function test_it_can_create_a_post_comments_at_the_same_time() { - config()->set('apiautopilot.settings.' . Post::class . '.database_file_url', 'featured_image_url'); + config()->set('apiautopilot.settings.'.Post::class.'.database_file_url', 'featured_image_url'); Storage::fake('public'); $file1 = UploadedFile::fake()->image('avatar.jpg');