Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0 #17

Merged
merged 2 commits into from
Aug 25, 2023
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
10 changes: 5 additions & 5 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/CreateMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}()
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/FileUrlDatabaseColumnIndexNotPresent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/ModelSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/Interfaces/FileManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
interface FileManipulation
{
/**
* @param UploadedFile $file
* @return array
*/
public function setAdditionalFileData(UploadedFile $file);
Expand Down
23 changes: 0 additions & 23 deletions src/ManyToManyRelationshipHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +38,6 @@ public function setRequest(Request $aRequest): static
}

/**
* @param Model $aModel
* @return $this
*/
public function setModelClass(Model $aModel): static
Expand All @@ -65,7 +48,6 @@ public function setModelClass(Model $aModel): static
}

/**
* @param $id
* @return $this
*/
public function setModelID($id): static
Expand All @@ -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;
Expand Down Expand Up @@ -111,7 +89,6 @@ public function attachTo(): static
}

/**
* @param Model $model
* @return $this
*/
public function detachFrom(Model $model): static
Expand Down
4 changes: 2 additions & 2 deletions src/ModelResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ModelResolver

protected array $relations;

protected string|null $relatedModelRouteParam;
protected ?string $relatedModelRouteParam;

protected Request $request;

protected Model $model;

protected int $id;

public function setRelatedFunctionNameFromSecondaryParam(string|null $relatedModelRouteParam): static
public function setRelatedFunctionNameFromSecondaryParam(?string $relatedModelRouteParam): static
{
$this->relatedModelRouteParam = $relatedModelRouteParam;

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/HasModelRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
35 changes: 17 additions & 18 deletions tests/Feature/Relationships/CreateModelWithRelatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand Down