From e4838a53cfd334ba040719c5087bdf58940eabd0 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Wed, 1 Nov 2023 23:02:05 +0100 Subject: [PATCH 01/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/code-style-pr.yml | 19 + .github/workflows/code-style.yml | 19 + composer.json | 6 +- config/config.php | 14 +- docs/12-images.md | 6 +- pint.json | 130 ++ routes/web.php | 6 +- src/ApiHelper.php | 5 +- src/Builder.php | 679 ++---- src/Console/CreateWebhook.php | 46 +- src/Console/DeleteWebhook.php | 19 +- src/Console/ListWebhooks.php | 5 +- src/Console/PublishCommand.php | 2 + src/Console/ReactivateWebhook.php | 10 +- src/Enums/AgeRating/Category.php | 8 +- src/Enums/AgeRating/Rating.php | 28 +- .../AgeRatingContentDescription/Category.php | 8 +- src/Enums/Character/Gender.php | 10 +- src/Enums/Character/Species.php | 14 +- src/Enums/Company/ChangeDateCategory.php | 20 +- src/Enums/Company/StartDateCategory.php | 20 +- src/Enums/CompanyWebsite/Category.php | 38 +- src/Enums/ExternalGame/Category.php | 18 +- src/Enums/ExternalGame/Media.php | 8 +- src/Enums/Game/Category.php | 30 +- src/Enums/Game/Status.php | 18 +- src/Enums/GameVersionFeature/Category.php | 8 +- .../IncludedFeature.php | 10 +- src/Enums/Image/Size.php | 24 +- src/Enums/Platform/Category.php | 16 +- .../PlatformVersionReleaseDate/Category.php | 20 +- .../PlatformVersionReleaseDate/Region.php | 20 +- src/Enums/PlatformWebsite/Category.php | 42 +- src/Enums/ReleaseDate/Category.php | 20 +- src/Enums/ReleaseDate/Region.php | 20 +- src/Enums/TagNumbers.php | 14 + src/Enums/Webhook/Category.php | 78 +- src/Enums/Webhook/Method.php | 10 +- src/Enums/Website/Category.php | 38 +- .../AgeRatingContentDescriptionCreated.php | 13 +- .../AgeRatingContentDescriptionDeleted.php | 3 +- .../AgeRatingContentDescriptionUpdated.php | 3 +- src/Events/AgeRatingCreated.php | 13 +- src/Events/AgeRatingDeleted.php | 3 +- src/Events/AgeRatingUpdated.php | 3 +- src/Events/AlternativeNameCreated.php | 13 +- src/Events/AlternativeNameDeleted.php | 3 +- src/Events/AlternativeNameUpdated.php | 3 +- src/Events/ArtworkCreated.php | 13 +- src/Events/ArtworkDeleted.php | 3 +- src/Events/ArtworkUpdated.php | 3 +- src/Events/CharacterCreated.php | 13 +- src/Events/CharacterDeleted.php | 3 +- src/Events/CharacterMugShotCreated.php | 13 +- src/Events/CharacterMugShotDeleted.php | 3 +- src/Events/CharacterMugShotUpdated.php | 3 +- src/Events/CharacterUpdated.php | 3 +- src/Events/CollectionCreated.php | 13 +- src/Events/CollectionDeleted.php | 3 +- src/Events/CollectionMembershipCreated.php | 26 + src/Events/CollectionMembershipDeleted.php | 9 + .../CollectionMembershipTypeCreated.php | 26 + .../CollectionMembershipTypeDeleted.php | 9 + .../CollectionMembershipTypeUpdated.php | 9 + src/Events/CollectionMembershipUpdated.php | 9 + src/Events/CollectionRelationCreated.php | 26 + src/Events/CollectionRelationDeleted.php | 9 + src/Events/CollectionRelationTypeCreated.php | 26 + src/Events/CollectionRelationTypeDeleted.php | 9 + src/Events/CollectionRelationTypeUpdated.php | 9 + src/Events/CollectionRelationUpdated.php | 9 + src/Events/CollectionTypeCreated.php | 26 + src/Events/CollectionTypeDeleted.php | 9 + src/Events/CollectionTypeUpdated.php | 9 + src/Events/CollectionUpdated.php | 3 +- src/Events/CompanyCreated.php | 13 +- src/Events/CompanyDeleted.php | 3 +- src/Events/CompanyLogoCreated.php | 13 +- src/Events/CompanyLogoDeleted.php | 3 +- src/Events/CompanyLogoUpdated.php | 3 +- src/Events/CompanyUpdated.php | 3 +- src/Events/CompanyWebsiteCreated.php | 13 +- src/Events/CompanyWebsiteDeleted.php | 3 +- src/Events/CompanyWebsiteUpdated.php | 3 +- src/Events/CoverCreated.php | 13 +- src/Events/CoverDeleted.php | 3 +- src/Events/CoverUpdated.php | 3 +- src/Events/Event.php | 24 +- src/Events/EventCreated.php | 26 + src/Events/EventDeleted.php | 9 + src/Events/EventLogoCreated.php | 26 + src/Events/EventLogoDeleted.php | 9 + src/Events/EventLogoUpdated.php | 9 + src/Events/EventNetworkCreated.php | 26 + src/Events/EventNetworkDeleted.php | 9 + src/Events/EventNetworkUpdated.php | 9 + src/Events/EventUpdated.php | 9 + src/Events/ExternalGameCreated.php | 13 +- src/Events/ExternalGameDeleted.php | 3 +- src/Events/ExternalGameUpdated.php | 3 +- src/Events/FranchiseCreated.php | 13 +- src/Events/FranchiseDeleted.php | 3 +- src/Events/FranchiseUpdated.php | 3 +- src/Events/GameCreated.php | 13 +- src/Events/GameDeleted.php | 3 +- src/Events/GameEngineCreated.php | 13 +- src/Events/GameEngineDeleted.php | 3 +- src/Events/GameEngineLogoCreated.php | 13 +- src/Events/GameEngineLogoDeleted.php | 3 +- src/Events/GameEngineLogoUpdated.php | 3 +- src/Events/GameEngineUpdated.php | 3 +- src/Events/GameLocalizationCreated.php | 26 + src/Events/GameLocalizationDeleted.php | 9 + src/Events/GameLocalizationUpdated.php | 9 + src/Events/GameModeCreated.php | 13 +- src/Events/GameModeDeleted.php | 3 +- src/Events/GameModeUpdated.php | 3 +- src/Events/GameUpdated.php | 3 +- src/Events/GameVersionCreated.php | 13 +- src/Events/GameVersionDeleted.php | 3 +- src/Events/GameVersionFeatureCreated.php | 13 +- src/Events/GameVersionFeatureDeleted.php | 3 +- src/Events/GameVersionFeatureUpdated.php | 3 +- src/Events/GameVersionFeatureValueCreated.php | 13 +- src/Events/GameVersionFeatureValueDeleted.php | 3 +- src/Events/GameVersionFeatureValueUpdated.php | 3 +- src/Events/GameVersionUpdated.php | 3 +- src/Events/GameVideoCreated.php | 13 +- src/Events/GameVideoDeleted.php | 3 +- src/Events/GameVideoUpdated.php | 3 +- src/Events/GenreCreated.php | 13 +- src/Events/GenreDeleted.php | 3 +- src/Events/GenreUpdated.php | 3 +- src/Events/InvolvedCompanyCreated.php | 13 +- src/Events/InvolvedCompanyDeleted.php | 3 +- src/Events/InvolvedCompanyUpdated.php | 3 +- src/Events/KeywordCreated.php | 13 +- src/Events/KeywordDeleted.php | 3 +- src/Events/KeywordUpdated.php | 3 +- src/Events/LanguageCreated.php | 26 + src/Events/LanguageDeleted.php | 9 + src/Events/LanguageSupportCreated.php | 26 + src/Events/LanguageSupportDeleted.php | 9 + src/Events/LanguageSupportTypeCreated.php | 26 + src/Events/LanguageSupportTypeDeleted.php | 9 + src/Events/LanguageSupportTypeUpdated.php | 9 + src/Events/LanguageSupportUpdated.php | 9 + src/Events/LanguageUpdated.php | 9 + src/Events/MultiplayerModeCreated.php | 13 +- src/Events/MultiplayerModeDeleted.php | 3 +- src/Events/MultiplayerModeUpdated.php | 3 +- src/Events/NetworkTypeCreated.php | 26 + src/Events/NetworkTypeDeleted.php | 9 + src/Events/NetworkTypeUpdated.php | 9 + src/Events/PlatformCreated.php | 13 +- src/Events/PlatformDeleted.php | 3 +- src/Events/PlatformFamilyCreated.php | 13 +- src/Events/PlatformFamilyDeleted.php | 3 +- src/Events/PlatformFamilyUpdated.php | 3 +- src/Events/PlatformLogoCreated.php | 13 +- src/Events/PlatformLogoDeleted.php | 3 +- src/Events/PlatformLogoUpdated.php | 3 +- src/Events/PlatformUpdated.php | 3 +- src/Events/PlatformVersionCompanyCreated.php | 13 +- src/Events/PlatformVersionCompanyDeleted.php | 3 +- src/Events/PlatformVersionCompanyUpdated.php | 3 +- src/Events/PlatformVersionCreated.php | 13 +- src/Events/PlatformVersionDeleted.php | 3 +- .../PlatformVersionReleaseDateCreated.php | 13 +- .../PlatformVersionReleaseDateDeleted.php | 3 +- .../PlatformVersionReleaseDateUpdated.php | 3 +- src/Events/PlatformVersionUpdated.php | 3 +- src/Events/PlatformWebsiteCreated.php | 13 +- src/Events/PlatformWebsiteDeleted.php | 3 +- src/Events/PlatformWebsiteUpdated.php | 3 +- src/Events/PlayerPerspectiveCreated.php | 13 +- src/Events/PlayerPerspectiveDeleted.php | 3 +- src/Events/PlayerPerspectiveUpdated.php | 3 +- src/Events/RegionCreated.php | 26 + src/Events/RegionDeleted.php | 9 + src/Events/RegionUpdated.php | 9 + src/Events/ReleaseDateCreated.php | 13 +- src/Events/ReleaseDateDeleted.php | 3 +- src/Events/ReleaseDateStatusCreated.php | 26 + src/Events/ReleaseDateStatusDeleted.php | 9 + src/Events/ReleaseDateStatusUpdated.php | 9 + src/Events/ReleaseDateUpdated.php | 3 +- src/Events/ScreenshotCreated.php | 13 +- src/Events/ScreenshotDeleted.php | 3 +- src/Events/ScreenshotUpdated.php | 3 +- src/Events/ThemeCreated.php | 13 +- src/Events/ThemeDeleted.php | 3 +- src/Events/ThemeUpdated.php | 3 +- src/Events/WebsiteCreated.php | 13 +- src/Events/WebsiteDeleted.php | 3 +- src/Events/WebsiteUpdated.php | 3 +- src/Exceptions/AuthenticationException.php | 3 +- src/Exceptions/InvalidParamsException.php | 3 +- .../InvalidWebhookMethodException.php | 8 +- .../InvalidWebhookSecretException.php | 2 + src/Exceptions/MissingEndpointException.php | 2 + src/Exceptions/ModelNotFoundException.php | 3 +- src/Exceptions/PropertyDoesNotExist.php | 3 +- src/Exceptions/ServiceException.php | 3 +- .../ServiceUnavailableException.php | 3 +- src/Exceptions/UnauthorizedException.php | 3 +- .../WebhookSecretMissingException.php | 2 + src/IGDBLaravelServiceProvider.php | 21 +- src/Interfaces/ModelInterface.php | 5 +- src/Interfaces/WebhookInterface.php | 5 +- src/Models/AgeRating.php | 5 +- src/Models/AgeRatingContentDescription.php | 3 +- src/Models/AlternativeName.php | 6 +- src/Models/Artwork.php | 6 +- src/Models/Character.php | 6 +- src/Models/CharacterMugShot.php | 3 +- src/Models/Collection.php | 8 +- src/Models/CollectionMembership.php | 14 + src/Models/CollectionMembershipType.php | 12 + src/Models/CollectionRelation.php | 14 + src/Models/CollectionRelationType.php | 13 + src/Models/CollectionType.php | 9 + src/Models/Company.php | 6 +- src/Models/CompanyLogo.php | 3 +- src/Models/CompanyWebsite.php | 3 +- src/Models/Cover.php | 7 +- src/Models/Event.php | 14 + src/Models/EventLogo.php | 12 + src/Models/EventNetwork.php | 13 + src/Models/ExternalGame.php | 7 +- src/Models/Franchise.php | 6 +- src/Models/Game.php | 32 +- src/Models/GameEngine.php | 7 +- src/Models/GameEngineLogo.php | 3 +- src/Models/GameLocalization.php | 6 +- src/Models/GameMode.php | 3 +- src/Models/GameVersion.php | 6 +- src/Models/GameVersionFeature.php | 5 +- src/Models/GameVersionFeatureValue.php | 6 +- src/Models/GameVideo.php | 6 +- src/Models/Genre.php | 3 +- src/Models/Image.php | 23 +- src/Models/InvolvedCompany.php | 7 +- src/Models/Keyword.php | 3 +- src/Models/Language.php | 1 - src/Models/LanguageSupport.php | 6 +- src/Models/LanguageSupportType.php | 1 - src/Models/Model.php | 202 +- src/Models/MultiplayerMode.php | 7 +- src/Models/NetworkType.php | 12 + src/Models/Platform.php | 8 +- src/Models/PlatformFamily.php | 3 +- src/Models/PlatformLogo.php | 3 +- src/Models/PlatformVersion.php | 7 +- src/Models/PlatformVersionCompany.php | 6 +- src/Models/PlatformVersionReleaseDate.php | 6 +- src/Models/PlatformWebsite.php | 3 +- src/Models/PlayerPerspective.php | 3 +- src/Models/Region.php | 1 - src/Models/ReleaseDate.php | 8 +- src/Models/ReleaseDateStatus.php | 9 + src/Models/Screenshot.php | 6 +- src/Models/Search.php | 11 +- src/Models/Theme.php | 3 +- src/Models/Webhook.php | 122 +- src/Models/Website.php | 6 +- src/Traits/DateCasts.php | 4 +- src/Traits/HasAttributes.php | 9 +- src/Traits/HasRelationships.php | 5 +- src/Traits/Operators.php | 4 +- tests/ApiHelperTest.php | 14 +- tests/BuilderTest.php | 625 ++---- tests/EventsTest.php | 38 + tests/ImageTest.php | 44 +- tests/ModelTest.php | 370 +--- tests/TestCase.php | 55 +- tests/WebhookTest.php | 1854 +---------------- 277 files changed, 2559 insertions(+), 4136 deletions(-) create mode 100644 .github/workflows/code-style-pr.yml create mode 100644 .github/workflows/code-style.yml create mode 100644 pint.json create mode 100644 src/Enums/TagNumbers.php create mode 100644 src/Events/CollectionMembershipCreated.php create mode 100644 src/Events/CollectionMembershipDeleted.php create mode 100644 src/Events/CollectionMembershipTypeCreated.php create mode 100644 src/Events/CollectionMembershipTypeDeleted.php create mode 100644 src/Events/CollectionMembershipTypeUpdated.php create mode 100644 src/Events/CollectionMembershipUpdated.php create mode 100644 src/Events/CollectionRelationCreated.php create mode 100644 src/Events/CollectionRelationDeleted.php create mode 100644 src/Events/CollectionRelationTypeCreated.php create mode 100644 src/Events/CollectionRelationTypeDeleted.php create mode 100644 src/Events/CollectionRelationTypeUpdated.php create mode 100644 src/Events/CollectionRelationUpdated.php create mode 100644 src/Events/CollectionTypeCreated.php create mode 100644 src/Events/CollectionTypeDeleted.php create mode 100644 src/Events/CollectionTypeUpdated.php create mode 100644 src/Events/EventCreated.php create mode 100644 src/Events/EventDeleted.php create mode 100644 src/Events/EventLogoCreated.php create mode 100644 src/Events/EventLogoDeleted.php create mode 100644 src/Events/EventLogoUpdated.php create mode 100644 src/Events/EventNetworkCreated.php create mode 100644 src/Events/EventNetworkDeleted.php create mode 100644 src/Events/EventNetworkUpdated.php create mode 100644 src/Events/EventUpdated.php create mode 100644 src/Events/GameLocalizationCreated.php create mode 100644 src/Events/GameLocalizationDeleted.php create mode 100644 src/Events/GameLocalizationUpdated.php create mode 100644 src/Events/LanguageCreated.php create mode 100644 src/Events/LanguageDeleted.php create mode 100644 src/Events/LanguageSupportCreated.php create mode 100644 src/Events/LanguageSupportDeleted.php create mode 100644 src/Events/LanguageSupportTypeCreated.php create mode 100644 src/Events/LanguageSupportTypeDeleted.php create mode 100644 src/Events/LanguageSupportTypeUpdated.php create mode 100644 src/Events/LanguageSupportUpdated.php create mode 100644 src/Events/LanguageUpdated.php create mode 100644 src/Events/NetworkTypeCreated.php create mode 100644 src/Events/NetworkTypeDeleted.php create mode 100644 src/Events/NetworkTypeUpdated.php create mode 100644 src/Events/RegionCreated.php create mode 100644 src/Events/RegionDeleted.php create mode 100644 src/Events/RegionUpdated.php create mode 100644 src/Events/ReleaseDateStatusCreated.php create mode 100644 src/Events/ReleaseDateStatusDeleted.php create mode 100644 src/Events/ReleaseDateStatusUpdated.php create mode 100644 src/Models/CollectionMembership.php create mode 100644 src/Models/CollectionMembershipType.php create mode 100644 src/Models/CollectionRelation.php create mode 100644 src/Models/CollectionRelationType.php create mode 100644 src/Models/CollectionType.php create mode 100644 src/Models/Event.php create mode 100644 src/Models/EventLogo.php create mode 100644 src/Models/EventNetwork.php create mode 100644 src/Models/NetworkType.php create mode 100644 src/Models/ReleaseDateStatus.php create mode 100644 tests/EventsTest.php diff --git a/.github/workflows/code-style-pr.yml b/.github/workflows/code-style-pr.yml new file mode 100644 index 0000000..674568f --- /dev/null +++ b/.github/workflows/code-style-pr.yml @@ -0,0 +1,19 @@ +name: Pint (PR) + +on: + pull_request: + branches: [ main ] + paths-ignore: + - '.github/**' + - 'LICENSE' + - 'README.md' + +jobs: + pint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: composer install --prefer-dist --no-progress --dev + - name: Run pint + run: composer pint diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 0000000..290f090 --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,19 @@ +name: Pint + +on: + push: + branches: [ main ] + paths-ignore: + - '.github/**' + - 'LICENSE' + - 'README.md' + +jobs: + pint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: composer install --prefer-dist --no-progress --dev + - name: Run pint + run: composer pint diff --git a/composer.json b/composer.json index 341005d..847621a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "wrapper" ], "type": "library", - "minimum-stability": "dev", + "minimum-stability": "stable", "require": { "php": "^8.1", "laravel/framework": "^8.40.0|^9.0|^10.0", @@ -23,7 +23,8 @@ "orchestra/testbench": "^6.23|^7.0|^8.0", "nunomaduro/collision": "^5.3|^6.1|^7.0", "roave/security-advisories": "dev-latest", - "nunomaduro/larastan": "^1.0|^2.0" + "nunomaduro/larastan": "^1.0|^2.0", + "laravel/pint": "dev-main" }, "license": "MIT", "authors": [ @@ -33,6 +34,7 @@ } ], "scripts": { + "pint": "./vendor/bin/pint --test -v", "test": "./vendor/bin/testbench package:test", "stan": "./vendor/bin/phpstan analyse -c phpstan.neon", "stan-2g": "./vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=2G", diff --git a/config/config.php b/config/config.php index 74f1ca4..739cca7 100644 --- a/config/config.php +++ b/config/config.php @@ -1,28 +1,30 @@ [ 'client_id' => env('TWITCH_CLIENT_ID', ''), 'client_secret' => env('TWITCH_CLIENT_SECRET', ''), ], - /* + /** * This package caches queries automatically (for 1 hour per default). * Here you can set how long each query should be cached (in seconds). * - * To turn cache off set this value to 0 + * To turn cache off set this value to 0. */ 'cache_lifetime' => env('IGDB_CACHE_LIFETIME', 3600), - /* + /** * Path where the webhooks should be handled. */ 'webhook_path' => 'igdb-webhook/handle', - /* + /** * The webhook secret. * * This needs to be a string of your choice in order to use the webhook diff --git a/docs/12-images.md b/docs/12-images.md index 232b44d..09c9fb0 100644 --- a/docs/12-images.md +++ b/docs/12-images.md @@ -9,6 +9,7 @@ This is supported for: - `CharacterMugShot` - `CompanyLogo` - `Cover` +- `EventLogo` - `GameEngineLogo` - `PlatformLogo` - `Screenshot` @@ -31,9 +32,8 @@ $game->cover->getUrl(); ### Other sizes -As the first parameter the method receives your desired image size. Check out the available -sizes [in the official IGDB API documentation](https://api-docs.igdb.com/#images) or simply use the available constants -of the `MarcReichel\IGDBLaravel\Enums\Image\Size` class. +As the first parameter the method receives your desired image size. Simply use the available enum values +of the `MarcReichel\IGDBLaravel\Enums\Image\Size` enum. ```php // torchlight! {"lineNumbers": false} diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..99eb39e --- /dev/null +++ b/pint.json @@ -0,0 +1,130 @@ +{ + "preset": "psr12", + "rules": { + "align_multiline_comment": true, + "array_indentation": true, + "array_push": true, + "array_syntax": { + "syntax": "short" + }, + "assign_null_coalescing_to_coalesce_equal": true, + "binary_operator_spaces": true, + "blank_line_before_statement": true, + "cast_spaces": true, + "clean_namespace": true, + "combine_consecutive_issets": true, + "combine_consecutive_unsets": true, + "compact_nullable_typehint": true, + "concat_space": { + "spacing": "one" + }, + "declare_strict_types": true, + "fully_qualified_strict_types": true, + "function_to_constant": true, + "general_phpdoc_annotation_remove": { + "annotations": [ + "author", + "package", + "since" + ], + "case_sensitive": false + }, + "get_class_to_class_keyword": true, + "is_null": true, + "lambda_not_used_import": true, + "logical_operators": true, + "method_chaining_indentation": true, + "modernize_types_casting": true, + "multiline_whitespace_before_semicolons": true, + "no_empty_comment": true, + "no_empty_phpdoc": true, + "no_empty_statement": true, + "no_extra_blank_lines": { + "tokens": ["attribute", "break", "case", "continue", "curly_brace_block", "default", "extra", "parenthesis_brace_block", "return", "square_brace_block", "switch", "throw", "use", "use_trait"] + }, + "no_multiline_whitespace_around_double_arrow": true, + "no_short_bool_cast": true, + "no_singleline_whitespace_before_semicolons": true, + "no_superfluous_elseif": true, + "no_superfluous_phpdoc_tags": true, + "no_trailing_comma_in_singleline": true, + "no_unneeded_control_parentheses": true, + "no_useless_concat_operator": true, + "no_useless_else": true, + "no_useless_nullsafe_operator": true, + "no_useless_return": true, + "no_whitespace_before_comma_in_array": true, + "nullable_type_declaration": true, + "object_operator_without_whitespace": true, + "ordered_imports": { + "imports_order": [ + "class", + "function", + "const" + ], + "sort_algorithm": "alpha" + }, + "ordered_interfaces": true, + "ordered_types": { + "null_adjustment": "always_last" + }, + "phpdoc_align": { + "align": "left" + }, + "phpdoc_indent": true, + "phpdoc_no_useless_inheritdoc": true, + "phpdoc_order": true, + "phpdoc_scalar": true, + "phpdoc_single_line_var_spacing": true, + "phpdoc_separation": { + "groups": [ + [ + "deprecated", + "link", + "see" + ], + [ + "template", + "template-extends", + "template-implements" + ] + ] + }, + "phpdoc_summary": true, + "phpdoc_tag_casing": true, + "phpdoc_trim": true, + "phpdoc_trim_consecutive_blank_line_separation": true, + "phpdoc_var_without_name": true, + "php_unit_construct": true, + "php_unit_dedicate_assert": true, + "php_unit_dedicate_assert_internal_type": true, + "php_unit_internal_class": true, + "php_unit_method_casing": true, + "return_assignment": true, + "return_type_declaration": true, + "short_scalar_cast": true, + "single_line_comment_spacing": true, + "single_line_comment_style": true, + "single_quote": true, + "single_space_around_construct": true, + "ternary_to_null_coalescing": true, + "trailing_comma_in_multiline": { + "elements": [ + "arguments", + "arrays", + "match", + "parameters" + ] + }, + "trim_array_spaces": true, + "type_declaration_spaces": true, + "types_spaces": { + "space": "single" + }, + "use_arrow_functions": true, + "void_return": true, + "whitespace_after_comma_in_array": { + "ensure_single_space": true + } + } +} diff --git a/routes/web.php b/routes/web.php index 327a8d5..f51b790 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,7 @@ name('handle-igdb-webhook'); diff --git a/src/ApiHelper.php b/src/ApiHelper.php index c3bb344..b93cd1f 100644 --- a/src/ApiHelper.php +++ b/src/ApiHelper.php @@ -1,5 +1,7 @@ json(); if (is_array($response) && isset($response['access_token']) && $response['expires_in']) { - Cache::put($accessTokenCacheKey, (string)$response['access_token'], (int)$response['expires_in'] - 60); + Cache::put($accessTokenCacheKey, (string) $response['access_token'], (int) $response['expires_in'] - 60); $accessToken = $response['access_token']; } diff --git a/src/Builder.php b/src/Builder.php index 814b0c3..193e8fc 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -1,5 +1,7 @@ push('*'); } - $collection = $collection->filter(function ($field) { - return !strpos($field, '.'); - })->flatten(); + $collection = $collection->filter(fn ($field) => !strpos($field, '.'))->flatten(); if ($collection->isEmpty()) { $collection->push('*'); @@ -105,9 +88,6 @@ public function select(mixed $fields): self return $this; } - /** - * @return void - */ protected function init(): void { $this->initClient(); @@ -115,9 +95,6 @@ protected function init(): void $this->resetCacheLifetime(); } - /** - * @return void - */ private function initClient(): void { $this->client = Http::withOptions([ @@ -130,8 +107,6 @@ private function initClient(): void /** * Init the default query. - * - * @return void */ protected function initQuery(): void { @@ -140,8 +115,6 @@ protected function initQuery(): void /** * Reset the cache lifetime. - * - * @return void */ protected function resetCacheLifetime(): void { @@ -155,10 +128,6 @@ protected function resetCacheLifetime(): void /** * Set the "limit" value of the query. - * - * @param int $limit - * - * @return self */ public function limit(int $limit): self { @@ -170,10 +139,6 @@ public function limit(int $limit): self /** * Alias to set the "limit" value of the query. - * - * @param int $limit - * - * @return self */ public function take(int $limit): self { @@ -182,10 +147,6 @@ public function take(int $limit): self /** * Set the "offset" value of the query. - * - * @param int $offset - * - * @return self */ public function offset(int $offset): self { @@ -196,10 +157,6 @@ public function offset(int $offset): self /** * Alias to set the "offset" value of the query. - * - * @param int $offset - * - * @return self */ public function skip(int $offset): self { @@ -208,11 +165,6 @@ public function skip(int $offset): self /** * Set the limit and offset for a given page. - * - * @param int $page - * @param int $perPage - * - * @return self */ public function forPage(int $page, int $perPage = 10): self { @@ -221,10 +173,6 @@ public function forPage(int $page, int $perPage = 10): self /** * Search for the given string. - * - * @param string $query - * - * @return self */ public function search(string $query): self { @@ -236,13 +184,8 @@ public function search(string $query): self /** * Add a fuzzy search to the query. * - * @param mixed $key - * @param string $query - * @param bool $caseSensitive - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function fuzzySearch( mixed $key, @@ -253,7 +196,7 @@ public function fuzzySearch( $tokenizedQuery = explode(' ', $query); $keys = collect($key)->crossJoin($tokenizedQuery)->toArray(); - return $this->whereNested(function ($query) use ($keys, $caseSensitive) { + return $this->whereNested(function ($query) use ($keys, $caseSensitive): void { foreach ($keys as $v) { if (is_array($v)) { $query->whereLike($v[0], $v[1], $caseSensitive, '|'); @@ -265,12 +208,6 @@ public function fuzzySearch( /** * Add an "or fuzzy search" to the query. * - * @param mixed $key - * @param string $query - * @param bool $caseSensitive - * @param string $boolean - * - * @return self * @throws ReflectionException|InvalidParamsException */ public function orFuzzySearch( @@ -285,19 +222,15 @@ public function orFuzzySearch( /** * Add a basic where clause to the query. * - * @param mixed $key - * @param mixed|null $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function where( mixed $key, mixed $operator = null, mixed $value = null, - string $boolean = '&' + string $boolean = '&', ): self { if ($key instanceof Closure) { return $this->whereNested($key, $boolean); @@ -311,8 +244,11 @@ public function where( throw new InvalidArgumentException('Parameter #1 $key needs to be string. ' . gettype($key) . ' given.'); } - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, - func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator( + $value, + $operator, + func_num_args() === 2, + ); $select = $this->query->get('fields', new Collection()); if (!$select->contains($key) && !$select->contains('*')) { @@ -350,19 +286,15 @@ public function where( /** * Add an "or where" clause to the query. * - * @param mixed $key - * @param string|null $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function orWhere( mixed $key, string $operator = null, mixed $value = null, - string $boolean = '|' + string $boolean = '|', ): self { if ($key instanceof Closure) { return $this->whereNested($key, $boolean); @@ -372,8 +304,11 @@ public function orWhere( return $this->addArrayOfWheres($key, $boolean); } - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, - func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator( + $value, + $operator, + func_num_args() === 2, + ); return $this->where($key, $operator, $value, $boolean); } @@ -381,19 +316,13 @@ public function orWhere( /** * Add a "where like" clause to the query. * - * @param string $key - * @param string $value - * @param bool $caseSensitive - * @param string $boolean - * - * @return self * @throws JsonException */ public function whereLike( string $key, string $value, bool $caseSensitive = true, - string $boolean = '&' + string $boolean = '&', ): self { $where = $this->query->get('where', new Collection()); @@ -409,19 +338,13 @@ public function whereLike( /** * Add an "or where like" clause to the query. * - * @param string $key - * @param string $value - * @param bool $caseSensitive - * @param string $boolean - * - * @return self * @throws JsonException */ public function orWhereLike( string $key, string $value, bool $caseSensitive = true, - string $boolean = '|' + string $boolean = '|', ): self { return $this->whereLike($key, $value, $caseSensitive, $boolean); } @@ -429,19 +352,13 @@ public function orWhereLike( /** * Add a "where not like" clause to the query. * - * @param string $key - * @param string $value - * @param bool $caseSensitive - * @param string $boolean - * - * @return self * @throws JsonException */ public function whereNotLike( string $key, string $value, bool $caseSensitive = true, - string $boolean = '&' + string $boolean = '&', ): self { $where = $this->query->get('where', new Collection()); @@ -457,31 +374,18 @@ public function whereNotLike( /** * Add an "or where not like" clause to the query. * - * @param string $key - * @param string $value - * @param bool $caseSensitive - * @param string $boolean - * - * @return self * @throws JsonException */ public function orWhereNotLike( string $key, string $value, bool $caseSensitive = true, - string $boolean = '|' + string $boolean = '|', ): self { return $this->whereNotLike($key, $value, $caseSensitive, $boolean); } /** - * @param string $key - * @param string $value - * @param bool $caseSensitive - * @param string $operator - * @param string $insensitiveOperator - * - * @return string * @throws JsonException */ private function generateWhereLikeClause( @@ -489,7 +393,7 @@ private function generateWhereLikeClause( string $value, bool $caseSensitive, string $operator, - string $insensitiveOperator + string $insensitiveOperator, ): string { $hasPrefix = Str::startsWith($value, ['%', '*']); $hasSuffix = Str::endsWith($value, ['%', '*']); @@ -512,23 +416,17 @@ private function generateWhereLikeClause( /** * Prepare the value and operator for a where clause. - * - * @param mixed $value - * @param mixed $operator - * @param bool $useDefault - * - * @return array */ private function prepareValueAndOperator( mixed $value, mixed $operator, - bool $useDefault = false + bool $useDefault = false, ): array { if ($useDefault) { return [$operator, '=']; } - if (!is_string($operator) && !is_null($operator)) { + if (!is_string($operator) && null !== $operator) { throw new InvalidArgumentException('Parameter #2 $operator needs to be string or null. ' . gettype($operator) . ' given.'); } @@ -543,37 +441,28 @@ private function prepareValueAndOperator( * Determine if the given operator and value combination is legal. * * Prevents using Null values with invalid operators. - * - * @param string|null $operator - * @param mixed $value - * - * @return bool */ - private function invalidOperatorAndValue(string|null $operator, mixed $value): bool + private function invalidOperatorAndValue(?string $operator, mixed $value): bool { - return is_null($value) && in_array($operator, $this->operators, true) && !in_array($operator, ['=', '!=']); + return null === $value && in_array($operator, $this->operators, true) && !in_array($operator, ['=', '!=']); } /** * Add an array of where clauses to the query. * - * @param array $arrayOfWheres - * @param string $boolean - * @param string $method - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ protected function addArrayOfWheres( array $arrayOfWheres, string $boolean, - string $method = 'where' + string $method = 'where', ): self { return $this->whereNested(function ($query) use ( $arrayOfWheres, $method, $boolean - ) { + ): void { foreach ($arrayOfWheres as $key => $value) { if (is_numeric($key) && is_array($value)) { $query->$method(...array_values($value)); @@ -587,11 +476,8 @@ protected function addArrayOfWheres( /** * Add a nested where statement to the query. * - * @param Closure $callback - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ protected function whereNested(Closure $callback, string $boolean = '&'): self { @@ -607,11 +493,6 @@ protected function whereNested(Closure $callback, string $boolean = '&'): self /** * Add another query builder as a nested where to the query builder. - * - * @param Builder $query - * @param string $boolean - * - * @return self */ protected function addNestedWhereQuery(Builder $query, string $boolean): self { @@ -628,15 +509,6 @@ protected function addNestedWhereQuery(Builder $query, string $boolean): self /** * Add a "where in" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereIn( string $key, @@ -644,18 +516,17 @@ public function whereIn( string $boolean = '&', string $operator = '=', string $prefix = '(', - string $suffix = ')' + string $suffix = ')', ): self { if (($prefix === '(' && $suffix !== ')') || ($prefix === '[' && $suffix !== ']') || ($prefix === '{' && $suffix !== '}')) { $message = 'Prefix and Suffix must be "(" and ")", "[" and "]" or "{" and "}".'; + throw new InvalidArgumentException($message); } $where = $this->query->get('where', new Collection()); - $valuesString = collect($values)->map(function ($value) { - return !is_numeric($value) ? '"' . $value . '"' : $value; - })->implode(','); + $valuesString = collect($values)->map(fn ($value) => !is_numeric($value) ? '"' . $value . '"' : $value)->implode(','); $where->push(($where->count() ? $boolean . ' ' : '') . $key . ' ' . $operator . ' ' . $prefix . $valuesString . $suffix); @@ -666,15 +537,6 @@ public function whereIn( /** * Add an "or where in" clause to the query. - * - * @param string $key - * @param array $value - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereIn( string $key, @@ -682,23 +544,13 @@ public function orWhereIn( string $boolean = '|', string $operator = '=', string $prefix = '(', - string $suffix = ')' + string $suffix = ')', ): self { - return $this->whereIn($key, $value, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $value, $boolean, $operator, $prefix, $suffix); } /** * Add a "where in all" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereInAll( string $key, @@ -706,23 +558,13 @@ public function whereInAll( string $boolean = '&', string $operator = '=', string $prefix = '[', - string $suffix = ']' + string $suffix = ']', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add an "or where in all" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereInAll( string $key, @@ -732,21 +574,11 @@ public function orWhereInAll( string $prefix = '[', string $suffix = ']', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add a "where in exact" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereInExact( string $key, @@ -756,21 +588,11 @@ public function whereInExact( string $prefix = '{', string $suffix = '}', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add an "or where in exact" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereInExact( string $key, @@ -780,21 +602,11 @@ public function orWhereInExact( string $prefix = '{', string $suffix = '}', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add a "where not in" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereNotIn( string $key, @@ -804,21 +616,11 @@ public function whereNotIn( string $prefix = '(', string $suffix = ')', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add an "or where not in" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereNotIn( string $key, @@ -826,23 +628,13 @@ public function orWhereNotIn( string $boolean = '|', string $operator = '!=', string $prefix = '(', - string $suffix = ')' + string $suffix = ')', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add a "where not in all" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereNotInAll( string $key, @@ -850,23 +642,13 @@ public function whereNotInAll( string $boolean = '&', string $operator = '!=', string $prefix = '[', - string $suffix = ']' + string $suffix = ']', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add an "or where not in all" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereNotInAll( string $key, @@ -874,23 +656,13 @@ public function orWhereNotInAll( string $boolean = '|', string $operator = '!=', string $prefix = '[', - string $suffix = ']' + string $suffix = ']', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add a "where not in exact" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function whereNotInExact( string $key, @@ -898,23 +670,13 @@ public function whereNotInExact( string $boolean = '&', string $operator = '!=', string $prefix = '{', - string $suffix = '}' + string $suffix = '}', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add an "or where not in exact" clause to the query. - * - * @param string $key - * @param array $values - * @param string $boolean - * @param string $operator - * @param string $prefix - * @param string $suffix - * - * @return self */ public function orWhereNotInExact( string $key, @@ -922,30 +684,23 @@ public function orWhereNotInExact( string $boolean = '|', string $operator = '!=', string $prefix = '{', - string $suffix = '}' + string $suffix = '}', ): self { - return $this->whereIn($key, $values, $boolean, $operator, $prefix, - $suffix); + return $this->whereIn($key, $values, $boolean, $operator, $prefix, $suffix); } /** * Add a where between statement to the query. * - * @param string $key - * @param mixed $first - * @param mixed $second - * @param bool $withBoundaries - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function whereBetween( string $key, mixed $first, mixed $second, bool $withBoundaries = true, - string $boolean = '&' + string $boolean = '&', ): self { if (collect($this->dates)->has($key) && $this->dates[$key] === 'date') { $first = $this->castDate($first); @@ -956,11 +711,10 @@ public function whereBetween( $key, $first, $second, - $withBoundaries - ) { + $withBoundaries, + ): void { $operator = ($withBoundaries ? '=' : ''); - $query->where($key, '>' . $operator, $first)->where($key, - '<' . $operator, $second); + $query->where($key, '>' . $operator, $first)->where($key, '<' . $operator, $second); }, $boolean); return $this; @@ -969,44 +723,31 @@ public function whereBetween( /** * Add a or where between statement to the query. * - * @param string $key - * @param mixed $first - * @param mixed $second - * @param bool $withBoundaries - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function orWhereBetween( string $key, mixed $first, mixed $second, bool $withBoundaries = true, - string $boolean = '|' + string $boolean = '|', ): self { - return $this->whereBetween($key, $first, $second, $withBoundaries, - $boolean); + return $this->whereBetween($key, $first, $second, $withBoundaries, $boolean); } /** * Add a where not between statement to the query. * - * @param string $key - * @param mixed $first - * @param mixed $second - * @param bool $withBoundaries - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function whereNotBetween( string $key, mixed $first, mixed $second, bool $withBoundaries = false, - string $boolean = '&' + string $boolean = '&', ): self { if (collect($this->dates)->has($key) && $this->dates[$key] === 'date') { $first = $this->castDate($first); @@ -1017,11 +758,10 @@ public function whereNotBetween( $key, $first, $second, - $withBoundaries - ) { + $withBoundaries, + ): void { $operator = ($withBoundaries ? '=' : ''); - $query->where($key, '<' . $operator, $first)->orWhere($key, - '>' . $operator, $second); + $query->where($key, '<' . $operator, $first)->orWhere($key, '>' . $operator, $second); }, $boolean); return $this; @@ -1030,33 +770,21 @@ public function whereNotBetween( /** * Add a or where not between statement to the query. * - * @param string $key - * @param mixed $first - * @param mixed $second - * @param bool $withBoundaries - * @param string $boolean - * - * @return self - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function orWhereNotBetween( string $key, mixed $first, mixed $second, bool $withBoundaries = false, - string $boolean = '|' + string $boolean = '|', ): self { - return $this->whereNotBetween($key, $first, $second, $withBoundaries, - $boolean); + return $this->whereNotBetween($key, $first, $second, $withBoundaries, $boolean); } /** * Add a "where has" statement to the query. - * - * @param string $relationship - * @param string $boolean - * - * @return self */ public function whereHas(string $relationship, string $boolean = '&'): self { @@ -1073,11 +801,6 @@ public function whereHas(string $relationship, string $boolean = '&'): self /** * Add an "or where has" statement to the query. - * - * @param string $relationship - * @param string $boolean - * - * @return self */ public function orWhereHas(string $relationship, string $boolean = '|'): self { @@ -1086,11 +809,6 @@ public function orWhereHas(string $relationship, string $boolean = '|'): self /** * Add a "where has not" statement to the query. - * - * @param string $relationship - * @param string $boolean - * - * @return self */ public function whereHasNot(string $relationship, string $boolean = '&'): self { @@ -1107,11 +825,6 @@ public function whereHasNot(string $relationship, string $boolean = '&'): self /** * Add a "where has not" statement to the query. - * - * @param string $relationship - * @param string $boolean - * - * @return self */ public function orWhereHasNot(string $relationship, string $boolean = '|'): self { @@ -1120,11 +833,6 @@ public function orWhereHasNot(string $relationship, string $boolean = '|'): self /** * Add a "where null" clause to the query. - * - * @param string $key - * @param string $boolean - * - * @return self */ public function whereNull(string $key, string $boolean = '&'): self { @@ -1133,11 +841,6 @@ public function whereNull(string $key, string $boolean = '&'): self /** * Add an "or where null" clause to the query. - * - * @param string $key - * @param string $boolean - * - * @return self */ public function orWhereNull(string $key, string $boolean = '|'): self { @@ -1146,11 +849,6 @@ public function orWhereNull(string $key, string $boolean = '|'): self /** * Add a "where not null" clause to the query. - * - * @param string $key - * @param string $boolean - * - * @return self */ public function whereNotNull(string $key, string $boolean = '&'): self { @@ -1159,11 +857,6 @@ public function whereNotNull(string $key, string $boolean = '&'): self /** * Add an "or where not null" clause to the query. - * - * @param string $key - * @param string $boolean - * - * @return self */ public function orWhereNotNull(string $key, string $boolean = '|'): self { @@ -1173,18 +866,17 @@ public function orWhereNotNull(string $key, string $boolean = '|'): self /** * Add a "where date" statement to the query. * - * @param string $key - * @param mixed $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function whereDate(string $key, mixed $operator, mixed $value = null, string $boolean = '&'): self { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, - func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator( + $value, + $operator, + func_num_args() === 2, + ); $start = Carbon::parse($value)->startOfDay()->timestamp; $end = Carbon::parse($value)->endOfDay()->timestamp; @@ -1200,13 +892,9 @@ public function whereDate(string $key, mixed $operator, mixed $value = null, str } /** - * @param string $key - * @param mixed $operator - * @param mixed $value - * @param string $boolean - * - * @return self - * @throws JsonException|ReflectionException|InvalidParamsException + * @throws JsonException + * @throws ReflectionException + * @throws InvalidParamsException */ private function whereDateGreaterThan(string $key, mixed $operator, mixed $value, string $boolean): self { @@ -1218,13 +906,9 @@ private function whereDateGreaterThan(string $key, mixed $operator, mixed $value } /** - * @param string $key - * @param mixed $operator - * @param mixed $value - * @param string $boolean - * - * @return self - * @throws JsonException|ReflectionException|InvalidParamsException + * @throws JsonException + * @throws ReflectionException + * @throws InvalidParamsException */ private function whereDateGreaterThanOrEquals(string $key, mixed $operator, mixed $value, string $boolean): self { @@ -1236,13 +920,9 @@ private function whereDateGreaterThanOrEquals(string $key, mixed $operator, mixe } /** - * @param string $key - * @param mixed $operator - * @param mixed $value - * @param string $boolean - * - * @return self - * @throws JsonException|ReflectionException|InvalidParamsException + * @throws JsonException + * @throws ReflectionException + * @throws InvalidParamsException */ private function whereDateLowerThan(string $key, mixed $operator, mixed $value, string $boolean): self { @@ -1254,14 +934,9 @@ private function whereDateLowerThan(string $key, mixed $operator, mixed $value, } /** - * @param string $key - * @param mixed $operator - * @param mixed $value - * @param string $boolean - * - * @return self * @throws JsonException - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ private function whereDateLowerThanOrEquals(string $key, mixed $operator, mixed $value, string $boolean): self { @@ -1275,13 +950,9 @@ private function whereDateLowerThanOrEquals(string $key, mixed $operator, mixed /** * Add an "or where date" statement to the query. * - * @param string $key - * @param mixed $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function orWhereDate(string $key, mixed $operator, mixed $value = null, string $boolean = '|'): self { @@ -1291,18 +962,17 @@ public function orWhereDate(string $key, mixed $operator, mixed $value = null, s /** * Add a "where year" statement to the query. * - * @param string $key - * @param mixed $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function whereYear(string $key, mixed $operator, mixed $value = null, string $boolean = '&'): self { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, - func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator( + $value, + $operator, + func_num_args() === 2, + ); $value = Carbon::now()->setYear($value)->startOfYear(); @@ -1319,25 +989,23 @@ public function whereYear(string $key, mixed $operator, mixed $value = null, str $value = $value->clone()->startOfYear()->timestamp; } - return $this->where($key, $operator, $value, $boolean); } /** * Add an "or where year" statement to the query. * - * @param string $key - * @param mixed $operator - * @param mixed|null $value - * @param string $boolean - * - * @return self - * @throws ReflectionException|JsonException|InvalidParamsException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function orWhereYear(string $key, mixed $operator, mixed $value = null, string $boolean = '|'): self { - [$value, $operator] = $this->prepareValueAndOperator($value, $operator, - func_num_args() === 2); + [$value, $operator] = $this->prepareValueAndOperator( + $value, + $operator, + func_num_args() === 2, + ); return $this->whereYear($key, $operator, $value, $boolean); } @@ -1345,16 +1013,13 @@ public function orWhereYear(string $key, mixed $operator, mixed $value = null, s /** * Add a "sort" clause to the query. * - * @param string $key - * @param string $direction - * - * @return self * @throws InvalidParamsException */ public function orderBy(string $key, string $direction = 'asc'): self { if (!in_array($direction, ['asc', 'desc'])) { $message = 'Expected `asc` or `desc` as order direction. `' . $direction . '` given.'; + throw new InvalidParamsException($message); } @@ -1368,9 +1033,6 @@ public function orderBy(string $key, string $direction = 'asc'): self /** * Add a "sort desc" clause to the query. * - * @param string $key - * - * @return self * @throws InvalidParamsException */ public function orderByDesc(string $key): self @@ -1380,30 +1042,27 @@ public function orderByDesc(string $key): self /** * Add an "expand" clause to the query. - * - * @param array $relationships - * - * @return self */ public function with(array $relationships): self { - $relationships = (array)collect($relationships)->mapWithKeys(function ( + $relationships = collect($relationships)->mapWithKeys(function ( $fields, - $relationship + $relationship, ) { if (is_numeric($relationship)) { return [$fields => ['*']]; } + return [$relationship => $fields]; })->map(function ($fields, $relationship) { if (collect($fields)->count() === 0) { $fields = ['*']; } - return collect($fields)->map(function ($field) use ($relationship) { - return $relationship . '.' . $field; - })->implode(','); - })->values(); + return collect($fields)->map(fn ($field) => $relationship . '.' . $field)->implode(','); + }) + ->values() + ->toArray(); $select = $this->query->get('fields', new Collection()); @@ -1416,10 +1075,6 @@ public function with(array $relationships): self /** * Overwrite the cache lifetime for this query. - * - * @param int $seconds - * - * @return self */ public function cache(int $seconds): self { @@ -1430,8 +1085,6 @@ public function cache(int $seconds): self /** * Get the resulting query. - * - * @return string */ public function getQuery(): string { @@ -1440,22 +1093,15 @@ public function getQuery(): string return collect($value)->unique()->implode(' '); } if ($key === 'fields') { - return collect($value)->unique()->sortBy(function ($field) { - return count(explode('.', $field)); - })->implode(','); + return collect($value)->unique()->sortBy(fn ($field) => count(explode('.', $field)))->implode(','); } + return $value; - })->map(function ($value, $key) { - return Str::finish($key . ' ' . $value, ';'); - })->unique()->sort()->implode("\n"); + })->map(fn ($value, $key) => Str::finish($key . ' ' . $value, ';'))->unique()->sort()->implode("\n"); } /** * Set the endpoint as string. - * - * @param string $endpoint - * - * @return self */ public function endpoint(string $endpoint): self { @@ -1467,11 +1113,8 @@ public function endpoint(string $endpoint): self } /** - * Set the endpoint from model or string - * - * @param mixed $model + * Set the endpoint from model or string. * - * @return void * @throws ReflectionException * @throws InvalidParamsException */ @@ -1480,7 +1123,7 @@ protected function setEndpoint(mixed $model): void $neededNamespace = __NAMESPACE__ . '\\Models'; if (is_object($model)) { - $class = get_class($model); + $class = $model::class; $parents = class_parents($model) ? collect(class_parents($model)) : collect(); if ($parents->isEmpty()) { @@ -1495,7 +1138,7 @@ protected function setEndpoint(mixed $model): void $reflectionNamespace = $reflectionClass->getNamespaceName(); if (Str::startsWith($reflectionNamespace, $neededNamespace)) { - $this->class = get_class($model); + $this->class = $model::class; $class = class_basename($this->class); $this->endpoint = Str::snake(Str::plural($class)); } @@ -1505,32 +1148,30 @@ protected function setEndpoint(mixed $model): void if (!isset($this->endpoint)) { $message = 'Construction-Parameter of Builder must be a string or a Class which extends ' . $neededNamespace . '\\Model. ' . ucfirst(gettype($model)) . ' given.'; + throw new InvalidArgumentException($message); } } /** * Cast a value as date. - * - * @param mixed $date - * - * @return mixed */ private function castDate(mixed $date): mixed { if (is_string($date)) { return Carbon::parse($date)->timestamp; } + if ($date instanceof Carbon) { return $date->timestamp; } + return $date; } /** * Execute the query. * - * @return mixed * @throws MissingEndpointException */ public function get(): mixed @@ -1538,9 +1179,7 @@ public function get(): mixed $data = $this->fetchApi(); if (isset($this->class) && $this->class) { - $data = collect($data)->map(function ($result) { - return $this->mapToModel($result); - }); + $data = collect($data)->map(fn ($result) => $this->mapToModel($result)); } $this->init(); @@ -1548,11 +1187,6 @@ public function get(): mixed return $data; } - /** - * @param mixed $result - * - * @return mixed - */ private function mapToModel(mixed $result): mixed { $model = $this->class; @@ -1568,10 +1202,10 @@ private function mapToModel(mixed $result): mixed /** * Execute a query for a single record by ID. * - * @param int $id - * - * @return mixed - * @throws MissingEndpointException|ReflectionException|JsonException|InvalidParamsException + * @throws MissingEndpointException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function find(int $id): mixed { @@ -1579,10 +1213,11 @@ public function find(int $id): mixed } /** - * @param int $id - * - * @return mixed - * @throws MissingEndpointException|ModelNotFoundException|ReflectionException|JsonException|InvalidParamsException + * @throws MissingEndpointException + * @throws ModelNotFoundException + * @throws ReflectionException + * @throws JsonException + * @throws InvalidParamsException */ public function findOrFail(int $id): mixed { @@ -1606,7 +1241,6 @@ public function findOrFail(int $id): mixed /** * Execute the query and get the first result. * - * @return mixed * @throws MissingEndpointException */ public function first(): mixed @@ -1617,7 +1251,6 @@ public function first(): mixed } /** - * @return mixed * @throws MissingEndpointException * @throws ModelNotFoundException */ @@ -1643,7 +1276,6 @@ public function firstOrFail(): mixed /** * Return the total "count" result of the query. * - * @return mixed * @throws MissingEndpointException */ public function count(): mixed @@ -1656,7 +1288,6 @@ public function count(): mixed } /** - * @return Collection * @throws MissingEndpointException */ public function all(): Collection @@ -1667,9 +1298,6 @@ public function all(): Collection } /** - * @param int $limit - * - * @return Paginator * @throws MissingEndpointException */ public function paginate(int $limit = 10): Paginator @@ -1692,9 +1320,6 @@ public function paginate(int $limit = 10): Paginator } /** - * @param bool $count - * - * @return mixed * @throws MissingEndpointException */ private function fetchApi(bool $count = false): mixed @@ -1725,11 +1350,6 @@ private function fetchApi(bool $count = false): mixed }); } - /** - * @param bool $count - * - * @return string - */ private function getEndpoint(bool $count = false): string { $endpoint = $this->endpoint; @@ -1741,11 +1361,6 @@ private function getEndpoint(bool $count = false): string return $endpoint; } - /** - * @param string $endpoint - * - * @return string - */ private function handleCache(string $endpoint): string { $cacheKey = 'igdb_cache.' . md5($endpoint . $this->getQuery()); diff --git a/src/Console/CreateWebhook.php b/src/Console/CreateWebhook.php index 73e01be..e04e69b 100644 --- a/src/Console/CreateWebhook.php +++ b/src/Console/CreateWebhook.php @@ -1,10 +1,13 @@ option('method') ?? $this->choice('For which event do you want to create the webhook?', - $methods, 'update'); + $method = $this->option('method') ?? $this->choice( + 'For which event do you want to create the webhook?', + $methods, + 'update', + ); if (!in_array($method, $methods, true)) { $this->error((new InvalidWebhookMethodException())->getMessage()); + return 1; } + $mappedMethod = match ($method) { + 'create' => Method::CREATE, + 'update' => Method::UPDATE, + 'delete' => Method::DELETE, + }; + try { - $class::createWebhook($method); + $class::createWebhook($mappedMethod); } catch (Exception $e) { $this->error($e->getMessage()); @@ -77,9 +87,6 @@ public function handle(): int return 0; } - /** - * @return array - */ private function getModels(): array { $pattern = '/\/(?:Model|Search|Webhook|Image)\.php$/'; @@ -92,17 +99,10 @@ private function getModels(): array $grep = preg_grep($pattern, $glob, PREG_GREP_INVERT); return collect($grep ?: []) - ->map(function ($path) { - return basename($path, '.php'); - }) + ->map(fn ($path) => basename($path, '.php')) ->toArray(); } - /** - * @param string $model - * - * @return string - */ private function getClosestModel(string $model): string { return collect($this->getModels())->map(function ($m) use ($model) { @@ -110,12 +110,10 @@ private function getClosestModel(string $model): string 'model' => $m, 'levenshtein' => levenshtein($m, $model), ]; - })->filter(function ($m) { - return $m['levenshtein'] <= 5; - })->sortBy(function ($m) { - return $m['levenshtein']; - })->map(function ($m) { - return $m['model']; - })->first(); + }) + ->filter(fn ($m) => $m['levenshtein'] <= 5) + ->sortBy(fn ($m) => $m['levenshtein']) + ->map(fn ($m) => $m['model']) + ->first(); } } diff --git a/src/Console/DeleteWebhook.php b/src/Console/DeleteWebhook.php index 9c8ff63..4d2bda7 100644 --- a/src/Console/DeleteWebhook.php +++ b/src/Console/DeleteWebhook.php @@ -1,5 +1,7 @@ argument('id'); + $id = (int) $this->argument('id'); if ($id) { return $this->deleteOne($id); @@ -35,22 +34,19 @@ public function handle(): int return 0; } - /** - * @param int $id - * - * @return int - */ private function deleteOne(int $id): int { $webhook = Webhook::find($id); if (!$webhook instanceof Webhook) { $this->error('Webhook not found.'); + return 1; } if (!$webhook->delete()) { $this->error('Webhook could not be deleted.'); + return 1; } @@ -59,9 +55,6 @@ private function deleteOne(int $id): int return 0; } - /** - * @return int - */ private function deleteAll(): int { $webhooks = Webhook::all(); @@ -74,7 +67,7 @@ private function deleteAll(): int $this->comment('Deleting all your registered webhooks ...'); - $this->withProgressBar($webhooks, function (Webhook $webhook) { + $this->withProgressBar($webhooks, function (Webhook $webhook): void { $webhook->delete(); }); diff --git a/src/Console/ListWebhooks.php b/src/Console/ListWebhooks.php index da890ba..b026cac 100644 --- a/src/Console/ListWebhooks.php +++ b/src/Console/ListWebhooks.php @@ -1,5 +1,7 @@ error('Webhook not found.'); + return 1; } if ($webhook->active) { $this->info('Webhook does not need to be reactivated.'); + return 0; } @@ -55,7 +55,7 @@ public function handle(): int try { $class::createWebhook($method); - } catch (AuthenticationException | InvalidWebhookMethodException | WebhookSecretMissingException $e) { + } catch (AuthenticationException | WebhookSecretMissingException $e) { $this->error($e->getMessage()); return 1; diff --git a/src/Enums/AgeRating/Category.php b/src/Enums/AgeRating/Category.php index 2b2c7b6..b7a18d2 100644 --- a/src/Enums/AgeRating/Category.php +++ b/src/Enums/AgeRating/Category.php @@ -1,9 +1,11 @@ data = $data; diff --git a/src/Events/AgeRatingContentDescriptionDeleted.php b/src/Events/AgeRatingContentDescriptionDeleted.php index 41914fa..514b776 100644 --- a/src/Events/AgeRatingContentDescriptionDeleted.php +++ b/src/Events/AgeRatingContentDescriptionDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/AgeRatingDeleted.php b/src/Events/AgeRatingDeleted.php index 1a52b26..adfedd6 100644 --- a/src/Events/AgeRatingDeleted.php +++ b/src/Events/AgeRatingDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/AlternativeNameDeleted.php b/src/Events/AlternativeNameDeleted.php index cb3af72..3276f77 100644 --- a/src/Events/AlternativeNameDeleted.php +++ b/src/Events/AlternativeNameDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/ArtworkDeleted.php b/src/Events/ArtworkDeleted.php index d247dc8..7318242 100644 --- a/src/Events/ArtworkDeleted.php +++ b/src/Events/ArtworkDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CharacterDeleted.php b/src/Events/CharacterDeleted.php index b1c8d96..09fdbfa 100644 --- a/src/Events/CharacterDeleted.php +++ b/src/Events/CharacterDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CharacterMugShotDeleted.php b/src/Events/CharacterMugShotDeleted.php index e74b10d..a760548 100644 --- a/src/Events/CharacterMugShotDeleted.php +++ b/src/Events/CharacterMugShotDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CollectionDeleted.php b/src/Events/CollectionDeleted.php index 15fe290..417fea0 100644 --- a/src/Events/CollectionDeleted.php +++ b/src/Events/CollectionDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/CollectionMembershipDeleted.php b/src/Events/CollectionMembershipDeleted.php new file mode 100644 index 0000000..bf5e98f --- /dev/null +++ b/src/Events/CollectionMembershipDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/CollectionMembershipTypeDeleted.php b/src/Events/CollectionMembershipTypeDeleted.php new file mode 100644 index 0000000..cb93e09 --- /dev/null +++ b/src/Events/CollectionMembershipTypeDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/CollectionRelationDeleted.php b/src/Events/CollectionRelationDeleted.php new file mode 100644 index 0000000..298bf9c --- /dev/null +++ b/src/Events/CollectionRelationDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/CollectionRelationTypeDeleted.php b/src/Events/CollectionRelationTypeDeleted.php new file mode 100644 index 0000000..eafc214 --- /dev/null +++ b/src/Events/CollectionRelationTypeDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/CollectionTypeDeleted.php b/src/Events/CollectionTypeDeleted.php new file mode 100644 index 0000000..95e2ceb --- /dev/null +++ b/src/Events/CollectionTypeDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/CompanyDeleted.php b/src/Events/CompanyDeleted.php index 0c30038..5c2b437 100644 --- a/src/Events/CompanyDeleted.php +++ b/src/Events/CompanyDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CompanyLogoDeleted.php b/src/Events/CompanyLogoDeleted.php index dde5ca3..579253d 100644 --- a/src/Events/CompanyLogoDeleted.php +++ b/src/Events/CompanyLogoDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CompanyWebsiteDeleted.php b/src/Events/CompanyWebsiteDeleted.php index a330625..6f62c30 100644 --- a/src/Events/CompanyWebsiteDeleted.php +++ b/src/Events/CompanyWebsiteDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/CoverDeleted.php b/src/Events/CoverDeleted.php index 44ad79f..0e7a1b9 100644 --- a/src/Events/CoverDeleted.php +++ b/src/Events/CoverDeleted.php @@ -1,8 +1,9 @@ class = get_class($this); + $this->class = static::class; $this->url = $request->fullUrl(); /** @var string $method */ $method = $request->route('method'); diff --git a/src/Events/EventCreated.php b/src/Events/EventCreated.php new file mode 100644 index 0000000..103b538 --- /dev/null +++ b/src/Events/EventCreated.php @@ -0,0 +1,26 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/EventDeleted.php b/src/Events/EventDeleted.php new file mode 100644 index 0000000..391acde --- /dev/null +++ b/src/Events/EventDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/EventLogoDeleted.php b/src/Events/EventLogoDeleted.php new file mode 100644 index 0000000..c9cd3ff --- /dev/null +++ b/src/Events/EventLogoDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/EventNetworkDeleted.php b/src/Events/EventNetworkDeleted.php new file mode 100644 index 0000000..7e51688 --- /dev/null +++ b/src/Events/EventNetworkDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/ExternalGameDeleted.php b/src/Events/ExternalGameDeleted.php index 11543ed..916abea 100644 --- a/src/Events/ExternalGameDeleted.php +++ b/src/Events/ExternalGameDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/FranchiseDeleted.php b/src/Events/FranchiseDeleted.php index aa0a4d2..974f0e5 100644 --- a/src/Events/FranchiseDeleted.php +++ b/src/Events/FranchiseDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameDeleted.php b/src/Events/GameDeleted.php index 149b5ee..6f37469 100644 --- a/src/Events/GameDeleted.php +++ b/src/Events/GameDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameEngineDeleted.php b/src/Events/GameEngineDeleted.php index 480623c..e6520da 100644 --- a/src/Events/GameEngineDeleted.php +++ b/src/Events/GameEngineDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameEngineLogoDeleted.php b/src/Events/GameEngineLogoDeleted.php index 9b44c8c..5424606 100644 --- a/src/Events/GameEngineLogoDeleted.php +++ b/src/Events/GameEngineLogoDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/GameLocalizationDeleted.php b/src/Events/GameLocalizationDeleted.php new file mode 100644 index 0000000..19512f0 --- /dev/null +++ b/src/Events/GameLocalizationDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/GameModeDeleted.php b/src/Events/GameModeDeleted.php index 5c5e20e..232c8ba 100644 --- a/src/Events/GameModeDeleted.php +++ b/src/Events/GameModeDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameVersionDeleted.php b/src/Events/GameVersionDeleted.php index 465c42d..98f70d0 100644 --- a/src/Events/GameVersionDeleted.php +++ b/src/Events/GameVersionDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameVersionFeatureDeleted.php b/src/Events/GameVersionFeatureDeleted.php index 24819ca..8f5ff02 100644 --- a/src/Events/GameVersionFeatureDeleted.php +++ b/src/Events/GameVersionFeatureDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameVersionFeatureValueDeleted.php b/src/Events/GameVersionFeatureValueDeleted.php index c7d8e89..e99b598 100644 --- a/src/Events/GameVersionFeatureValueDeleted.php +++ b/src/Events/GameVersionFeatureValueDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GameVideoDeleted.php b/src/Events/GameVideoDeleted.php index 30d3152..ccdab5c 100644 --- a/src/Events/GameVideoDeleted.php +++ b/src/Events/GameVideoDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/GenreDeleted.php b/src/Events/GenreDeleted.php index be39682..451c390 100644 --- a/src/Events/GenreDeleted.php +++ b/src/Events/GenreDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/InvolvedCompanyDeleted.php b/src/Events/InvolvedCompanyDeleted.php index faa480a..d092caf 100644 --- a/src/Events/InvolvedCompanyDeleted.php +++ b/src/Events/InvolvedCompanyDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/KeywordDeleted.php b/src/Events/KeywordDeleted.php index 2df0051..9e3cf05 100644 --- a/src/Events/KeywordDeleted.php +++ b/src/Events/KeywordDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/LanguageDeleted.php b/src/Events/LanguageDeleted.php new file mode 100644 index 0000000..9c023cb --- /dev/null +++ b/src/Events/LanguageDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/LanguageSupportDeleted.php b/src/Events/LanguageSupportDeleted.php new file mode 100644 index 0000000..55981fd --- /dev/null +++ b/src/Events/LanguageSupportDeleted.php @@ -0,0 +1,9 @@ +data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/LanguageSupportTypeDeleted.php b/src/Events/LanguageSupportTypeDeleted.php new file mode 100644 index 0000000..a31b7c3 --- /dev/null +++ b/src/Events/LanguageSupportTypeDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/MultiplayerModeDeleted.php b/src/Events/MultiplayerModeDeleted.php index 512585d..d0f76d5 100644 --- a/src/Events/MultiplayerModeDeleted.php +++ b/src/Events/MultiplayerModeDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/NetworkTypeDeleted.php b/src/Events/NetworkTypeDeleted.php new file mode 100644 index 0000000..eb5efc7 --- /dev/null +++ b/src/Events/NetworkTypeDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/PlatformDeleted.php b/src/Events/PlatformDeleted.php index ff9e061..46a106e 100644 --- a/src/Events/PlatformDeleted.php +++ b/src/Events/PlatformDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformFamilyDeleted.php b/src/Events/PlatformFamilyDeleted.php index b4e401b..ea480f9 100644 --- a/src/Events/PlatformFamilyDeleted.php +++ b/src/Events/PlatformFamilyDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformLogoDeleted.php b/src/Events/PlatformLogoDeleted.php index 5e0cc28..fcc7b1f 100644 --- a/src/Events/PlatformLogoDeleted.php +++ b/src/Events/PlatformLogoDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformVersionCompanyDeleted.php b/src/Events/PlatformVersionCompanyDeleted.php index a5c900e..3b737f7 100644 --- a/src/Events/PlatformVersionCompanyDeleted.php +++ b/src/Events/PlatformVersionCompanyDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformVersionDeleted.php b/src/Events/PlatformVersionDeleted.php index 1675420..aea83cf 100644 --- a/src/Events/PlatformVersionDeleted.php +++ b/src/Events/PlatformVersionDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformVersionReleaseDateDeleted.php b/src/Events/PlatformVersionReleaseDateDeleted.php index cfa69db..ad9223e 100644 --- a/src/Events/PlatformVersionReleaseDateDeleted.php +++ b/src/Events/PlatformVersionReleaseDateDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlatformWebsiteDeleted.php b/src/Events/PlatformWebsiteDeleted.php index ac00ef3..9dd3ede 100644 --- a/src/Events/PlatformWebsiteDeleted.php +++ b/src/Events/PlatformWebsiteDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/PlayerPerspectiveDeleted.php b/src/Events/PlayerPerspectiveDeleted.php index 9769712..147c6e7 100644 --- a/src/Events/PlayerPerspectiveDeleted.php +++ b/src/Events/PlayerPerspectiveDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/RegionDeleted.php b/src/Events/RegionDeleted.php new file mode 100644 index 0000000..fa62107 --- /dev/null +++ b/src/Events/RegionDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/ReleaseDateDeleted.php b/src/Events/ReleaseDateDeleted.php index ae34e02..edd18e3 100644 --- a/src/Events/ReleaseDateDeleted.php +++ b/src/Events/ReleaseDateDeleted.php @@ -1,8 +1,9 @@ data = $data; + parent::__construct($request); + } +} diff --git a/src/Events/ReleaseDateStatusDeleted.php b/src/Events/ReleaseDateStatusDeleted.php new file mode 100644 index 0000000..8b82de0 --- /dev/null +++ b/src/Events/ReleaseDateStatusDeleted.php @@ -0,0 +1,9 @@ +data = $data; diff --git a/src/Events/ScreenshotDeleted.php b/src/Events/ScreenshotDeleted.php index 074abdc..44b57a6 100644 --- a/src/Events/ScreenshotDeleted.php +++ b/src/Events/ScreenshotDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/ThemeDeleted.php b/src/Events/ThemeDeleted.php index 12d4011..3ba5c75 100644 --- a/src/Events/ThemeDeleted.php +++ b/src/Events/ThemeDeleted.php @@ -1,8 +1,9 @@ data = $data; diff --git a/src/Events/WebsiteDeleted.php b/src/Events/WebsiteDeleted.php index 81dc6e0..31192d0 100644 --- a/src/Events/WebsiteDeleted.php +++ b/src/Events/WebsiteDeleted.php @@ -1,8 +1,9 @@ getConstants()); - $message = 'Method must be one of ' . implode(', ', $allowedMethods); + $message = 'Method must be one of ' . implode(', ', ['create', 'update', 'delete']); parent::__construct($message); } } diff --git a/src/Exceptions/InvalidWebhookSecretException.php b/src/Exceptions/InvalidWebhookSecretException.php index 311cec3..f3f03f2 100644 --- a/src/Exceptions/InvalidWebhookSecretException.php +++ b/src/Exceptions/InvalidWebhookSecretException.php @@ -1,5 +1,7 @@ publishes([ __DIR__ . '/../config/config.php' => config_path('igdb.php'), ], 'igdb:config'); - Route::group($this->routeConfiguration(), function () { - $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); + Route::group($this->routeConfiguration(), function (): void { + $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); }); if ($this->app->runningInConsole()) { @@ -39,19 +35,14 @@ public function boot(): void } } - /** - * Register services. - * - * @return void - */ public function register(): void { $this->mergeConfigFrom( - __DIR__ . '/../config/config.php', 'igdb' + __DIR__ . '/../config/config.php', + 'igdb', ); } - #[ArrayShape(['prefix' => "\Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed"])] protected function routeConfiguration(): array { return [ diff --git a/src/Interfaces/ModelInterface.php b/src/Interfaces/ModelInterface.php index 005d407..2354b5c 100644 --- a/src/Interfaces/ModelInterface.php +++ b/src/Interfaces/ModelInterface.php @@ -1,11 +1,10 @@ AgeRatingContentDescription::class, ]; diff --git a/src/Models/AgeRatingContentDescription.php b/src/Models/AgeRatingContentDescription.php index f6e6980..ef0e929 100644 --- a/src/Models/AgeRatingContentDescription.php +++ b/src/Models/AgeRatingContentDescription.php @@ -1,8 +1,9 @@ Game::class, + ]; } diff --git a/src/Models/Artwork.php b/src/Models/Artwork.php index ec101a4..a8f3c76 100644 --- a/src/Models/Artwork.php +++ b/src/Models/Artwork.php @@ -1,8 +1,12 @@ Game::class, + ]; } diff --git a/src/Models/Character.php b/src/Models/Character.php index d187216..46ea65c 100644 --- a/src/Models/Character.php +++ b/src/Models/Character.php @@ -1,13 +1,13 @@ Game::class, 'mug_shot' => CharacterMugShot::class, ]; } diff --git a/src/Models/CharacterMugShot.php b/src/Models/CharacterMugShot.php index 5c3eb64..6018c62 100644 --- a/src/Models/CharacterMugShot.php +++ b/src/Models/CharacterMugShot.php @@ -1,8 +1,9 @@ CollectionRelation::class, + 'as_parent_relations' => CollectionRelation::class, + 'type' => CollectionType::class, + ]; } diff --git a/src/Models/CollectionMembership.php b/src/Models/CollectionMembership.php new file mode 100644 index 0000000..764fd11 --- /dev/null +++ b/src/Models/CollectionMembership.php @@ -0,0 +1,14 @@ + Collection::class, + 'game' => Game::class, + 'type' => CollectionMembershipType::class, + ]; +} diff --git a/src/Models/CollectionMembershipType.php b/src/Models/CollectionMembershipType.php new file mode 100644 index 0000000..606ed10 --- /dev/null +++ b/src/Models/CollectionMembershipType.php @@ -0,0 +1,12 @@ + CollectionType::class, + ]; +} diff --git a/src/Models/CollectionRelation.php b/src/Models/CollectionRelation.php new file mode 100644 index 0000000..7436b13 --- /dev/null +++ b/src/Models/CollectionRelation.php @@ -0,0 +1,14 @@ + Collection::class, + 'parent_collection' => Collection::class, + 'type' => CollectionRelationType::class, + ]; +} diff --git a/src/Models/CollectionRelationType.php b/src/Models/CollectionRelationType.php new file mode 100644 index 0000000..e751bea --- /dev/null +++ b/src/Models/CollectionRelationType.php @@ -0,0 +1,13 @@ + CollectionType::class, + 'allowed_parent_type' => CollectionType::class, + ]; +} diff --git a/src/Models/CollectionType.php b/src/Models/CollectionType.php new file mode 100644 index 0000000..6131ac2 --- /dev/null +++ b/src/Models/CollectionType.php @@ -0,0 +1,9 @@ + self::class, 'developed' => Game::class, + 'logo' => CompanyLogo::class, 'parent' => self::class, 'published' => Game::class, 'websites' => CompanyWebsite::class, diff --git a/src/Models/CompanyLogo.php b/src/Models/CompanyLogo.php index b36190f..8241f68 100644 --- a/src/Models/CompanyLogo.php +++ b/src/Models/CompanyLogo.php @@ -1,8 +1,9 @@ Game::class, + 'game_localization' => GameLocalization::class, + ]; } diff --git a/src/Models/Event.php b/src/Models/Event.php new file mode 100644 index 0000000..4294f4d --- /dev/null +++ b/src/Models/Event.php @@ -0,0 +1,14 @@ + EventLogo::class, + 'games' => Game::class, + 'videos' => GameVideo::class, + ]; +} diff --git a/src/Models/EventLogo.php b/src/Models/EventLogo.php new file mode 100644 index 0000000..4f36ec0 --- /dev/null +++ b/src/Models/EventLogo.php @@ -0,0 +1,12 @@ + Event::class, + ]; +} diff --git a/src/Models/EventNetwork.php b/src/Models/EventNetwork.php new file mode 100644 index 0000000..2ed4b31 --- /dev/null +++ b/src/Models/EventNetwork.php @@ -0,0 +1,13 @@ + Event::class, + 'network_type' => NetworkType::class, + ]; +} diff --git a/src/Models/ExternalGame.php b/src/Models/ExternalGame.php index 4939fc2..879f698 100644 --- a/src/Models/ExternalGame.php +++ b/src/Models/ExternalGame.php @@ -1,8 +1,13 @@ Game::class, + 'platform' => Platform::class, + ]; } diff --git a/src/Models/Franchise.php b/src/Models/Franchise.php index 5f7b2d3..b50479b 100644 --- a/src/Models/Franchise.php +++ b/src/Models/Franchise.php @@ -1,8 +1,12 @@ Game::class, + ]; } diff --git a/src/Models/Game.php b/src/Models/Game.php index 76fd5c3..294d8e6 100644 --- a/src/Models/Game.php +++ b/src/Models/Game.php @@ -1,22 +1,48 @@ AgeRating::class, + 'alternative_names' => AlternativeName::class, + 'artwork' => Artwork::class, 'bundles' => self::class, + 'collection' => Collection::class, + 'collections' => Collection::class, 'cover' => Cover::class, 'dlcs' => self::class, + 'expanded_games' => self::class, 'expansions' => self::class, + 'external_games' => ExternalGame::class, + 'forks' => self::class, + 'franchise' => Franchise::class, + 'franchises' => Franchise::class, + 'game_engines' => GameEngine::class, + 'game_localizations' => GameLocalization::class, + 'game_modes' => GameMode::class, + 'genres' => Genre::class, + 'involved_companies' => InvolvedCompany::class, + 'keywords' => Keyword::class, + 'language_supports' => LanguageSupport::class, + 'multiplayer_modes' => MultiplayerMode::class, 'parent_game' => self::class, + 'platforms' => Platform::class, + 'player_perspectives' => PlayerPerspective::class, + 'ports' => self::class, + 'release_dates' => ReleaseDate::class, 'remakes' => self::class, 'remasters' => self::class, + 'screenshots' => Screenshot::class, 'similar_games' => self::class, 'standalone_expansions' => self::class, + 'tags' => null, + 'themes' => Theme::class, 'version_parent' => self::class, + 'videos' => GameVideo::class, + 'websites' => Website::class, ]; } diff --git a/src/Models/GameEngine.php b/src/Models/GameEngine.php index c9b92ea..152b0de 100644 --- a/src/Models/GameEngine.php +++ b/src/Models/GameEngine.php @@ -1,13 +1,14 @@ Company::class, 'logo' => GameEngineLogo::class, + 'platforms' => Platform::class, ]; } diff --git a/src/Models/GameEngineLogo.php b/src/Models/GameEngineLogo.php index e6618b5..6a7f233 100644 --- a/src/Models/GameEngineLogo.php +++ b/src/Models/GameEngineLogo.php @@ -1,8 +1,9 @@ Cover::class, + 'game' => Game::class, + 'region' => Region::class, + ]; } diff --git a/src/Models/GameMode.php b/src/Models/GameMode.php index 8c45c98..c9d9cbb 100644 --- a/src/Models/GameMode.php +++ b/src/Models/GameMode.php @@ -1,8 +1,9 @@ GameVersionFeature::class, + ]; } diff --git a/src/Models/GameVersionFeature.php b/src/Models/GameVersionFeature.php index 6a3dc37..9c3524d 100644 --- a/src/Models/GameVersionFeature.php +++ b/src/Models/GameVersionFeature.php @@ -1,12 +1,11 @@ GameVersionFeatureValue::class, ]; diff --git a/src/Models/GameVersionFeatureValue.php b/src/Models/GameVersionFeatureValue.php index 50424fd..84a861f 100644 --- a/src/Models/GameVersionFeatureValue.php +++ b/src/Models/GameVersionFeatureValue.php @@ -1,13 +1,13 @@ Game::class, 'game_feature' => GameVersionFeature::class, ]; } diff --git a/src/Models/GameVideo.php b/src/Models/GameVideo.php index 262a070..b6ebbf5 100644 --- a/src/Models/GameVideo.php +++ b/src/Models/GameVideo.php @@ -1,8 +1,12 @@ Game::class, + ]; } diff --git a/src/Models/Genre.php b/src/Models/Genre.php index c1afd6f..5cf60b5 100644 --- a/src/Models/Genre.php +++ b/src/Models/Genre.php @@ -1,8 +1,9 @@ getConstants()); - $sizeFromEnum = $constants->first(function ($value) use ($size) { - return $value === $size; - }); - - if (is_null($sizeFromEnum)) { - throw new InvalidArgumentException("[$size] is not a valid image size."); - } - $basePath = static::IMAGE_BASE_PATH; $id = $this->getAttribute('image_id'); - if (is_null($id)) { + if ($id === null) { throw new PropertyDoesNotExist('Property [image_id] is missing from the response. Make sure you specify `image_id` inside the fields attribute.'); } $id = '' . $id; + $parsedSize = $size->value; + if ($retina) { - $size = Str::finish('' . $sizeFromEnum, '_2x'); + $parsedSize = Str::finish($parsedSize, '_2x'); } - return "$basePath/t_$size/$id.jpg"; + return "$basePath/t_$parsedSize/$id.jpg"; } } diff --git a/src/Models/InvolvedCompany.php b/src/Models/InvolvedCompany.php index 369d15b..825e428 100644 --- a/src/Models/InvolvedCompany.php +++ b/src/Models/InvolvedCompany.php @@ -1,8 +1,13 @@ Company::class, + 'game' => Game::class, + ]; } diff --git a/src/Models/Keyword.php b/src/Models/Keyword.php index 21d3455..44fdb22 100644 --- a/src/Models/Keyword.php +++ b/src/Models/Keyword.php @@ -1,8 +1,9 @@ Game::class, + 'language' => Language::class, + 'language_support_type' => LanguageSupportType::class, + ]; } diff --git a/src/Models/LanguageSupportType.php b/src/Models/LanguageSupportType.php index 0c51f35..048d15d 100644 --- a/src/Models/LanguageSupportType.php +++ b/src/Models/LanguageSupportType.php @@ -6,5 +6,4 @@ class LanguageSupportType extends Model { - // } diff --git a/src/Models/Model.php b/src/Models/Model.php index 95821a1..a6da3f1 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -1,32 +1,30 @@ builder = new Builder($this); - self::$instance = $this; $this->setAttributes($properties); $this->setRelations($properties); @@ -114,203 +105,117 @@ public function __construct(array $properties = []) $this->setEndpoint(); } - /** - * @param string $field - * - * @return mixed - */ public function __get(string $field): mixed { return $this->getAttribute($field); } - /** - * @param string $field - * @param mixed $value - * - * @return void - */ public function __set(string $field, mixed $value): void { $this->attributes[$field] = $value; } - /** - * @param mixed $offset - * - * @return bool - */ - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return isset($this->attributes[$offset]) || isset($this->relations[$offset]); } - /** - * @param mixed $offset - * - * @return mixed - */ - public function offsetGet($offset): mixed + public function offsetGet(mixed $offset): mixed { return $this->getAttribute((string) $offset); } - /** - * @param mixed $offset - * @param mixed $value - * - * @return void - */ - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->attributes[$offset] = $value; } - /** - * @param mixed $offset - * - * @return void - */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { unset($this->attributes[$offset], $this->relations[$offset]); } - /** - * @param mixed $field - * - * @return bool - */ public function __isset(mixed $field): bool { return $this->offsetExists($field); } - /** - * @param mixed $field - * - * @return void - */ public function __unset(mixed $field): void { $this->offsetUnset($field); } /** - * @param mixed $method - * @param mixed $parameters - * - * @return mixed * @throws ReflectionException + * @throws InvalidParamsException */ - public static function __callStatic(mixed $method, mixed $parameters) + public static function __callStatic(mixed $method, mixed $parameters): mixed { - $that = new static; + $that = new static(); + return $that->forwardCallTo($that->newQuery(), $method, $parameters); } - /** - * @return void - */ protected function setIdentifier(): void { - $this->identifier = collect($this->attributes)->get('id'); + $this->identifier = (string) collect($this->attributes)->get('id'); } - /** - * @param array $attributes - * - * @return void - */ protected function setAttributes(array $attributes): void { $this->attributes = collect($attributes)->filter(function ($value) { if (is_array($value)) { - return collect($value)->filter(function ($value) { - return is_object($value); - })->isEmpty(); + return collect($value)->filter(fn ($value) => is_object($value))->isEmpty(); } + return !is_object($value); })->map(function ($value, $key) { $dates = collect($this->dates); if ($dates->contains($key)) { return Carbon::createFromTimestamp($value); } + return $value; })->toArray(); } - /** - * @param array $attributes - * - * @return void - */ protected function setRelations(array $attributes): void { $this->relations = collect($attributes) ->filter(fn ($value, $key) => array_key_exists($key, $this->casts)) ->map(function ($value, $key) { if (is_array($value) && array_is_list($value)) { - return collect($value)->map(function ($value) use ($key) { - return $this->mapToModel($key, $value); - })->filter(); + return collect($value)->map(fn ($value) => $this->mapToModel($key, $value))->filter(); } + return $this->mapToModel($key, $value); }) ->filter(fn (mixed $value): bool => $value instanceof Model || ($value instanceof \Illuminate\Support\Collection && !$value->isEmpty())); } - /** - * @param mixed $object - * @param mixed $method - * @param mixed $parameters - * - * @return mixed - */ public function forwardCallTo(mixed $object, mixed $method, mixed $parameters): mixed { try { return $object->$method(...$parameters); - } catch (Error | BadMethodCallException $e) { + } catch (BadMethodCallException | Error $e) { throw new BadMethodCallException($e->getMessage()); } } /** - * @return Builder - * @throws ReflectionException|InvalidParamsException + * @throws ReflectionException + * @throws InvalidParamsException */ public function newQuery(): Builder { return new Builder($this); } - /** - * @param mixed $fields - * - * @return Model - */ - public function getInstance(mixed $fields): Model - { - return self::$instance; - } - - /** - * @param string $field - * - * @return mixed - */ public function getAttribute(string $field): mixed { return collect($this->attributes)->merge($this->relations)->get($field); } - /** - * @param string $property - * @param mixed $value - * - * @return mixed - */ private function mapToModel(string $property, mixed $value): mixed { $class = $this->getClassNameForProperty($property); @@ -340,17 +245,12 @@ private function mapToModel(string $property, mixed $value): mixed return null; } - /** - * @param string $property - * - * @return bool|null|string - */ - protected function getClassNameForProperty(string $property): bool|null|string + protected function getClassNameForProperty(string $property): bool | string | null { if (collect($this->casts)->has($property)) { $class = collect($this->casts)->get($property); - if (!is_null($class) && class_exists($class)) { + if (null !== $class && class_exists($class)) { return $class; } } @@ -361,7 +261,7 @@ protected function getClassNameForProperty(string $property): bool|null|string return $class; } - $class = __NAMESPACE__ . '\\' . class_basename(get_class($this)) . Str::singular(Str::studly($property)); + $class = __NAMESPACE__ . '\\' . class_basename(static::class) . Str::singular(Str::studly($property)); if (class_exists($class)) { return $class; @@ -370,29 +270,18 @@ protected function getClassNameForProperty(string $property): bool|null|string return false; } - /** - * @param mixed $value - * - * @return array - */ protected function getProperties(mixed $value): array { return collect($value)->toArray(); } - /** - * @return void - */ protected function setEndpoint(): void { - $class = class_basename(get_class($this)); + $class = class_basename(static::class); $this->endpoint = Str::snake(Str::plural($class)); } - /** - * @return string - */ public function getEndpoint(): string { return $this->endpoint; @@ -400,8 +289,6 @@ public function getEndpoint(): string /** * Get the instance as an array. - * - * @return array */ public function toArray(): array { @@ -413,6 +300,7 @@ public function toArray(): array return $relation->toArray(); }); + return $attributes->merge($relations)->sortKeys()->toArray(); } @@ -420,8 +308,6 @@ public function toArray(): array * Convert the object to its JSON representation. * * @param int $options - * - * @return string */ public function toJson($options = 0): string { @@ -429,38 +315,26 @@ public function toJson($options = 0): string } /** - * @param string $method - * @param array $parameters - * - * @return Webhook * @throws AuthenticationException - * @throws InvalidWebhookMethodException * @throws WebhookSecretMissingException * @throws RequestException * @throws Exception */ - public static function createWebhook(string $method, array $parameters = []): Webhook + public static function createWebhook(Method $method, array $parameters = []): Webhook { if (!config('igdb.webhook_secret')) { throw new WebhookSecretMissingException(); } - $self = (new static); + $self = new static(); $routeParameters = array_merge($parameters, [ 'model' => $self->getEndpoint(), - 'method' => $method, + 'method' => $method->value, ]); $url = route('handle-igdb-webhook', $routeParameters); - $reflectionClass = new ReflectionClass(Method::class); - $allowedMethods = array_values($reflectionClass->getConstants()); - - if (!in_array($method, $allowedMethods, true)) { - throw new InvalidWebhookMethodException(); - } - $endpoint = $self->endpoint . '/webhooks'; $client = Http::withOptions([ @@ -470,11 +344,11 @@ public static function createWebhook(string $method, array $parameters = []): We 'Client-ID' => config('igdb.credentials.client_id'), 'Authorization' => 'Bearer ' . ApiHelper::retrieveAccessToken(), ]) - ->asForm(); + ->asForm(); $response = $client->post($endpoint, [ 'url' => $url, - 'method' => $method, + 'method' => $method->value, 'secret' => config('igdb.webhook_secret'), ])->throw()->json(); diff --git a/src/Models/MultiplayerMode.php b/src/Models/MultiplayerMode.php index 5b2b7d7..d809135 100644 --- a/src/Models/MultiplayerMode.php +++ b/src/Models/MultiplayerMode.php @@ -1,8 +1,13 @@ Game::class, + 'platform' => Platform::class, + ]; } diff --git a/src/Models/NetworkType.php b/src/Models/NetworkType.php new file mode 100644 index 0000000..229648a --- /dev/null +++ b/src/Models/NetworkType.php @@ -0,0 +1,12 @@ + EventNetwork::class, + ]; +} diff --git a/src/Models/Platform.php b/src/Models/Platform.php index 4325687..c54ee08 100644 --- a/src/Models/Platform.php +++ b/src/Models/Platform.php @@ -1,13 +1,15 @@ PlatformFamily::class, + 'platform_logo' => PlatformLogo::class, + 'versions' => PlatformVersion::class, 'websites' => PlatformWebsite::class, ]; } diff --git a/src/Models/PlatformFamily.php b/src/Models/PlatformFamily.php index d413595..160d2d0 100644 --- a/src/Models/PlatformFamily.php +++ b/src/Models/PlatformFamily.php @@ -1,8 +1,9 @@ PlatformVersionCompany::class, 'main_manufacturer' => PlatformVersionCompany::class, + 'platform_logo' => PlatformLogo::class, + 'platform_version_release_dates' => PlatformVersionReleaseDate::class, ]; } diff --git a/src/Models/PlatformVersionCompany.php b/src/Models/PlatformVersionCompany.php index a9df15a..3438e36 100644 --- a/src/Models/PlatformVersionCompany.php +++ b/src/Models/PlatformVersionCompany.php @@ -1,8 +1,12 @@ Company::class, + ]; } diff --git a/src/Models/PlatformVersionReleaseDate.php b/src/Models/PlatformVersionReleaseDate.php index 6ff3ee6..83ff76a 100644 --- a/src/Models/PlatformVersionReleaseDate.php +++ b/src/Models/PlatformVersionReleaseDate.php @@ -1,8 +1,12 @@ PlatformVersion::class, + ]; } diff --git a/src/Models/PlatformWebsite.php b/src/Models/PlatformWebsite.php index 789545c..6b885c6 100644 --- a/src/Models/PlatformWebsite.php +++ b/src/Models/PlatformWebsite.php @@ -1,8 +1,9 @@ Game::class, + 'platform' => Platform::class, + 'status' => ReleaseDateStatus::class, + ]; } diff --git a/src/Models/ReleaseDateStatus.php b/src/Models/ReleaseDateStatus.php new file mode 100644 index 0000000..4b1bae8 --- /dev/null +++ b/src/Models/ReleaseDateStatus.php @@ -0,0 +1,9 @@ + Game::class, + ]; } diff --git a/src/Models/Search.php b/src/Models/Search.php index 0224b64..05f4990 100644 --- a/src/Models/Search.php +++ b/src/Models/Search.php @@ -1,8 +1,17 @@ Character::class, + 'collection' => Collection::class, + 'company' => Company::class, + 'game' => Game::class, + 'platform' => Platform::class, + 'theme' => Theme::class, + ]; } diff --git a/src/Models/Theme.php b/src/Models/Theme.php index f049fd6..5adb4fd 100644 --- a/src/Models/Theme.php +++ b/src/Models/Theme.php @@ -1,8 +1,9 @@ withHeaders([ 'Accept' => 'application/json', 'Client-ID' => config('igdb.credentials.client_id'), - 'Authorization' => 'Bearer '.ApiHelper::retrieveAccessToken(), + 'Authorization' => 'Bearer ' . ApiHelper::retrieveAccessToken(), ]); $this->fill(...$parameters); } - /** - * @return \Illuminate\Support\Collection - */ public static function all(): \Illuminate\Support\Collection { - $self = new static; + $self = new static(); $response = $self->client->get('webhooks'); if ($response->failed()) { return new \Illuminate\Support\Collection(); } + return $self->mapToModel(collect($response->json())); } - /** - * @param int $id - * - * @return mixed - */ public static function find(int $id): mixed { - $self = new static; - $response = $self->client->get('webhooks/'.$id); + $self = new static(); + $response = $self->client->get('webhooks/' . $id); if ($response->failed()) { return null; } + return $self->mapToModel(collect($response->json()))->first(); } - /** - * @return mixed - */ public function delete(): mixed { if (!$this->id) { return false; } - $self = new static; + $self = new static(); - $response = $self->client->delete('webhooks/'.$this->id)->json(); + $response = $self->client->delete('webhooks/' . $this->id)->json(); if (!$response) { return false; @@ -154,7 +106,7 @@ public static function handle(Request $request): mixed } $className = Str::singular(Str::studly($endpoint)); - $fullClassName = '\\MarcReichel\\IGDBLaravel\\Models\\'.$className; + $fullClassName = 'MarcReichel\\IGDBLaravel\\Models\\' . $className; if (!class_exists($fullClassName)) { return $data; @@ -164,14 +116,15 @@ public static function handle(Request $request): mixed $method = $request->route('method'); $entity = new $fullClassName($data); - $reflectionClass = new ReflectionClass(Method::class); - $allowedMethods = array_values($reflectionClass->getConstants()); + $allowedMethods = collect(Method::cases()) + ->map(static fn (Method $method) => $method->value) + ->toArray(); if (!$method || !in_array($method, $allowedMethods, true)) { return $entity; } - $event = '\\MarcReichel\\IGDBLaravel\\Events\\'.$className.ucfirst(strtolower($method)).'d'; + $event = 'MarcReichel\\IGDBLaravel\\Events\\' . $className . ucfirst(strtolower($method)) . 'd'; if (!class_exists($event)) { return $entity; @@ -196,9 +149,6 @@ public static function validate(Request $request): void throw new InvalidWebhookSecretException(); } - /** - * @return string - */ public function getModel(): string { $reflectionCategory = new ReflectionClass(Category::class); @@ -213,53 +163,39 @@ public function getModel(): string return $category; } - /** - * @return string - */ - public function getMethod(): string + public function getMethod(): Method { - $reflectionMethod = new ReflectionClass(Method::class); - $methods = collect($reflectionMethod->getConstants())->values(); - - $method = $methods->get($this->sub_category); - - if (!is_string($method)) { - return (string) $this->sub_category; - } + return match ($this->sub_category) { + 1 => Method::DELETE, + 2 => Method::UPDATE, + default => Method::CREATE, + }; + } - return $method; + public function getSubCategory(): int + { + return $this->sub_category; } - #[ArrayShape([ - 'id' => "int", - 'url' => "string", - 'category' => "int|mixed", - 'sub_category' => "int|mixed", - 'number_of_retries' => "int", - 'active' => "bool", - ])] public function toArray(): array { return [ 'id' => $this->id, 'url' => $this->url, 'category' => $this->getModel(), - 'sub_category' => $this->getMethod(), + 'sub_category' => $this->sub_category, 'number_of_retries' => $this->number_of_retries, 'active' => $this->active, ]; } - /** - * @param mixed ...$parameters - */ private function fill(mixed ...$parameters): void { if ($parameters) { foreach ($parameters as $parameter => $value) { if (property_exists($this, (string) $parameter)) { if (is_string($value) && in_array($parameter, ['created_at', 'updated_at'])) { - $this->{$parameter} = new Carbon($value); + $this->{$parameter} = (string) new Carbon($value); } else { $this->{$parameter} = $value; } diff --git a/src/Models/Website.php b/src/Models/Website.php index c04c705..f9fb56c 100644 --- a/src/Models/Website.php +++ b/src/Models/Website.php @@ -1,8 +1,12 @@ Game::class, + ]; } diff --git a/src/Traits/DateCasts.php b/src/Traits/DateCasts.php index d29ae36..1a5004e 100644 --- a/src/Traits/DateCasts.php +++ b/src/Traits/DateCasts.php @@ -1,13 +1,13 @@ 'date', diff --git a/src/Traits/HasAttributes.php b/src/Traits/HasAttributes.php index 3e0dab1..bada51e 100644 --- a/src/Traits/HasAttributes.php +++ b/src/Traits/HasAttributes.php @@ -1,17 +1,12 @@ Http::response([ 'access_token' => 'test-suite-token', - 'expires_in' => 3600 + 'expires_in' => 3600, ]), ]); diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 2b808bb..3ae85db 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -1,5 +1,7 @@ Http::response([ 'access_token' => 'test-suite-token', - 'expires_in' => 3600 + 'expires_in' => 3600, ]), - '*/games/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/companies/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/artworks/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, + '*/games/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/companies/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/artworks/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), '*/webhooks' => Http::response(), '*/count' => Http::response(['count' => 1337]), '*/companies' => Http::response(['id' => 1337, 'name' => 'Fortnite']), @@ -51,275 +47,224 @@ public function setUp(): void } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_fields_query(): void + public function testItShouldGenerateFieldsQuery(): void { $this->igdb->select(['name'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'fields name;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields name;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_asterisk_fields_query_with_empty_fields(): void + public function testItShouldGenerateAsteriskFieldsQueryWithEmptyFields(): void { $this->igdb->select([])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'fields *;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_filter_expended_field_query(): void + public function testItShouldFilterExpendedFieldQuery(): void { $this->igdb->select(['company.logo.*'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'fields *;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_search_query(): void + public function testItShouldGenerateSearchQuery(): void { $this->igdb->search('Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'search "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'search "Fortnite";')); } /** - * @test * @throws MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_fuzzy_search_query(): void + public function testItShouldGenerateFuzzySearchQuery(): void { $this->igdb->fuzzySearch(['name', 'company'], 'phpunit test')->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where (name ~ *"phpunit"* | name ~ *"test"* | company ~ *"phpunit"* | company ~ *"test"*);'); + return $this->isApiCall( + $request, + 'games', + 'where (name ~ *"phpunit"* | name ~ *"test"* | company ~ *"phpunit"* | company ~ *"test"*);', + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_or_fuzzy_search_query(): void + public function testItShouldGenerateOrFuzzySearchQuery(): void { $this->igdb->where('name', 'Fortnite')->orFuzzySearch(['name', 'company'], 'phpunit test')->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" | (name ~ *"phpunit"* | name ~ *"test"* | company ~ *"phpunit"* | company ~ *"test"*);'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" | (name ~ *"phpunit"* | name ~ *"test"* | company ~ *"phpunit"* | company ~ *"test"*);', + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_equals_query_with_operator(): void + public function testItShouldGenerateWhereEqualsQueryWithOperator(): void { $this->igdb->where('name', '=', 'Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite";')); $timestamp = Carbon::now()->timestamp; $this->igdb->where('first_release_date', '>=', $timestamp)->get(); - Http::assertSent(function (Request $request) use ($timestamp) { - return $this->isApiCall($request, 'games', "where first_release_date >= $timestamp;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date >= $timestamp;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_nested_where_query(): void + public function testItShouldGenerateNestedWhereQuery(): void { $now = Carbon::now()->timestamp; $nextYear = Carbon::now()->addYear()->timestamp; - $this->igdb->where(function ($query) use ($now, $nextYear) { + $this->igdb->where(function ($query) use ($now, $nextYear): void { $query->where('first_release_date', '>=', $now) ->where('first_release_date', '<=', $nextYear); })->orWhere('name', 'Fortnite')->get(); Http::assertSent(function (Request $request) use ($now, $nextYear) { - return $this->isApiCall($request, 'games', - "where (first_release_date >= $now & first_release_date <= $nextYear) | name = \"Fortnite\";"); + return $this->isApiCall( + $request, + 'games', + "where (first_release_date >= $now & first_release_date <= $nextYear) | name = \"Fortnite\";", + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_equals_query_without_operator(): void + public function testItShouldGenerateWhereEqualsQueryWithoutOperator(): void { $this->igdb->where('name', 'Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite";')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_fill_up_fields_from_where_clause(): void + public function testItShouldFillUpFieldsFromWhereClause(): void { $this->igdb->select('company')->where('name', 'Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields company,name;\nwhere name = \"Fortnite\";"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "fields company,name;\nwhere name = \"Fortnite\";")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_and_where_query(): void + public function testItShouldGenerateAndWhereQuery(): void { $this->igdb->where('name', 'Fortnite')->where('name', 'Borderlands 2')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" & name = "Borderlands 2";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" & name = "Borderlands 2";')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_or_where_query(): void + public function testItShouldGenerateOrWhereQuery(): void { $this->igdb->where('name', 'Fortnite')->orWhere('name', 'Borderlands 2')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = "Borderlands 2";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = "Borderlands 2";')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_like_queries_via_normal_where_method(): void + public function testItShouldGenerateWhereLikeQueriesViaNormalWhereMethod(): void { $this->igdb->where('name', 'like', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = *"Fort"*;')); $this->igdb->where('name', 'ilike', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name ~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name ~ *"Fort"*;')); $this->igdb->where('name', 'not like', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name != *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name != *"Fort"*;')); $this->igdb->where('name', 'not ilike', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name !~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name !~ *"Fort"*;')); } /** - * @test * @throws JsonException|MissingEndpointException */ - public function it_should_generate_where_like_queries_via_where_like_method(): void + public function testItShouldGenerateWhereLikeQueriesViaWhereLikeMethod(): void { $this->igdb->whereLike('name', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = *"Fort"*;')); $this->igdb->whereLike('name', '%Fort%', false)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name ~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name ~ *"Fort"*;')); $this->igdb->whereNotLike('name', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name != *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name != *"Fort"*;')); $this->igdb->whereNotLike('name', '%Fort%', false)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name !~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name !~ *"Fort"*;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_or_where_like_queries_via_or_where_like_methods(): void + public function testItShouldGenerateOrWhereLikeQueriesViaOrWhereLikeMethods(): void { $this->igdb->where('name', 'Fortnite')->orWhereLike('name', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = *"Fort"*;')); $this->igdb->where('name', 'Fortnite')->orWhereLike('name', '%Fort%', false)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name ~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name ~ *"Fort"*;')); $this->igdb->where('name', 'Fortnite')->orWhereNotLike('name', '%Fort%')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name != *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name != *"Fort"*;')); $this->igdb->where('name', 'Fortnite')->orWhereNotLike('name', '%Fort%', false)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name !~ *"Fort"*;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name !~ *"Fort"*;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_throw_exception_with_invalid_operator_and_value_combination(): void + public function testItShouldThrowExceptionWithInvalidOperatorAndValueCombination(): void { $this->expectException(InvalidArgumentException::class); @@ -327,211 +272,183 @@ public function it_should_throw_exception_with_invalid_operator_and_value_combin } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_between_query(): void + public function testItShouldGenerateWhereBetweenQuery(): void { $this->igdb->whereBetween('first_release_date', 1546297200, 1577833199)->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where (first_release_date >= 1546297200 & first_release_date <= 1577833199);'); + return $this->isApiCall( + $request, + 'games', + 'where (first_release_date >= 1546297200 & first_release_date <= 1577833199);', + ); }); $this->igdb->where('name', 'Fortnite')->orWhereBetween('first_release_date', 1546297200, 1577833199)->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" | (first_release_date >= 1546297200 & first_release_date <= 1577833199);'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" | (first_release_date >= 1546297200 & first_release_date <= 1577833199);', + ); }); $this->igdb->whereNotBetween('first_release_date', 1546297200, 1577833199)->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where (first_release_date < 1546297200 | first_release_date > 1577833199);'); + return $this->isApiCall( + $request, + 'games', + 'where (first_release_date < 1546297200 | first_release_date > 1577833199);', + ); }); $this->igdb->where('name', 'Fortnite')->orWhereNotBetween('first_release_date', 1546297200, 1577833199)->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" | (first_release_date < 1546297200 | first_release_date > 1577833199);'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" | (first_release_date < 1546297200 | first_release_date > 1577833199);', + ); }); } /** - * @test * @throws MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_between_query_without_boundaries(): void + public function testItShouldGenerateWhereBetweenQueryWithoutBoundaries(): void { $this->igdb->whereBetween('first_release_date', 1546297200, 1577833199, false)->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where (first_release_date > 1546297200 & first_release_date < 1577833199);'); + return $this->isApiCall( + $request, + 'games', + 'where (first_release_date > 1546297200 & first_release_date < 1577833199);', + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_in_query(): void + public function testItShouldGenerateWhereInQuery(): void { $this->igdb->whereIn('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = (0,4);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = (0,4);')); $this->igdb->where('name', 'Fortnite')->orWhereIn('name', ['Borderlands', 'Call of Duty'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = ("Borderlands","Call of Duty");'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = ("Borderlands","Call of Duty");')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_in_exact_query(): void + public function testItShouldGenerateWhereInExactQuery(): void { $this->igdb->whereInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = {0,4};')); $this->igdb->where('name', 'Fortnite')->orWhereInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | category = {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | category = {0,4};')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_in_all_query(): void + public function testItShouldGenerateWhereInAllQuery(): void { $this->igdb->whereInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = [0,4];')); $this->igdb->where('name', 'Fortnite')->orWhereInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | category = [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | category = [0,4];')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_not_in_query(): void + public function testItShouldGenerateWhereNotInQuery(): void { $this->igdb->whereNotIn('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != (0,4);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != (0,4);')); $this->igdb->where('name', 'Fortnite')->orWhereNotIn('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != (0,4);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != (0,4);')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_not_in_exact_query(): void + public function testItShouldGenerateWhereNotInExactQuery(): void { $this->igdb->whereNotInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != {0,4};')); $this->igdb->where('name', 'Fortnite')->orWhereNotInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != {0,4};')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_not_in_all_query(): void + public function testItShouldGenerateWhereNotInAllQuery(): void { $this->igdb->whereNotInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != [0,4];')); $this->igdb->where('name', 'Fortnite')->orWhereNotInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | category != [0,4];')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_null_query(): void + public function testItShouldGenerateWhereNullQuery(): void { $this->igdb->whereNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date = null;')); $this->igdb->where('name', 'Fortnite')->orWhereNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date = null;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_not_null_query(): void + public function testItShouldGenerateWhereNotNullQuery(): void { $this->igdb->whereNotNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date != null;')); $this->igdb->where('name', 'Fortnite')->orWhereNotNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date != null;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_equals_query(): void + public function testItShouldGenerateWhereDateEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfDay()->timestamp; @@ -540,111 +457,96 @@ public function it_should_generate_where_date_equals_query(): void $this->igdb->whereDate('first_release_date', $date->format('Y-m-d'))->get(); Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', - "where (first_release_date >= $start & first_release_date <= $end);"); + return $this->isApiCall( + $request, + 'games', + "where (first_release_date >= $start & first_release_date <= $end);", + ); }); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', $date->format('Y-m-d'))->get(); Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', - "where name = \"Fortnite\" | (first_release_date >= $start & first_release_date <= $end);"); + return $this->isApiCall( + $request, + 'games', + "where name = \"Fortnite\" | (first_release_date >= $start & first_release_date <= $end);", + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_larger_or_equals_query(): void + public function testItShouldGenerateWhereDateLargerOrEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfDay()->timestamp; $this->igdb->whereDate('first_release_date', '>=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date >= $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date >= $start;")); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', '>=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date >= $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date >= $start;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_larger_query(): void + public function testItShouldGenerateWhereDateLargerQuery(): void { $date = now(); $end = $date->clone()->addDay()->startOfDay()->timestamp; $this->igdb->whereDate('first_release_date', '>', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date > $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date > $end;")); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', '>', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date > $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date > $end;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_smaller_or_equals_query(): void + public function testItShouldGenerateWhereDateSmallerOrEqualsQuery(): void { $date = now(); $end = $date->clone()->endOfDay()->timestamp; $this->igdb->whereDate('first_release_date', '<=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date <= $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date <= $end;")); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', '<=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date <= $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date <= $end;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_smaller_query(): void + public function testItShouldGenerateWhereDateSmallerQuery(): void { $date = now(); $start = $date->clone()->subDay()->endOfDay()->timestamp; $this->igdb->whereDate('first_release_date', '<', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date < $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date < $start;")); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', '<', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date < $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where name = \"Fortnite\" | first_release_date < $start;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_date_not_equals_query(): void + public function testItShouldGenerateWhereDateNotEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfDay()->timestamp; @@ -652,22 +554,17 @@ public function it_should_generate_where_date_not_equals_query(): void $this->igdb->whereDate('first_release_date', '!=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', "where (first_release_date < $start | first_release_date > $end);"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where (first_release_date < $start | first_release_date > $end);")); $this->igdb->where('name', 'Fortnite')->orWhereDate('first_release_date', '!=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', "where name = \"Fortnite\" | (first_release_date < $start | first_release_date > $end);"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where name = \"Fortnite\" | (first_release_date < $start | first_release_date > $end);")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_year_equals_query(): void + public function testItShouldGenerateWhereYearEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; @@ -676,155 +573,141 @@ public function it_should_generate_where_year_equals_query(): void $this->igdb->whereYear('first_release_date', $date->year)->get(); Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', - "where (first_release_date >= $start & first_release_date <= $end);"); + return $this->isApiCall( + $request, + 'games', + "where (first_release_date >= $start & first_release_date <= $end);", + ); }); $this->igdb->where('name', 'Fortnite')->orWhereYear('first_release_date', $date->year)->get(); Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', - "where name = \"Fortnite\" | (first_release_date >= $start & first_release_date <= $end);"); + return $this->isApiCall( + $request, + 'games', + "where name = \"Fortnite\" | (first_release_date >= $start & first_release_date <= $end);", + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_year_larger_or_equals_query(): void + public function testItShouldGenerateWhereYearLargerOrEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; $this->igdb->whereYear('first_release_date', '>=', $date->year)->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date >= $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date >= $start;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_year_larger_query(): void + public function testItShouldGenerateWhereYearLargerQuery(): void { $date = now(); $end = $date->clone()->endOfYear()->timestamp; $this->igdb->whereYear('first_release_date', '>', $date->year)->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date > $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date > $end;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_year_smaller_or_equals_query(): void + public function testItShouldGenerateWhereYearSmallerOrEqualsQuery(): void { $date = now(); $end = $date->clone()->endOfYear()->timestamp; $this->igdb->whereYear('first_release_date', '<=', $date->year)->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date <= $end;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date <= $end;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_year_smaller_query(): void + public function testItShouldGenerateWhereYearSmallerQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; $this->igdb->whereYear('first_release_date', '<', $date->year)->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date < $start;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date < $start;")); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_has_query(): void + public function testItShouldGenerateWhereHasQuery(): void { $this->igdb->whereHas('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date != null;')); $this->igdb->where('name', 'Fortnite')->orWhereHas('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date != null;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_where_has_not_query(): void + public function testItShouldGenerateWhereHasNotQuery(): void { $this->igdb->whereHasNot('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date = null;')); $this->igdb->where('name', 'Fortnite')->orWhereHasNot('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | first_release_date = null;')); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_nested_or_where_query(): void + public function testItShouldGenerateNestedOrWhereQuery(): void { $this->igdb->where('name', 'Fortnite') - ->orWhere(function ($query) { + ->orWhere(function ($query): void { $query->where('aggregated_rating', '>=', 90) ->where('aggregated_rating_count', '>=', 3000); })->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" | (aggregated_rating >= 90 & aggregated_rating_count >= 3000);'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" | (aggregated_rating >= 90 & aggregated_rating_count >= 3000);', + ); }); } /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_array_where_query(): void + public function testItShouldGenerateArrayWhereQuery(): void { $this->igdb->where([['name', 'Fortnite'], ['name', 'Borderlands 2']])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where (name = "Fortnite" & name = "Borderlands 2");'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where (name = "Fortnite" & name = "Borderlands 2");')); $this->igdb->where('name', 'Fortnite')->orWhere([['name', 'Call of Duty'], ['name', 'Borderlands 2']])->get(); Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" | (name = "Call of Duty" & name = "Borderlands 2");'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" | (name = "Call of Duty" & name = "Borderlands 2");', + ); }); $now = Carbon::now()->timestamp; @@ -832,16 +715,18 @@ public function it_should_generate_array_where_query(): void $this->igdb->where('name', 'Fortnite')->where(['name' => 'Borderlands', 'first_release_date' => $now])->get(); Http::assertSent(function (Request $request) use ($now) { - return $this->isApiCall($request, 'games', - 'where name = "Fortnite" & (name = "Borderlands" & first_release_date = ' . $now . ');'); + return $this->isApiCall( + $request, + 'games', + 'where name = "Fortnite" & (name = "Borderlands" & first_release_date = ' . $now . ');', + ); }); } /** - * @test * @throws MissingEndpointException */ - public function it_should_throw_exception_with_invalid_prefix_and_suffix_in_where_in_query(): void + public function testItShouldThrowExceptionWithInvalidPrefixAndSuffixInWhereInQuery(): void { $this->expectException(InvalidArgumentException::class); @@ -849,143 +734,110 @@ public function it_should_throw_exception_with_invalid_prefix_and_suffix_in_wher } /** - * @test * @throws InvalidParamsException * @throws MissingEndpointException */ - public function it_should_generate_orderby_query(): void + public function testItShouldGenerateOrderByQuery(): void { $this->igdb->orderBy('name')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name asc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name asc;')); $this->igdb->orderBy('name', 'desc')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name desc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name desc;')); $this->igdb->orderBy('name')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name asc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name asc;')); } /** - * @test * @throws InvalidParamsException * @throws MissingEndpointException */ - public function it_should_not_generate_orderby_query_with_invalid_params(): void + public function testItShouldNotGenerateOrderByQueryWithInvalidParams(): void { $this->expectException(InvalidParamsException::class); $this->igdb->orderBy('name', 'foo')->get(); - Http::assertNotSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name foo;'); - }); + Http::assertNotSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name foo;')); } /** - * @test * @throws InvalidParamsException * @throws MissingEndpointException */ - public function it_should_generate_orderbydesc_query(): void + public function testItShouldGenerateOrderByDescQuery(): void { $this->igdb->orderByDesc('name')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name desc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name desc;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_offset_query(): void + public function testItShouldGenerateOffsetQuery(): void { $this->igdb->skip(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'offset 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'offset 10;')); $this->igdb->offset(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'offset 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'offset 10;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_limit_query(): void + public function testItShouldGenerateLimitQuery(): void { $this->igdb->take(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'limit 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'limit 10;')); $this->igdb->limit(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'limit 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'limit 10;')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_forPage_query(): void + public function testItShouldGenerateForPageQuery(): void { $this->igdb->forPage(2, 20)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 20;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 20;")); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_all_query(): void + public function testItShouldGenerateAllQuery(): void { $this->igdb->all(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 500;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 500;\noffset 0;")); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_first_query(): void + public function testItShouldGenerateFirstQuery(): void { $this->igdb->first(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 1;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 1;\noffset 0;")); } /** - * @test * @throws MissingEndpointException */ - public function it_should_throw_exception_for_first_or_fail_method(): void + public function testItShouldThrowExceptionForFirstOrFailMethod(): void { $this->expectException(ModelNotFoundException::class); @@ -993,91 +845,71 @@ public function it_should_throw_exception_for_first_or_fail_method(): void } /** - * @test * @throws InvalidParamsException * @throws JsonException * @throws MissingEndpointException * @throws ModelNotFoundException * @throws ReflectionException */ - public function it_should_throw_exception_for_find_or_fail_method(): void + public function testItShouldThrowExceptionForFindOrFailMethod(): void { $this->expectException(ModelNotFoundException::class); $this->igdb->findOrFail(1337); } - /** - * @test * @throws JsonException|MissingEndpointException|ReflectionException|InvalidParamsException */ - public function it_should_generate_find_query(): void + public function testItShouldGenerateFindQuery(): void { $this->igdb->find(1905); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 1;\noffset 0;\nwhere id = 1905;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 1;\noffset 0;\nwhere id = 1905;")); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_paginate_query(): void + public function testItShouldGeneratePaginateQuery(): void { $this->igdb->paginate(20); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 0;")); $this->get('/?page=2'); $this->igdb->paginate(20); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 20;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 20;")); } /** - * @test * @throws MissingEndpointException */ - public function it_should_generate_expanding_query(): void + public function testItShouldGenerateExpandingQuery(): void { $this->igdb->with(['cover', 'artworks'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,cover.*,artworks.*;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,cover.*,artworks.*;')); $this->igdb->with(['involved_companies', 'involved_companies.company'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,involved_companies.*,involved_companies.company.*;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,involved_companies.*,involved_companies.company.*;')); $this->igdb->with(['cover' => ['url'], 'artworks' => ['url']])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,cover.url,artworks.url;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,cover.url,artworks.url;')); $this->igdb->with(['artworks' => [], 'cover' => []])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,artworks.*,cover.*;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,artworks.*,cover.*;')); } /** - * @test * @throws InvalidParamsException|JsonException|MissingEndpointException|ReflectionException */ - public function it_should_overwrite_cache(): void + public function testItShouldOverwriteCache(): void { $builder = $this->igdb->where('name', 'Fortnite Unit Test'); @@ -1089,44 +921,35 @@ public function it_should_overwrite_cache(): void } /** - * @test * @throws InvalidParamsException|JsonException|MissingEndpointException|ReflectionException */ - public function it_should_set_endpoint_later(): void + public function testItShouldSetEndpointLater(): void { $igdb = new Builder(); $igdb->endpoint('artworks')->where('url', 'test')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'artworks', "where url = \"test\";"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'artworks', 'where url = "test";')); } /** - * @test * @throws MissingEndpointException */ - public function it_should_request_count_endpoint(): void + public function testItShouldRequestCountEndpoint(): void { $count = $this->igdb->count(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games/count', 'fields *;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games/count', 'fields *;')); self::assertEquals(1337, $count); } /** - * @test * @throws MissingEndpointException */ - public function it_should_throw_exception_when_no_endpoint_is_set(): void + public function testItShouldThrowExceptionWhenNoEndpointIsSet(): void { $this->expectException(MissingEndpointException::class); - $igdb = new Builder(); - - $igdb->get(); + (new Builder())->get(); } } diff --git a/tests/EventsTest.php b/tests/EventsTest.php new file mode 100644 index 0000000..976907f --- /dev/null +++ b/tests/EventsTest.php @@ -0,0 +1,38 @@ +assertTrue(class_exists($eventClassString)); + } + + /** + * @dataProvider modelsDataProvider + */ + public function testItShouldHaveUpdatedEventForEveryModel(string $className): void + { + $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Updated'; + $this->assertTrue(class_exists($eventClassString)); + } + + /** + * @dataProvider modelsDataProvider + */ + public function testItShouldHaveDeletedEventForEveryModel(string $className): void + { + $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Deleted'; + $this->assertTrue(class_exists($eventClassString)); + } +} diff --git a/tests/ImageTest.php b/tests/ImageTest.php index a7adeea..3dae167 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -1,10 +1,11 @@ getUrl(); self::assertEquals('//images.igdb.com/igdb/image/upload/t_thumb/abc.jpg', $url); } - /** @test */ - public function it_should_generate_desired_image_url_with_parameter(): void + public function testItShouldGenerateDesiredImageUrlWithParameter(): void { $url = Artwork::first()->getUrl(Size::COVER_BIG); self::assertEquals('//images.igdb.com/igdb/image/upload/t_cover_big/abc.jpg', $url); } - /** @test */ - public function it_should_generate_retina_image_url(): void + public function testItShouldGenerateRetinaImageUrl(): void { $url = Artwork::first()->getUrl(Size::COVER_BIG, true); self::assertEquals('//images.igdb.com/igdb/image/upload/t_cover_big_2x/abc.jpg', $url); } - - /** @test */ - public function it_should_throw_exception_with_invalid_image_size(): void - { - $this->expectException(InvalidArgumentException::class); - - Artwork::first()->getUrl('foo'); - } } diff --git a/tests/ModelTest.php b/tests/ModelTest.php index a5765fe..d44b998 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -1,5 +1,7 @@ Http::response([ 'access_token' => 'test-suite-token', - 'expires_in' => 3600 + 'expires_in' => 3600, ]), - '*/games/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/companies/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/artworks/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, + '*/games/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/companies/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/artworks/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), '*/webhooks' => Http::response(), '*/count' => Http::response(['count' => 1337]), '*/companies' => Http::response(['id' => 1337, 'name' => 'Fortnite']), @@ -39,174 +38,123 @@ public function setUp(): void ]); } - /** @test */ - public function it_should_generate_fields_query(): void + public function testItShouldGenerateFieldsQuery(): void { Game::select(['name'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'fields name;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields name;')); } - /** @test */ - public function it_should_generate_search_query(): void + public function testItShouldGenerateSearchQuery(): void { Game::search('Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'search "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'search "Fortnite";')); } - /** @test */ - public function it_should_generate_where_equals_query_with_operator(): void + public function testItShouldGenerateWhereEqualsQueryWithOperator(): void { Game::where('name', '=', 'Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite";')); Game::where('first_release_date', '>=', 1546297200)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date >= 1546297200;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date >= 1546297200;')); } - /** @test */ - public function it_should_generate_where_equals_query_without_operator(): void + public function testItShouldGenerateWhereEqualsQueryWithoutOperator(): void { Game::where('name', 'Fortnite')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite";')); } - /** @test */ - public function it_should_generate_and_where_query(): void + public function testItShouldGenerateAndWhereQuery(): void { Game::where('name', 'Fortnite')->where('name', 'Borderlands 2')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" & name = "Borderlands 2";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" & name = "Borderlands 2";')); } - /** @test */ - public function it_should_generate_or_where_query(): void + public function testItShouldGenerateOrWhereQuery(): void { Game::where('name', 'Fortnite')->orWhere('name', 'Borderlands 2')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = "Borderlands 2";'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | name = "Borderlands 2";')); } - /** @test */ - public function it_should_generate_where_between_query(): void + public function testItShouldGenerateWhereBetweenQuery(): void { Game::whereBetween('first_release_date', 1546297200, 1577833199)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where (first_release_date >= 1546297200 & first_release_date <= 1577833199);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where (first_release_date >= 1546297200 & first_release_date <= 1577833199);')); } - /** @test */ - public function it_should_generate_where_between_query_without_boundaries(): void + public function testItShouldGenerateWhereBetweenQueryWithoutBoundaries(): void { Game::whereBetween('first_release_date', 1546297200, 1577833199, false)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where (first_release_date > 1546297200 & first_release_date < 1577833199);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where (first_release_date > 1546297200 & first_release_date < 1577833199);')); } - /** @test */ - public function it_should_generate_where_in_query(): void + public function testItShouldGenerateWhereInQuery(): void { - Game::whereIn('category', [0,4])->get(); + Game::whereIn('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = (0,4);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = (0,4);')); } - /** @test */ - public function it_should_generate_where_in_exact_query(): void + public function testItShouldGenerateWhereInExactQuery(): void { - Game::whereInExact('category', [0,4])->get(); + Game::whereInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = {0,4};')); } - /** @test */ - public function it_should_generate_where_in_all_query(): void + public function testItShouldGenerateWhereInAllQuery(): void { - Game::whereInAll('category', [0,4])->get(); + Game::whereInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category = [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category = [0,4];')); } - /** @test */ - public function it_should_generate_where_not_in_query(): void + public function testItShouldGenerateWhereNotInQuery(): void { - Game::whereNotIn('category', [0,4])->get(); + Game::whereNotIn('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != (0,4);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != (0,4);')); } - /** @test */ - public function it_should_generate_where_not_in_exact_query(): void + public function testItShouldGenerateWhereNotInExactQuery(): void { - Game::whereNotInExact('category', [0,4])->get(); + Game::whereNotInExact('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != {0,4};'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != {0,4};')); } - /** @test */ - public function it_should_generate_where_not_in_all_query(): void + public function testItShouldGenerateWhereNotInAllQuery(): void { - Game::whereNotInAll('category', [0,4])->get(); + Game::whereNotInAll('category', [0, 4])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where category != [0,4];'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where category != [0,4];')); } - /** @test */ - public function it_should_generate_where_null_query(): void + public function testItShouldGenerateWhereNullQuery(): void { Game::whereNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date = null;')); } - /** @test */ - public function it_should_generate_where_not_null_query(): void + public function testItShouldGenerateWhereNotNullQuery(): void { Game::whereNotNull('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date != null;')); } - /** @test */ - public function it_should_generate_where_date_equals_query(): void + public function testItShouldGenerateWhereDateEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfDay()->timestamp; @@ -214,65 +162,50 @@ public function it_should_generate_where_date_equals_query(): void Game::whereDate('first_release_date', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', "where (first_release_date >= {$start} & first_release_date <= {$end});"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where (first_release_date >= {$start} & first_release_date <= {$end});")); } - /** @test */ - public function it_should_generate_where_date_larger_or_equals_query(): void + public function testItShouldGenerateWhereDateLargerOrEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfDay()->timestamp; Game::whereDate('first_release_date', '>=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date >= {$start};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date >= {$start};")); } - /** @test */ - public function it_should_generate_where_date_larger_query(): void + public function testItShouldGenerateWhereDateLargerQuery(): void { $date = now(); $end = $date->clone()->addDay()->startOfDay()->timestamp; Game::whereDate('first_release_date', '>', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date > {$end};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date > {$end};")); } - /** @test */ - public function it_should_generate_where_date_smaller_or_equals_query(): void + public function testItShouldGenerateWhereDateSmallerOrEqualsQuery(): void { $date = now(); $end = $date->clone()->endOfDay()->timestamp; Game::whereDate('first_release_date', '<=', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date <= {$end};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date <= {$end};")); } - /** @test */ - public function it_should_generate_where_date_smaller_query(): void + public function testItShouldGenerateWhereDateSmallerQuery(): void { $date = now(); $start = $date->clone()->subDay()->endOfDay()->timestamp; Game::whereDate('first_release_date', '<', $date->format('Y-m-d'))->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date < {$start};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date < {$start};")); } - /** @test */ - public function it_should_generate_where_year_equals_query(): void + public function testItShouldGenerateWhereYearEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; @@ -280,293 +213,210 @@ public function it_should_generate_where_year_equals_query(): void Game::whereYear('first_release_date', $date->year)->get(); - Http::assertSent(function (Request $request) use ($start, $end) { - return $this->isApiCall($request, 'games', "where (first_release_date >= {$start} & first_release_date <= {$end});"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where (first_release_date >= {$start} & first_release_date <= {$end});")); } - /** @test */ - public function it_should_generate_where_year_larger_or_equals_query(): void + public function testItShouldGenerateWhereYearLargerOrEqualsQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; Game::whereYear('first_release_date', '>=', $date->year)->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date >= {$start};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date >= {$start};")); } - /** @test */ - public function it_should_generate_where_year_larger_query(): void + public function testItShouldGenerateWhereYearLargerQuery(): void { $date = now(); $end = $date->clone()->endOfYear()->timestamp; Game::whereYear('first_release_date', '>', $date->year)->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date > {$end};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date > {$end};")); } - /** @test */ - public function it_should_generate_where_year_smaller_or_equals_query(): void + public function testItShouldGenerateWhereYearSmallerOrEqualsQuery(): void { $date = now(); $end = $date->clone()->endOfYear()->timestamp; Game::whereYear('first_release_date', '<=', $date->year)->get(); - Http::assertSent(function (Request $request) use ($end) { - return $this->isApiCall($request, 'games', "where first_release_date <= {$end};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date <= {$end};")); } - /** @test */ - public function it_should_generate_where_year_smaller_query(): void + public function testItShouldGenerateWhereYearSmallerQuery(): void { $date = now(); $start = $date->clone()->startOfYear()->timestamp; Game::whereYear('first_release_date', '<', $date->year)->get(); - Http::assertSent(function (Request $request) use ($start) { - return $this->isApiCall($request, 'games', "where first_release_date < {$start};"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "where first_release_date < {$start};")); } - /** @test */ - public function it_should_generate_where_has_query(): void + public function testItShouldGenerateWhereHasQuery(): void { Game::whereHas('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date != null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date != null;')); } - /** @test */ - public function it_should_generate_where_has_not_query(): void + public function testItShouldGenerateWhereHasNotQuery(): void { Game::whereHasNot('first_release_date')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where first_release_date = null;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where first_release_date = null;')); } - /** @test */ - public function it_should_generate_nested_where_query(): void + public function testItShouldGenerateNestedWhereQuery(): void { Game::where('name', 'Fortnite') - ->orWhere(function($query) { + ->orWhere(function ($query): void { $query->where('aggregated_rating', '>=', 90) ->where('aggregated_rating_count', '>=', 3000); })->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where name = "Fortnite" | (aggregated_rating >= 90 & aggregated_rating_count >= 3000);'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where name = "Fortnite" | (aggregated_rating >= 90 & aggregated_rating_count >= 3000);')); } - /** @test */ - public function it_should_generate_array_where_query(): void + public function testItShouldGenerateArrayWhereQuery(): void { Game::where([['name', 'Fortnite'], ['name', 'Borderlands 2']])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'where (name = "Fortnite" & name = "Borderlands 2");'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'where (name = "Fortnite" & name = "Borderlands 2");')); } - /** @test */ - public function it_should_generate_orderby_query(): void + public function testItShouldGenerateOrderbyQuery(): void { Game::orderBy('name')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name asc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name asc;')); Game::orderBy('name', 'desc')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name desc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name desc;')); Game::orderBy('name', 'asc')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name asc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name asc;')); } - /** @test */ - public function it_should_not_generate_orderby_query_with_invalid_params(): void + public function testItShouldNotGenerateOrderbyQueryWithInvalidParams(): void { $this->expectException(InvalidParamsException::class); Game::orderBy('name', 'foo')->get(); - Http::assertNotSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name foo;'); - }); + Http::assertNotSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name foo;')); } - /** @test */ - public function it_should_generate_orderbydesc_query(): void + public function testItShouldGenerateOrderbydescQuery(): void { Game::orderByDesc('name')->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'sort name desc;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'sort name desc;')); } - /** @test */ - public function it_should_generate_offset_query(): void + public function testItShouldGenerateOffsetQuery(): void { Game::skip(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'offset 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'offset 10;')); Game::offset(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'offset 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'offset 10;')); } - /** @test */ - public function it_should_generate_limit_query(): void + public function testItShouldGenerateLimitQuery(): void { Game::take(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'limit 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'limit 10;')); Game::limit(10)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', 'limit 10;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'limit 10;')); } - /** @test */ - public function it_should_generate_forPage_query(): void + public function testItShouldGenerateForPageQuery(): void { Game::forPage(2, 20)->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 20;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 20;")); } - /** @test */ - public function it_should_generate_all_query(): void + public function testItShouldGenerateAllQuery(): void { Game::all(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 500;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 500;\noffset 0;")); } - /** @test */ - public function it_should_generate_first_query(): void + public function testItShouldGenerateFirstQuery(): void { Game::first(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 1;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 1;\noffset 0;")); } - - - /** @test */ - public function it_should_generate_find_query(): void + public function testItShouldGenerateFindQuery(): void { Game::find(1905); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 1;\noffset 0;\nwhere id = 1905;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 1;\noffset 0;\nwhere id = 1905;")); } - /** @test */ - public function it_should_generate_paginate_query(): void + public function testItShouldGeneratePaginateQuery(): void { Game::paginate(20); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 0;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 0;")); $this->get('/?page=2'); Game::paginate(20); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "limit 20;\noffset 20;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', "limit 20;\noffset 20;")); } - /** @test */ - public function it_should_generate_expanding_query(): void + public function testItShouldGenerateExpandingQuery(): void { Game::with(['cover', 'artworks'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,cover.*,artworks.*;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,cover.*,artworks.*;')); Game::with(['involved_companies', 'involved_companies.company'])->get(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games', "fields *,involved_companies.*,involved_companies.company.*;"); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games', 'fields *,involved_companies.*,involved_companies.company.*;')); } - /** @test */ - public function it_should_request_count_endpoint(): void + public function testItShouldRequestCountEndpoint(): void { $count = Game::count(); - Http::assertSent(function (Request $request) { - return $this->isApiCall($request, 'games/count', 'fields *;'); - }); + Http::assertSent(fn (Request $request) => $this->isApiCall($request, 'games/count', 'fields *;')); self::assertEquals(1337, $count); } - /** - * @test - */ - public function it_should_throw_exception_for_first_or_fail_method(): void + public function testItShouldThrowExceptionForFirstOrFailMethod(): void { $this->expectException(ModelNotFoundException::class); Game::firstOrFail(); } - /** - * @test - */ - public function it_should_throw_exception_for_find_or_fail_method(): void + public function testItShouldThrowExceptionForFindOrFailMethod(): void { $this->expectException(ModelNotFoundException::class); Game::findOrFail(1337); } - /** @test */ - public function it_should_throw_exception_when_bad_method_is_called(): void + public function testItShouldThrowExceptionWhenBadMethodIsCalled(): void { $this->expectException(BadMethodCallException::class); diff --git a/tests/TestCase.php b/tests/TestCase.php index f63bb1e..9a6e805 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,5 +1,7 @@ name('handle-igdb-webhook'); + Route::post( + 'igdb-webhook/handle/{model}/{method}', + static fn (\Illuminate\Http\Request $request) => Webhook::handle($request), + )->name('handle-igdb-webhook'); } protected function getPackageProviders($app): array @@ -48,26 +55,25 @@ protected function isWebhookCall(Request $request, string $endpoint): bool return $request->url() === 'https://api.igdb.com/v4/' . $endpoint . '/webhooks' && $request->isForm(); } - /** - * @param Request $request - * - * @return PromiseInterface - */ protected function createWebhookResponse(Request $request): PromiseInterface { $data = $request->data(); - $subCategory = 0; + $subCategory = null; switch ($data['method']) { case 'create': $subCategory = 0; + break; case 'delete': $subCategory = 1; + break; case 'update': $subCategory = 2; + break; } + return Http::response([ 'id' => 1337, 'url' => $data['url'], @@ -79,4 +85,33 @@ protected function createWebhookResponse(Request $request): PromiseInterface 'updated_at' => now()->toIso8601String(), ]); } + + public static function modelsDataProvider(): array + { + $files = glob(__DIR__ . '/../src/Models/*.php'); + $classNames = []; + $blackList = ['Search', 'Webhook']; + + if (!$files) { + return $classNames; + } + + foreach ($files as $file) { + $classString = 'MarcReichel\IGDBLaravel\Models\\' . basename($file, '.php'); + if (!class_exists($classString)) { + continue; + } + $reflection = new ReflectionClass($classString); + if ($reflection->isAbstract()) { + continue; + } + if (in_array(class_basename($classString), $blackList)) { + continue; + } + + $classNames[] = [class_basename($classString)]; + } + + return $classNames; + } } diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index fec9f55..d882f4e 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -1,137 +1,29 @@ Http::response([ 'access_token' => 'test-suite-token', - 'expires_in' => 3600 + 'expires_in' => 3600, ]), - '*/games/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/companies/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, - '*/artworks/webhooks' => function (Request $request) { - return $this->createWebhookResponse($request); - }, + '*/games/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/companies/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), + '*/artworks/webhooks' => fn (Request $request) => $this->createWebhookResponse($request), '*/webhooks' => Http::response(), '*/count' => Http::response(['count' => 1337]), '*/companies' => Http::response(['id' => 1337, 'name' => 'Fortnite']), @@ -162,46 +48,32 @@ public function setUp(): void } /** @test */ - public function it_should_generate_webhook(): void + public function itShouldGenerateWebhook(): void { $webhook = Game::createWebhook(Method::CREATE); - Http::assertSent(function (Request $request) { - return $this->isWebhookCall($request, 'games'); - }); + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'games')); self::assertEquals(0, $webhook->sub_category); self::assertEquals('http://localhost/' . $this->prefix . '/games/create', $webhook->url); $webhook = Company::createWebhook(Method::UPDATE); - Http::assertSent(function (Request $request) { - return $this->isWebhookCall($request, 'companies'); - }); + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'companies')); self::assertEquals(2, $webhook->sub_category); self::assertEquals('http://localhost/' . $this->prefix . '/companies/update', $webhook->url); $webhook = Artwork::createWebhook(Method::DELETE); - Http::assertSent(function (Request $request) { - return $this->isWebhookCall($request, 'artworks'); - }); + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'artworks')); self::assertEquals(1, $webhook->sub_category); self::assertEquals('http://localhost/' . $this->prefix . '/artworks/delete', $webhook->url); } /** @test */ - public function it_should_throw_exception_for_invalid_webhook_method(): void - { - $this->expectException(InvalidWebhookMethodException::class); - - Game::createWebhook('foo'); - } - - /** @test */ - public function it_should_throw_exception_when_no_secret_is_set(): void + public function itShouldThrowExceptionWhenNoSecretIsSet(): void { $this->expectException(WebhookSecretMissingException::class); @@ -210,1691 +82,15 @@ public function it_should_throw_exception_when_no_secret_is_set(): void Game::createWebhook(Method::CREATE); } - /** @test */ - public function it_should_dispatch_age_rating_content_destription_created_event(): void - { - $url = $this->prefix . '/age_rating_content_description/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingContentDescriptionCreated::class); - } - - /** @test */ - public function it_should_dispatch_age_rating_content_destription_deleted_event(): void - { - $url = $this->prefix . '/age_rating_content_description/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingContentDescriptionDeleted::class); - } - - /** @test */ - public function it_should_dispatch_age_rating_content_destription_updated_event(): void - { - $url = $this->prefix . '/age_rating_content_description/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingContentDescriptionUpdated::class); - } - - /** @test */ - public function it_should_dispatch_age_rating_created_event(): void - { - $url = $this->prefix . '/age_rating/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingCreated::class); - } - - /** @test */ - public function it_should_dispatch_age_rating_deleted_event(): void - { - $url = $this->prefix . '/age_rating/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingDeleted::class); - } - - /** @test */ - public function it_should_dispatch_age_rating_updated_event(): void - { - $url = $this->prefix . '/age_rating/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AgeRatingUpdated::class); - } - - /** @test */ - public function it_should_dispatch_alternative_name_created_event(): void - { - $url = $this->prefix . '/alternative_name/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AlternativeNameCreated::class); - } - - /** @test */ - public function it_should_dispatch_alternative_name_deleted_event(): void - { - $url = $this->prefix . '/alternative_name/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AlternativeNameDeleted::class); - } - - /** @test */ - public function it_should_dispatch_alternative_name_updated_event(): void - { - $url = $this->prefix . '/alternative_name/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(AlternativeNameUpdated::class); - } - - /** @test */ - public function it_should_dispatch_artwork_created_event(): void - { - $url = $this->prefix . '/artwork/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ArtworkCreated::class); - } - - /** @test */ - public function it_should_dispatch_artwork_deleted_event(): void - { - $url = $this->prefix . '/artwork/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ArtworkDeleted::class); - } - - /** @test */ - public function it_should_dispatch_artwork_updated_event(): void - { - $url = $this->prefix . '/artwork/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ArtworkUpdated::class); - } - - /** @test */ - public function it_should_dispatch_character_created_event(): void - { - $url = $this->prefix . '/character/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterCreated::class); - } - - /** @test */ - public function it_should_dispatch_character_deleted_event(): void - { - $url = $this->prefix . '/character/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterDeleted::class); - } - - /** @test */ - public function it_should_dispatch_character_updated_event(): void - { - $url = $this->prefix . '/character/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterUpdated::class); - } - - /** @test */ - public function it_should_dispatch_character_mug_shot_created_event(): void - { - $url = $this->prefix . '/character_mug_shot/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterMugShotCreated::class); - } - - /** @test */ - public function it_should_dispatch_character_mug_shot_deleted_event(): void - { - $url = $this->prefix . '/character_mug_shot/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterMugShotDeleted::class); - } - - /** @test */ - public function it_should_dispatch_character_mug_shot_updated_event(): void - { - $url = $this->prefix . '/character_mug_shot/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CharacterMugShotUpdated::class); - } - - /** @test */ - public function it_should_dispatch_collection_created_event(): void - { - $url = $this->prefix . '/collection/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CollectionCreated::class); - } - - /** @test */ - public function it_should_dispatch_collection_deleted_event(): void - { - $url = $this->prefix . '/collection/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CollectionDeleted::class); - } - - /** @test */ - public function it_should_dispatch_collection_updated_event(): void - { - $url = $this->prefix . '/collection/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CollectionUpdated::class); - } - - /** @test */ - public function it_should_dispatch_company_created_event(): void - { - $url = $this->prefix . '/company/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyCreated::class); - } - - /** @test */ - public function it_should_dispatch_company_deleted_event(): void - { - $url = $this->prefix . '/company/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyDeleted::class); - } - - /** @test */ - public function it_should_dispatch_company_updated_event(): void - { - $url = $this->prefix . '/company/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyUpdated::class); - } - - /** @test */ - public function it_should_dispatch_company_logo_created_event(): void - { - $url = $this->prefix . '/company_logo/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyLogoCreated::class); - } - - /** @test */ - public function it_should_dispatch_company_logo_deleted_event(): void - { - $url = $this->prefix . '/company_logo/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyLogoDeleted::class); - } - - /** @test */ - public function it_should_dispatch_company_logo_updated_event(): void - { - $url = $this->prefix . '/company_logo/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyLogoUpdated::class); - } - - /** @test */ - public function it_should_dispatch_company_website_created_event(): void - { - $url = $this->prefix . '/company_website/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyWebsiteCreated::class); - } - - /** @test */ - public function it_should_dispatch_company_website_deleted_event(): void - { - $url = $this->prefix . '/company_website/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyWebsiteDeleted::class); - } - - /** @test */ - public function it_should_dispatch_company_website_updated_event(): void - { - $url = $this->prefix . '/company_website/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CompanyWebsiteUpdated::class); - } - - /** @test */ - public function it_should_dispatch_cover_created_event(): void - { - $url = $this->prefix . '/cover/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CoverCreated::class); - } - - /** @test */ - public function it_should_dispatch_cover_deleted_event(): void - { - $url = $this->prefix . '/cover/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CoverDeleted::class); - } - - /** @test */ - public function it_should_dispatch_cover_updated_event(): void - { - $url = $this->prefix . '/cover/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(CoverUpdated::class); - } - - /** @test */ - public function it_should_dispatch_external_game_created_event(): void - { - $url = $this->prefix . '/external_game/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ExternalGameCreated::class); - } - - /** @test */ - public function it_should_dispatch_external_game_deleted_event(): void - { - $url = $this->prefix . '/external_game/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ExternalGameDeleted::class); - } - - /** @test */ - public function it_should_dispatch_external_game_updated_event(): void - { - $url = $this->prefix . '/external_game/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ExternalGameUpdated::class); - } - - /** @test */ - public function it_should_dispatch_franchise_created_event(): void - { - $url = $this->prefix . '/franchise/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(FranchiseCreated::class); - } - - /** @test */ - public function it_should_dispatch_franchise_deleted_event(): void - { - $url = $this->prefix . '/franchise/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(FranchiseDeleted::class); - } - - /** @test */ - public function it_should_dispatch_franchise_updated_event(): void - { - $url = $this->prefix . '/franchise/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(FranchiseUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_created_event(): void - { - $url = $this->prefix . '/game/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_deleted_event(): void - { - $url = $this->prefix . '/game/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_updated_event(): void - { - $url = $this->prefix . '/game/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_created_event(): void - { - $url = $this->prefix . '/game_engine/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_deleted_event(): void - { - $url = $this->prefix . '/game_engine/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_updated_event(): void - { - $url = $this->prefix . '/game_engine/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_logo_created_event(): void - { - $url = $this->prefix . '/game_engine_logo/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineLogoCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_logo_deleted_event(): void - { - $url = $this->prefix . '/game_engine_logo/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineLogoDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_engine_logo_updated_event(): void - { - $url = $this->prefix . '/game_engine_logo/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameEngineLogoUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_mode_created_event(): void - { - $url = $this->prefix . '/game_mode/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameModeCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_mode_deleted_event(): void - { - $url = $this->prefix . '/game_mode/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameModeDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_mode_updated_event(): void - { - $url = $this->prefix . '/game_mode/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameModeUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_created_event(): void - { - $url = $this->prefix . '/game_version/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_deleted_event(): void - { - $url = $this->prefix . '/game_version/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_version_updated_event(): void - { - $url = $this->prefix . '/game_version/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_created_event(): void - { - $url = $this->prefix . '/game_version_feature/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_deleted_event(): void - { - $url = $this->prefix . '/game_version_feature/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_updated_event(): void - { - $url = $this->prefix . '/game_version_feature/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_value_created_event(): void - { - $url = $this->prefix . '/game_version_feature_value/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureValueCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_value_deleted_event(): void - { - $url = $this->prefix . '/game_version_feature_value/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureValueDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_version_feature_value_updated_event(): void - { - $url = $this->prefix . '/game_version_feature_value/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVersionFeatureValueUpdated::class); - } - - /** @test */ - public function it_should_dispatch_game_video_created_event(): void - { - $url = $this->prefix . '/game_video/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVideoCreated::class); - } - - /** @test */ - public function it_should_dispatch_game_video_deleted_event(): void - { - $url = $this->prefix . '/game_video/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVideoDeleted::class); - } - - /** @test */ - public function it_should_dispatch_game_video_updated_event(): void - { - $url = $this->prefix . '/game_video/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GameVideoUpdated::class); - } - - /** @test */ - public function it_should_dispatch_genre_created_event(): void - { - $url = $this->prefix . '/genre/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GenreCreated::class); - } - - /** @test */ - public function it_should_dispatch_genre_deleted_event(): void - { - $url = $this->prefix . '/genre/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GenreDeleted::class); - } - - /** @test */ - public function it_should_dispatch_genre_updated_event(): void - { - $url = $this->prefix . '/genre/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(GenreUpdated::class); - } - - /** @test */ - public function it_should_dispatch_involved_company_created_event(): void - { - $url = $this->prefix . '/involved_company/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(InvolvedCompanyCreated::class); - } - - /** @test */ - public function it_should_dispatch_involved_company_deleted_event(): void - { - $url = $this->prefix . '/involved_company/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(InvolvedCompanyDeleted::class); - } - - /** @test */ - public function it_should_dispatch_involved_company_updated_event(): void - { - $url = $this->prefix . '/involved_company/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(InvolvedCompanyUpdated::class); - } - - /** @test */ - public function it_should_dispatch_keyword_created_event(): void - { - $url = $this->prefix . '/keyword/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(KeywordCreated::class); - } - - /** @test */ - public function it_should_dispatch_keyword_deleted_event(): void - { - $url = $this->prefix . '/keyword/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(KeywordDeleted::class); - } - - /** @test */ - public function it_should_dispatch_keyword_updated_event(): void - { - $url = $this->prefix . '/keyword/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(KeywordUpdated::class); - } - - /** @test */ - public function it_should_dispatch_multiplayer_mode_created_event(): void - { - $url = $this->prefix . '/multiplayer_mode/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(MultiplayerModeCreated::class); - } - - /** @test */ - public function it_should_dispatch_multiplayer_mode_deleted_event(): void - { - $url = $this->prefix . '/multiplayer_mode/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(MultiplayerModeDeleted::class); - } - - /** @test */ - public function it_should_dispatch_multiplayer_mode_updated_event(): void - { - $url = $this->prefix . '/multiplayer_mode/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(MultiplayerModeUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_created_event(): void - { - $url = $this->prefix . '/platform/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_deleted_event(): void - { - $url = $this->prefix . '/platform/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_updated_event(): void - { - $url = $this->prefix . '/platform/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_family_created_event(): void - { - $url = $this->prefix . '/platform_family/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformFamilyCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_family_deleted_event(): void - { - $url = $this->prefix . '/platform_family/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformFamilyDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_family_updated_event(): void - { - $url = $this->prefix . '/platform_family/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformFamilyUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_logo_created_event(): void - { - $url = $this->prefix . '/platform_logo/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformLogoCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_logo_deleted_event(): void - { - $url = $this->prefix . '/platform_logo/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformLogoDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_logo_updated_event(): void - { - $url = $this->prefix . '/platform_logo/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformLogoUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_company_created_event(): void - { - $url = $this->prefix . '/platform_version_company/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionCompanyCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_company_deleted_event(): void - { - $url = $this->prefix . '/platform_version_company/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionCompanyDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_company_updated_event(): void - { - $url = $this->prefix . '/platform_version_company/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionCompanyUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_created_event(): void - { - $url = $this->prefix . '/platform_version/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_deleted_event(): void - { - $url = $this->prefix . '/platform_version/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_updated_event(): void - { - $url = $this->prefix . '/platform_version/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_release_date_created_event(): void - { - $url = $this->prefix . '/platform_version_release_date/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionReleaseDateCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_release_date_deleted_event(): void - { - $url = $this->prefix . '/platform_version_release_date/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionReleaseDateDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_version_release_date_updated_event(): void - { - $url = $this->prefix . '/platform_version_release_date/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformVersionReleaseDateUpdated::class); - } - - /** @test */ - public function it_should_dispatch_platform_website_created_event(): void - { - $url = $this->prefix . '/platform_website/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformWebsiteCreated::class); - } - - /** @test */ - public function it_should_dispatch_platform_website_deleted_event(): void - { - $url = $this->prefix . '/platform_website/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformWebsiteDeleted::class); - } - - /** @test */ - public function it_should_dispatch_platform_website_updated_event(): void - { - $url = $this->prefix . '/platform_website/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlatformWebsiteUpdated::class); - } - - /** @test */ - public function it_should_dispatch_player_perspective_created_event(): void - { - $url = $this->prefix . '/player_perspective/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlayerPerspectiveCreated::class); - } - - /** @test */ - public function it_should_dispatch_player_perspective_deleted_event(): void - { - $url = $this->prefix . '/player_perspective/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlayerPerspectiveDeleted::class); - } - - /** @test */ - public function it_should_dispatch_player_perspective_updated_event(): void - { - $url = $this->prefix . '/player_perspective/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(PlayerPerspectiveUpdated::class); - } - - /** @test */ - public function it_should_dispatch_release_date_created_event(): void - { - $url = $this->prefix . '/release_date/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ReleaseDateCreated::class); - } - - /** @test */ - public function it_should_dispatch_release_date_deleted_event(): void - { - $url = $this->prefix . '/release_date/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ReleaseDateDeleted::class); - } - - /** @test */ - public function it_should_dispatch_release_date_updated_event(): void - { - $url = $this->prefix . '/release_date/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ReleaseDateUpdated::class); - } - - /** @test */ - public function it_should_dispatch_screenshot_created_event(): void - { - $url = $this->prefix . '/screenshot/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ScreenshotCreated::class); - } - - /** @test */ - public function it_should_dispatch_screenshot_deleted_event(): void - { - $url = $this->prefix . '/screenshot/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ScreenshotDeleted::class); - } - - /** @test */ - public function it_should_dispatch_screenshot_updated_event(): void - { - $url = $this->prefix . '/screenshot/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ScreenshotUpdated::class); - } - - /** @test */ - public function it_should_dispatch_theme_created_event(): void - { - $url = $this->prefix . '/theme/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ThemeCreated::class); - } - - /** @test */ - public function it_should_dispatch_theme_deleted_event(): void - { - $url = $this->prefix . '/theme/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ThemeDeleted::class); - } - - /** @test */ - public function it_should_dispatch_theme_updated_event(): void - { - $url = $this->prefix . '/theme/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(ThemeUpdated::class); - } - - /** @test */ - public function it_should_dispatch_website_created_event(): void - { - $url = $this->prefix . '/website/create'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(WebsiteCreated::class); - } - - /** @test */ - public function it_should_dispatch_website_deleted_event(): void - { - $url = $this->prefix . '/website/delete'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(WebsiteDeleted::class); - } - - /** @test */ - public function it_should_dispatch_website_updated_event(): void - { - $url = $this->prefix . '/website/update'; - - $response = $this->withHeaders([ - 'X-Secret' => 'secret', - ]) - ->postJson($url, ['id' => 1337]); - - $response->assertStatus(200); - - Event::assertDispatched(WebsiteUpdated::class); - } - - /** @test */ - public function it_should_validate_webhook_secret(): void - { - $this->withoutExceptionHandling(); - $this->expectException(InvalidWebhookSecretException::class); - - $url = $this->prefix . '/games/create'; - - $this->withHeaders([ - 'X-Secret' => 'foobar', - ]) - ->postJson($url, ['id' => 1337]); - - Event::assertNotDispatched(GameCreated::class); - } - - /** @test */ - public function it_should_keep_dispatching_event_for_deprecated_url(): void + /** + * @test + * + * @dataProvider modelsDataProvider + */ + public function itShouldDispatchCreatedEvent(string $className): void { - $url = 'igdb-webhook/handle/website/update'; + $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Created'; + $url = $this->prefix . '/' . Str::snake($className) . '/create'; $response = $this->withHeaders([ 'X-Secret' => 'secret', @@ -1903,6 +99,6 @@ public function it_should_keep_dispatching_event_for_deprecated_url(): void $response->assertStatus(200); - Event::assertDispatched(WebsiteUpdated::class); + Event::assertDispatched($eventClassString); } } From b2f62b79ab81d964f4ca730347426dcf0784d623 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Wed, 1 Nov 2023 23:05:11 +0100 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=8E=A8=20Fix=20code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/web.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/routes/web.php b/routes/web.php index f51b790..bd6c2be 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,10 +9,6 @@ /** * @deprecated */ -Route::post('{model}/{method}', static function (Request $request) { - return Webhook::handle($request); -}); +Route::post('{model}/{method}', static fn (Request $request) => Webhook::handle($request)); -Route::post(substr(md5(config('igdb.credentials.client_id')), 0, 8) . '/{model}/{method}', static function (Request $request) { - return Webhook::handle($request); -})->name('handle-igdb-webhook'); +Route::post(substr(md5(config('igdb.credentials.client_id')), 0, 8) . '/{model}/{method}', static fn (Request $request) => Webhook::handle($request))->name('handle-igdb-webhook'); From 6d978e398f4b45f490cacfa722de120bfb69c793 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Wed, 1 Nov 2023 23:06:23 +0100 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=92=9A=20Fix=20phpstan=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpstan.neon | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 6d2a388..6f1e26a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,7 +9,6 @@ parameters: # The level 9 is the highest level level: 8 ignoreErrors: - - '#Attribute class JetBrains\\PhpStorm\\ArrayShape does not exist.#' - '#Call to an undefined static method MarcReichel\\IGDBLaravel\\Models\\Game::foo\(\).#' - '#Unable to resolve the template type TValue in call to function collect#' - '#Unable to resolve the template type TKey in call to function collect#' From ef436550e8d513497cb693242bc75eafb57fd596 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Thu, 2 Nov 2023 08:18:55 +0100 Subject: [PATCH 04/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Fix=20pint=20depende?= =?UTF-8?q?ncy=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 847621a..055bf5e 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "nunomaduro/collision": "^5.3|^6.1|^7.0", "roave/security-advisories": "dev-latest", "nunomaduro/larastan": "^1.0|^2.0", - "laravel/pint": "dev-main" + "laravel/pint": "^1.13" }, "license": "MIT", "authors": [ From d4bb63020bf2332e4bb52587b8a443e2e0f1ac6a Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Thu, 2 Nov 2023 10:50:29 +0100 Subject: [PATCH 05/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AgeRatingContentDescriptionCreated.php | 9 +-- src/Events/AgeRatingCreated.php | 9 +-- src/Events/AlternativeNameCreated.php | 9 +-- src/Events/ArtworkCreated.php | 9 +-- src/Events/CharacterCreated.php | 9 +-- src/Events/CharacterMugShotCreated.php | 9 +-- src/Events/CollectionCreated.php | 9 +-- src/Events/CollectionMembershipCreated.php | 9 +-- .../CollectionMembershipTypeCreated.php | 9 +-- src/Events/CollectionRelationCreated.php | 10 +--- src/Events/CollectionRelationTypeCreated.php | 9 +-- src/Events/CollectionTypeCreated.php | 9 +-- src/Events/CompanyCreated.php | 9 +-- src/Events/CompanyLogoCreated.php | 9 +-- src/Events/CompanyWebsiteCreated.php | 9 +-- src/Events/CoverCreated.php | 9 +-- src/Events/Event.php | 7 +++ src/Events/EventCreated.php | 9 +-- src/Events/EventLogoCreated.php | 9 +-- src/Events/EventNetworkCreated.php | 9 +-- src/Events/ExternalGameCreated.php | 9 +-- src/Events/FranchiseCreated.php | 9 +-- src/Events/GameCreated.php | 9 +-- src/Events/GameEngineCreated.php | 9 +-- src/Events/GameEngineLogoCreated.php | 9 +-- src/Events/GameLocalizationCreated.php | 9 +-- src/Events/GameModeCreated.php | 9 +-- src/Events/GameVersionCreated.php | 9 +-- src/Events/GameVersionFeatureCreated.php | 9 +-- src/Events/GameVersionFeatureValueCreated.php | 9 +-- src/Events/GameVideoCreated.php | 9 +-- src/Events/GenreCreated.php | 9 +-- src/Events/InvolvedCompanyCreated.php | 9 +-- src/Events/KeywordCreated.php | 9 +-- src/Events/LanguageCreated.php | 9 +-- src/Events/LanguageSupportCreated.php | 9 +-- src/Events/LanguageSupportTypeCreated.php | 9 +-- src/Events/MultiplayerModeCreated.php | 9 +-- src/Events/NetworkTypeCreated.php | 9 +-- src/Events/PlatformCreated.php | 9 +-- src/Events/PlatformFamilyCreated.php | 9 +-- src/Events/PlatformLogoCreated.php | 9 +-- src/Events/PlatformVersionCompanyCreated.php | 9 +-- src/Events/PlatformVersionCreated.php | 9 +-- .../PlatformVersionReleaseDateCreated.php | 9 +-- src/Events/PlatformWebsiteCreated.php | 9 +-- src/Events/PlayerPerspectiveCreated.php | 9 +-- src/Events/RegionCreated.php | 9 +-- src/Events/ReleaseDateCreated.php | 9 +-- src/Events/ReleaseDateStatusCreated.php | 9 +-- src/Events/ScreenshotCreated.php | 9 +-- src/Events/ThemeCreated.php | 9 +-- src/Events/WebsiteCreated.php | 9 +-- src/Models/Webhook.php | 8 +-- tests/WebhookTest.php | 60 ++++++++++++++++--- 55 files changed, 117 insertions(+), 427 deletions(-) diff --git a/src/Events/AgeRatingContentDescriptionCreated.php b/src/Events/AgeRatingContentDescriptionCreated.php index 7c8d229..148ef69 100644 --- a/src/Events/AgeRatingContentDescriptionCreated.php +++ b/src/Events/AgeRatingContentDescriptionCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\AgeRatingContentDescription; class AgeRatingContentDescriptionCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public AgeRatingContentDescription $data; public function __construct(AgeRatingContentDescription $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/AgeRatingCreated.php b/src/Events/AgeRatingCreated.php index 7974c35..ed3e67a 100644 --- a/src/Events/AgeRatingCreated.php +++ b/src/Events/AgeRatingCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\AgeRating; class AgeRatingCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public AgeRating $data; public function __construct(AgeRating $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/AlternativeNameCreated.php b/src/Events/AlternativeNameCreated.php index ac657d0..af7f407 100644 --- a/src/Events/AlternativeNameCreated.php +++ b/src/Events/AlternativeNameCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\AlternativeName; class AlternativeNameCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public AlternativeName $data; public function __construct(AlternativeName $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ArtworkCreated.php b/src/Events/ArtworkCreated.php index 4fea7ed..e2b84c8 100644 --- a/src/Events/ArtworkCreated.php +++ b/src/Events/ArtworkCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Artwork; class ArtworkCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Artwork $data; public function __construct(Artwork $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CharacterCreated.php b/src/Events/CharacterCreated.php index 6951699..f40573b 100644 --- a/src/Events/CharacterCreated.php +++ b/src/Events/CharacterCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Character; class CharacterCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Character $data; public function __construct(Character $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CharacterMugShotCreated.php b/src/Events/CharacterMugShotCreated.php index aa65041..d8cf1d2 100644 --- a/src/Events/CharacterMugShotCreated.php +++ b/src/Events/CharacterMugShotCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CharacterMugShot; class CharacterMugShotCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CharacterMugShot $data; public function __construct(CharacterMugShot $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CollectionCreated.php b/src/Events/CollectionCreated.php index 068060f..f0044d6 100644 --- a/src/Events/CollectionCreated.php +++ b/src/Events/CollectionCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Collection; class CollectionCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Collection $data; public function __construct(Collection $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CollectionMembershipCreated.php b/src/Events/CollectionMembershipCreated.php index 84eb44a..dff4a20 100644 --- a/src/Events/CollectionMembershipCreated.php +++ b/src/Events/CollectionMembershipCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CollectionMembership; class CollectionMembershipCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CollectionMembership $data; public function __construct(CollectionMembership $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CollectionMembershipTypeCreated.php b/src/Events/CollectionMembershipTypeCreated.php index 97c7781..ff80d7d 100644 --- a/src/Events/CollectionMembershipTypeCreated.php +++ b/src/Events/CollectionMembershipTypeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CollectionMembershipType; class CollectionMembershipTypeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CollectionMembershipType $data; public function __construct(CollectionMembershipType $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CollectionRelationCreated.php b/src/Events/CollectionRelationCreated.php index f104c33..8d0ae39 100644 --- a/src/Events/CollectionRelationCreated.php +++ b/src/Events/CollectionRelationCreated.php @@ -4,23 +4,17 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CollectionRelation; class CollectionRelationCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CollectionRelation $data; public function __construct(CollectionRelation $data, Request $request) { - $this->data = $data; parent::__construct($request); + + $this->data = $data; } } diff --git a/src/Events/CollectionRelationTypeCreated.php b/src/Events/CollectionRelationTypeCreated.php index 5b0407c..6e919d4 100644 --- a/src/Events/CollectionRelationTypeCreated.php +++ b/src/Events/CollectionRelationTypeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CollectionRelationType; class CollectionRelationTypeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CollectionRelationType $data; public function __construct(CollectionRelationType $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CollectionTypeCreated.php b/src/Events/CollectionTypeCreated.php index 942b85e..994148b 100644 --- a/src/Events/CollectionTypeCreated.php +++ b/src/Events/CollectionTypeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CollectionType; class CollectionTypeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CollectionType $data; public function __construct(CollectionType $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CompanyCreated.php b/src/Events/CompanyCreated.php index 09f9021..84998ac 100644 --- a/src/Events/CompanyCreated.php +++ b/src/Events/CompanyCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Company; class CompanyCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Company $data; public function __construct(Company $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CompanyLogoCreated.php b/src/Events/CompanyLogoCreated.php index 2d530e1..3042459 100644 --- a/src/Events/CompanyLogoCreated.php +++ b/src/Events/CompanyLogoCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CompanyLogo; class CompanyLogoCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CompanyLogo $data; public function __construct(CompanyLogo $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CompanyWebsiteCreated.php b/src/Events/CompanyWebsiteCreated.php index 157ff58..12f4e4c 100644 --- a/src/Events/CompanyWebsiteCreated.php +++ b/src/Events/CompanyWebsiteCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\CompanyWebsite; class CompanyWebsiteCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public CompanyWebsite $data; public function __construct(CompanyWebsite $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/CoverCreated.php b/src/Events/CoverCreated.php index fd08f10..98ea2ba 100644 --- a/src/Events/CoverCreated.php +++ b/src/Events/CoverCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Cover; class CoverCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Cover $data; public function __construct(Cover $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/Event.php b/src/Events/Event.php index 12813c0..69eb448 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -5,10 +5,17 @@ namespace MarcReichel\IGDBLaravel\Events; use Carbon\Carbon; +use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; +use Illuminate\Queue\SerializesModels; abstract class Event { + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; + public string $class; public string $url; public ?string $method; diff --git a/src/Events/EventCreated.php b/src/Events/EventCreated.php index 103b538..71d2469 100644 --- a/src/Events/EventCreated.php +++ b/src/Events/EventCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Event as EventModel; class EventCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public EventModel $data; public function __construct(EventModel $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/EventLogoCreated.php b/src/Events/EventLogoCreated.php index 81d6d7c..e56d233 100644 --- a/src/Events/EventLogoCreated.php +++ b/src/Events/EventLogoCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\EventLogo; class EventLogoCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public EventLogo $data; public function __construct(EventLogo $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/EventNetworkCreated.php b/src/Events/EventNetworkCreated.php index b6cb725..4a6ac64 100644 --- a/src/Events/EventNetworkCreated.php +++ b/src/Events/EventNetworkCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\EventNetwork; class EventNetworkCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public EventNetwork $data; public function __construct(EventNetwork $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ExternalGameCreated.php b/src/Events/ExternalGameCreated.php index 6a7daac..ac06974 100644 --- a/src/Events/ExternalGameCreated.php +++ b/src/Events/ExternalGameCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\ExternalGame; class ExternalGameCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public ExternalGame $data; public function __construct(ExternalGame $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/FranchiseCreated.php b/src/Events/FranchiseCreated.php index 2342443..a92609b 100644 --- a/src/Events/FranchiseCreated.php +++ b/src/Events/FranchiseCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Franchise; class FranchiseCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Franchise $data; public function __construct(Franchise $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameCreated.php b/src/Events/GameCreated.php index e9a1494..9ea0073 100644 --- a/src/Events/GameCreated.php +++ b/src/Events/GameCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Game; class GameCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Game $data; public function __construct(Game $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameEngineCreated.php b/src/Events/GameEngineCreated.php index da6ccfb..680b0ca 100644 --- a/src/Events/GameEngineCreated.php +++ b/src/Events/GameEngineCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameEngine; class GameEngineCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameEngine $data; public function __construct(GameEngine $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameEngineLogoCreated.php b/src/Events/GameEngineLogoCreated.php index 71e2dde..ca12005 100644 --- a/src/Events/GameEngineLogoCreated.php +++ b/src/Events/GameEngineLogoCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameEngineLogo; class GameEngineLogoCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameEngineLogo $data; public function __construct(GameEngineLogo $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameLocalizationCreated.php b/src/Events/GameLocalizationCreated.php index 4f2e668..606ceef 100644 --- a/src/Events/GameLocalizationCreated.php +++ b/src/Events/GameLocalizationCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameLocalization; class GameLocalizationCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameLocalization $data; public function __construct(GameLocalization $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameModeCreated.php b/src/Events/GameModeCreated.php index 29759e4..98bb00f 100644 --- a/src/Events/GameModeCreated.php +++ b/src/Events/GameModeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameMode; class GameModeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameMode $data; public function __construct(GameMode $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameVersionCreated.php b/src/Events/GameVersionCreated.php index aae0397..39da7a8 100644 --- a/src/Events/GameVersionCreated.php +++ b/src/Events/GameVersionCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameVersion; class GameVersionCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameVersion $data; public function __construct(GameVersion $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameVersionFeatureCreated.php b/src/Events/GameVersionFeatureCreated.php index 928de67..238e49f 100644 --- a/src/Events/GameVersionFeatureCreated.php +++ b/src/Events/GameVersionFeatureCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameVersionFeature; class GameVersionFeatureCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameVersionFeature $data; public function __construct(GameVersionFeature $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameVersionFeatureValueCreated.php b/src/Events/GameVersionFeatureValueCreated.php index b4fe9f4..fa86c2d 100644 --- a/src/Events/GameVersionFeatureValueCreated.php +++ b/src/Events/GameVersionFeatureValueCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameVersionFeatureValue; class GameVersionFeatureValueCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameVersionFeatureValue $data; public function __construct(GameVersionFeatureValue $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GameVideoCreated.php b/src/Events/GameVideoCreated.php index e12a4ac..a9caef2 100644 --- a/src/Events/GameVideoCreated.php +++ b/src/Events/GameVideoCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\GameVideo; class GameVideoCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public GameVideo $data; public function __construct(GameVideo $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/GenreCreated.php b/src/Events/GenreCreated.php index 1367e51..0cd1836 100644 --- a/src/Events/GenreCreated.php +++ b/src/Events/GenreCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Genre; class GenreCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Genre $data; public function __construct(Genre $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/InvolvedCompanyCreated.php b/src/Events/InvolvedCompanyCreated.php index 24de9de..ea5eaa5 100644 --- a/src/Events/InvolvedCompanyCreated.php +++ b/src/Events/InvolvedCompanyCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\InvolvedCompany; class InvolvedCompanyCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public InvolvedCompany $data; public function __construct(InvolvedCompany $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/KeywordCreated.php b/src/Events/KeywordCreated.php index 8225614..1aec389 100644 --- a/src/Events/KeywordCreated.php +++ b/src/Events/KeywordCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Keyword; class KeywordCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Keyword $data; public function __construct(Keyword $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/LanguageCreated.php b/src/Events/LanguageCreated.php index 92e5d46..d3f29db 100644 --- a/src/Events/LanguageCreated.php +++ b/src/Events/LanguageCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Language; class LanguageCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Language $data; public function __construct(Language $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/LanguageSupportCreated.php b/src/Events/LanguageSupportCreated.php index 115138f..3ae2152 100644 --- a/src/Events/LanguageSupportCreated.php +++ b/src/Events/LanguageSupportCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\LanguageSupport; class LanguageSupportCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public LanguageSupport $data; public function __construct(LanguageSupport $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/LanguageSupportTypeCreated.php b/src/Events/LanguageSupportTypeCreated.php index 89940fb..53f62da 100644 --- a/src/Events/LanguageSupportTypeCreated.php +++ b/src/Events/LanguageSupportTypeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\LanguageSupportType; class LanguageSupportTypeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public LanguageSupportType $data; public function __construct(LanguageSupportType $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/MultiplayerModeCreated.php b/src/Events/MultiplayerModeCreated.php index 102d857..1140bee 100644 --- a/src/Events/MultiplayerModeCreated.php +++ b/src/Events/MultiplayerModeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\MultiplayerMode; class MultiplayerModeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public MultiplayerMode $data; public function __construct(MultiplayerMode $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/NetworkTypeCreated.php b/src/Events/NetworkTypeCreated.php index 98e5f7d..c620862 100644 --- a/src/Events/NetworkTypeCreated.php +++ b/src/Events/NetworkTypeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\NetworkType; class NetworkTypeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public NetworkType $data; public function __construct(NetworkType $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformCreated.php b/src/Events/PlatformCreated.php index ad783fb..378baaa 100644 --- a/src/Events/PlatformCreated.php +++ b/src/Events/PlatformCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Platform; class PlatformCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Platform $data; public function __construct(Platform $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformFamilyCreated.php b/src/Events/PlatformFamilyCreated.php index e2db349..38512c8 100644 --- a/src/Events/PlatformFamilyCreated.php +++ b/src/Events/PlatformFamilyCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformFamily; class PlatformFamilyCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformFamily $data; public function __construct(PlatformFamily $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformLogoCreated.php b/src/Events/PlatformLogoCreated.php index 2979450..ee5e87e 100644 --- a/src/Events/PlatformLogoCreated.php +++ b/src/Events/PlatformLogoCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformLogo; class PlatformLogoCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformLogo $data; public function __construct(PlatformLogo $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformVersionCompanyCreated.php b/src/Events/PlatformVersionCompanyCreated.php index 27ac2ec..333a5cd 100644 --- a/src/Events/PlatformVersionCompanyCreated.php +++ b/src/Events/PlatformVersionCompanyCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformVersionCompany; class PlatformVersionCompanyCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformVersionCompany $data; public function __construct(PlatformVersionCompany $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformVersionCreated.php b/src/Events/PlatformVersionCreated.php index 683a8c6..748dba6 100644 --- a/src/Events/PlatformVersionCreated.php +++ b/src/Events/PlatformVersionCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformVersion; class PlatformVersionCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformVersion $data; public function __construct(PlatformVersion $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformVersionReleaseDateCreated.php b/src/Events/PlatformVersionReleaseDateCreated.php index c70a574..6b1f13c 100644 --- a/src/Events/PlatformVersionReleaseDateCreated.php +++ b/src/Events/PlatformVersionReleaseDateCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformVersionReleaseDate; class PlatformVersionReleaseDateCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformVersionReleaseDate $data; public function __construct(PlatformVersionReleaseDate $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlatformWebsiteCreated.php b/src/Events/PlatformWebsiteCreated.php index 40262e9..e0a1f78 100644 --- a/src/Events/PlatformWebsiteCreated.php +++ b/src/Events/PlatformWebsiteCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlatformWebsite; class PlatformWebsiteCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlatformWebsite $data; public function __construct(PlatformWebsite $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/PlayerPerspectiveCreated.php b/src/Events/PlayerPerspectiveCreated.php index 1075b87..93a8c82 100644 --- a/src/Events/PlayerPerspectiveCreated.php +++ b/src/Events/PlayerPerspectiveCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\PlayerPerspective; class PlayerPerspectiveCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public PlayerPerspective $data; public function __construct(PlayerPerspective $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/RegionCreated.php b/src/Events/RegionCreated.php index e6a03b8..b2f3082 100644 --- a/src/Events/RegionCreated.php +++ b/src/Events/RegionCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Region; class RegionCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Region $data; public function __construct(Region $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ReleaseDateCreated.php b/src/Events/ReleaseDateCreated.php index 9f71648..6c024e5 100644 --- a/src/Events/ReleaseDateCreated.php +++ b/src/Events/ReleaseDateCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\ReleaseDate; class ReleaseDateCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public ReleaseDate $data; public function __construct(ReleaseDate $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ReleaseDateStatusCreated.php b/src/Events/ReleaseDateStatusCreated.php index 2810faa..2d066b8 100644 --- a/src/Events/ReleaseDateStatusCreated.php +++ b/src/Events/ReleaseDateStatusCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\ReleaseDateStatus; class ReleaseDateStatusCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public ReleaseDateStatus $data; public function __construct(ReleaseDateStatus $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ScreenshotCreated.php b/src/Events/ScreenshotCreated.php index 49ca0ef..c933e84 100644 --- a/src/Events/ScreenshotCreated.php +++ b/src/Events/ScreenshotCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Screenshot; class ScreenshotCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Screenshot $data; public function __construct(Screenshot $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/ThemeCreated.php b/src/Events/ThemeCreated.php index 2d7969b..5721a04 100644 --- a/src/Events/ThemeCreated.php +++ b/src/Events/ThemeCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Theme; class ThemeCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Theme $data; public function __construct(Theme $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Events/WebsiteCreated.php b/src/Events/WebsiteCreated.php index 438c0ab..202773d 100644 --- a/src/Events/WebsiteCreated.php +++ b/src/Events/WebsiteCreated.php @@ -4,23 +4,16 @@ namespace MarcReichel\IGDBLaravel\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Http\Request; -use Illuminate\Queue\SerializesModels; use MarcReichel\IGDBLaravel\Models\Website; class WebsiteCreated extends Event { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - public Website $data; public function __construct(Website $data, Request $request) { - $this->data = $data; parent::__construct($request); + $this->data = $data; } } diff --git a/src/Models/Webhook.php b/src/Models/Webhook.php index 6606173..1829ca5 100644 --- a/src/Models/Webhook.php +++ b/src/Models/Webhook.php @@ -151,10 +151,10 @@ public static function validate(Request $request): void public function getModel(): string { - $reflectionCategory = new ReflectionClass(Category::class); - $categories = collect($reflectionCategory->getConstants())->flip(); + $categories = collect(Category::cases()) + ->mapWithKeys(fn (Category $category) => [(string) $category->value => $category->name]); - $category = $categories->get((string) $this->category); + $category = $categories->get($this->category); if (!is_string($category)) { return (string) $this->category; @@ -182,7 +182,7 @@ public function toArray(): array return [ 'id' => $this->id, 'url' => $this->url, - 'category' => $this->getModel(), + 'category' => $this->category, 'sub_category' => $this->sub_category, 'number_of_retries' => $this->number_of_retries, 'active' => $this->active, diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index d882f4e..713475c 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; +use MarcReichel\IGDBLaravel\Enums\Webhook\Category; use MarcReichel\IGDBLaravel\Enums\Webhook\Method; use MarcReichel\IGDBLaravel\Exceptions\WebhookSecretMissingException; use MarcReichel\IGDBLaravel\Models\Artwork; @@ -47,8 +48,7 @@ protected function setUp(): void ]); } - /** @test */ - public function itShouldGenerateWebhook(): void + public function testItShouldGenerateWebhook(): void { $webhook = Game::createWebhook(Method::CREATE); @@ -72,8 +72,7 @@ public function itShouldGenerateWebhook(): void self::assertEquals('http://localhost/' . $this->prefix . '/artworks/delete', $webhook->url); } - /** @test */ - public function itShouldThrowExceptionWhenNoSecretIsSet(): void + public function testItShouldThrowExceptionWhenNoSecretIsSet(): void { $this->expectException(WebhookSecretMissingException::class); @@ -83,11 +82,9 @@ public function itShouldThrowExceptionWhenNoSecretIsSet(): void } /** - * @test - * * @dataProvider modelsDataProvider */ - public function itShouldDispatchCreatedEvent(string $className): void + public function testItShouldDispatchCreatedEvent(string $className): void { $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Created'; $url = $this->prefix . '/' . Str::snake($className) . '/create'; @@ -101,4 +98,53 @@ public function itShouldDispatchCreatedEvent(string $className): void Event::assertDispatched($eventClassString); } + + /** + * @dataProvider modelsDataProvider + */ + public function testItShouldDispatchUpdatedEvent(string $className): void + { + $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Updated'; + $url = $this->prefix . '/' . Str::snake($className) . '/update'; + + $response = $this->withHeaders([ + 'X-Secret' => 'secret', + ]) + ->postJson($url, ['id' => 1337]); + + $response->assertStatus(200); + + Event::assertDispatched($eventClassString); + } + + /** + * @dataProvider modelsDataProvider + */ + public function testItShouldDispatchDeletedEvent(string $className): void + { + $eventClassString = 'MarcReichel\IGDBLaravel\Events\\' . $className . 'Deleted'; + $url = $this->prefix . '/' . Str::snake($className) . '/delete'; + + $response = $this->withHeaders([ + 'X-Secret' => 'secret', + ]) + ->postJson($url, ['id' => 1337]); + + $response->assertStatus(200); + + Event::assertDispatched($eventClassString); + } + + /** + * @dataProvider modelsDataProvider + */ + public function testItShouldHaveACategoryCaseForEveryModel(string $className): void + { + $categories = collect(Category::cases()) + ->map(fn (Category $category) => $category->name) + ->values() + ->toArray(); + + $this->assertContains($className, $categories); + } } From ecb553b914b6c47885808cea239a039cbf84bc8a Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Thu, 2 Nov 2023 10:58:34 +0100 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=8E=A8=20Remove=20unused=20use=20st?= =?UTF-8?q?atement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Webhook.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Models/Webhook.php b/src/Models/Webhook.php index 1829ca5..7eb9dcc 100644 --- a/src/Models/Webhook.php +++ b/src/Models/Webhook.php @@ -16,7 +16,6 @@ use MarcReichel\IGDBLaravel\Exceptions\AuthenticationException; use MarcReichel\IGDBLaravel\Exceptions\InvalidWebhookSecretException; use MarcReichel\IGDBLaravel\Interfaces\WebhookInterface; -use ReflectionClass; class Webhook implements WebhookInterface { From a1d14028092b6123d7a28ffe2a21769abfba0ed7 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Fri, 3 Nov 2023 13:37:55 +0100 Subject: [PATCH 07/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20missing=20webh?= =?UTF-8?q?ook=20category=20IDs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Enums/Webhook/Category.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Enums/Webhook/Category.php b/src/Enums/Webhook/Category.php index 7cdfdd7..07b115a 100644 --- a/src/Enums/Webhook/Category.php +++ b/src/Enums/Webhook/Category.php @@ -6,15 +6,14 @@ enum Category: int { - case PlatformWebsite = 195160949; case AgeRating = 285072627; + case AgeRatingContentDescription = 473256507; case CompanyLogo = 418544557; case GameVersionFeature = 465537972; - case AgeRatingContentDescription = 473256507; + case PlatformWebsite = 195160949; case GameMode = 477001771; case Game = 625691411; case PlatformVersion = 630691907; - case Website = 698516688; case Genre = 719936021; case CompanyWebsite = 810050019; case CharacterMugShot = 824164576; @@ -43,4 +42,20 @@ enum Category: int case GameVideo = 1982000162; case PlatformVersionReleaseDate = 1994392367; case Keyword = 2139795778; + case LanguageSupport = 349003740; + case CollectionType = 156355986; + case CollectionMembershipType = 1180608740; + case Language = 207519550; + case ReleaseDateStatus = 1506091483; + case CollectionMembership = 2098492748; + case CollectionRelation = 635029137; + case Event = 1249614672; + case EventLogo = 1020437596; + case NetworkType = 1082018767; + case GameLocalization = 806896207; + case Region = 111529551; + case EventNetwork = 1460724974; + case CollectionRelationType = 1781504066; + case LanguageSupportType = 1157224631; + case Website = 698516688; } From 52b75fff730593c5130cc2b329a919866819411e Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Fri, 3 Nov 2023 13:45:48 +0100 Subject: [PATCH 08/10] =?UTF-8?q?=F0=9F=90=9B=20Fix=20webhook=20property?= =?UTF-8?q?=20assignment=20type=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Webhook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Webhook.php b/src/Models/Webhook.php index 7eb9dcc..2d49d0d 100644 --- a/src/Models/Webhook.php +++ b/src/Models/Webhook.php @@ -193,7 +193,7 @@ private function fill(mixed ...$parameters): void if ($parameters) { foreach ($parameters as $parameter => $value) { if (property_exists($this, (string) $parameter)) { - if (is_string($value) && in_array($parameter, ['created_at', 'updated_at'])) { + if (in_array($parameter, ['created_at', 'updated_at'])) { $this->{$parameter} = (string) new Carbon($value); } else { $this->{$parameter} = $value; From 00ab16cde63a995a1deb10330906ef0d619951f8 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Fri, 3 Nov 2023 14:24:47 +0100 Subject: [PATCH 09/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20for=20bac?= =?UTF-8?q?kwards=20compatibility.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Image.php | 20 +++++++++++++++++--- src/Models/Model.php | 17 ++++++++++++++--- tests/ImageTest.php | 38 ++++++++++++++++++++++++++++++++------ tests/WebhookTest.php | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/src/Models/Image.php b/src/Models/Image.php index ddb36a6..3310e18 100644 --- a/src/Models/Image.php +++ b/src/Models/Image.php @@ -14,9 +14,10 @@ abstract class Image extends Model protected const IMAGE_BASE_PATH = '//images.igdb.com/igdb/image/upload'; /** - * @throws PropertyDoesNotExist|InvalidArgumentException + * @throws PropertyDoesNotExist + * @throws InvalidArgumentException */ - public function getUrl(Size $size = Size::THUMBNAIL, bool $retina = false): string + public function getUrl(Size | string $size = Size::THUMBNAIL, bool $retina = false): string { $basePath = static::IMAGE_BASE_PATH; $id = $this->getAttribute('image_id'); @@ -27,7 +28,20 @@ public function getUrl(Size $size = Size::THUMBNAIL, bool $retina = false): stri $id = '' . $id; - $parsedSize = $size->value; + if ($size instanceof Size) { + $parsedSize = $size->value; + } else { + $parsedSize = $size; + } + + $cases = collect(Size::cases()) + ->map(static fn (Size $s) => $s->value) + ->values() + ->toArray(); + + if (!in_array($parsedSize, $cases, true)) { + throw new InvalidArgumentException('Size must be one of ' . implode(', ', $cases)); + } if ($retina) { $parsedSize = Str::finish($parsedSize, '_2x'); diff --git a/src/Models/Model.php b/src/Models/Model.php index a6da3f1..efc7bd7 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -19,6 +19,7 @@ use MarcReichel\IGDBLaravel\Enums\Webhook\Method; use MarcReichel\IGDBLaravel\Exceptions\AuthenticationException; use MarcReichel\IGDBLaravel\Exceptions\InvalidParamsException; +use MarcReichel\IGDBLaravel\Exceptions\InvalidWebhookMethodException; use MarcReichel\IGDBLaravel\Exceptions\WebhookSecretMissingException; use MarcReichel\IGDBLaravel\Interfaces\ModelInterface; use MarcReichel\IGDBLaravel\Traits\{HasAttributes, HasRelationships}; @@ -320,7 +321,7 @@ public function toJson($options = 0): string * @throws RequestException * @throws Exception */ - public static function createWebhook(Method $method, array $parameters = []): Webhook + public static function createWebhook(Method | string $method, array $parameters = []): Webhook { if (!config('igdb.webhook_secret')) { throw new WebhookSecretMissingException(); @@ -328,9 +329,19 @@ public static function createWebhook(Method $method, array $parameters = []): We $self = new static(); + if ($method instanceof Method) { + $parsedMethod = $method->value; + } else { + $parsedMethod = $method; + } + + if (!in_array($parsedMethod, ['create', 'update', 'delete'])) { + throw new InvalidWebhookMethodException(); + } + $routeParameters = array_merge($parameters, [ 'model' => $self->getEndpoint(), - 'method' => $method->value, + 'method' => $parsedMethod, ]); $url = route('handle-igdb-webhook', $routeParameters); @@ -348,7 +359,7 @@ public static function createWebhook(Method $method, array $parameters = []): We $response = $client->post($endpoint, [ 'url' => $url, - 'method' => $method->value, + 'method' => $parsedMethod, 'secret' => config('igdb.webhook_secret'), ])->throw()->json(); diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 3dae167..92d94ba 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +use InvalidArgumentException; use MarcReichel\IGDBLaravel\Enums\Image\Size; use MarcReichel\IGDBLaravel\Models\Artwork; use MarcReichel\IGDBLaravel\Models\CharacterMugShot; @@ -43,6 +44,18 @@ public function setUp(): void ]); } + public static function imageSizeDataProvider(): array + { + $enumCases = collect(Size::cases()) + ->map(static fn (Size $size) => [$size, $size->value]) + ->toArray(); + $stringCases = collect(Size::cases()) + ->map(static fn (Size $size) => [$size->value, $size->value]) + ->toArray(); + + return array_merge($enumCases, $stringCases); + } + public function testArtworkShouldBeMappedAsInstanceOfImage(): void { self::assertInstanceOf(Image::class, Artwork::first()); @@ -85,17 +98,30 @@ public function testItShouldGenerateDefaultImageUrlWithoutAttributes(): void self::assertEquals('//images.igdb.com/igdb/image/upload/t_thumb/abc.jpg', $url); } - public function testItShouldGenerateDesiredImageUrlWithParameter(): void + /** + * @dataProvider imageSizeDataProvider + */ + public function testItShouldGenerateDesiredImageUrlWithParameter(Size | string $size, string $value): void + { + $url = Artwork::first()->getUrl($size); + + self::assertEquals('//images.igdb.com/igdb/image/upload/t_' . $value . '/abc.jpg', $url); + } + + /** + * @dataProvider imageSizeDataProvider + */ + public function testItShouldGenerateRetinaImageUrl(Size | string $size, string $value): void { - $url = Artwork::first()->getUrl(Size::COVER_BIG); + $url = Artwork::first()->getUrl($size, true); - self::assertEquals('//images.igdb.com/igdb/image/upload/t_cover_big/abc.jpg', $url); + self::assertEquals('//images.igdb.com/igdb/image/upload/t_' . $value . '_2x/abc.jpg', $url); } - public function testItShouldGenerateRetinaImageUrl(): void + public function testItShouldThrowExceptionWithInvalidImageSize(): void { - $url = Artwork::first()->getUrl(Size::COVER_BIG, true); + $this->expectException(InvalidArgumentException::class); - self::assertEquals('//images.igdb.com/igdb/image/upload/t_cover_big_2x/abc.jpg', $url); + Artwork::first()->getUrl('foo'); } } diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 713475c..419ee1e 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -11,6 +11,7 @@ use Illuminate\Support\Str; use MarcReichel\IGDBLaravel\Enums\Webhook\Category; use MarcReichel\IGDBLaravel\Enums\Webhook\Method; +use MarcReichel\IGDBLaravel\Exceptions\InvalidWebhookMethodException; use MarcReichel\IGDBLaravel\Exceptions\WebhookSecretMissingException; use MarcReichel\IGDBLaravel\Models\Artwork; use MarcReichel\IGDBLaravel\Models\Company; @@ -72,6 +73,37 @@ public function testItShouldGenerateWebhook(): void self::assertEquals('http://localhost/' . $this->prefix . '/artworks/delete', $webhook->url); } + public function testItShouldGenerateWebhookWithStringMethod(): void + { + $webhook = Game::createWebhook('create'); + + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'games')); + + self::assertEquals(0, $webhook->sub_category); + self::assertEquals('http://localhost/' . $this->prefix . '/games/create', $webhook->url); + + $webhook = Company::createWebhook('update'); + + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'companies')); + + self::assertEquals(2, $webhook->sub_category); + self::assertEquals('http://localhost/' . $this->prefix . '/companies/update', $webhook->url); + + $webhook = Artwork::createWebhook('delete'); + + Http::assertSent(fn (Request $request) => $this->isWebhookCall($request, 'artworks')); + + self::assertEquals(1, $webhook->sub_category); + self::assertEquals('http://localhost/' . $this->prefix . '/artworks/delete', $webhook->url); + } + + public function testItShouldThrowExceptionWithInvalidMethod(): void + { + $this->expectException(InvalidWebhookMethodException::class); + + Game::createWebhook('foo'); + } + public function testItShouldThrowExceptionWhenNoSecretIsSet(): void { $this->expectException(WebhookSecretMissingException::class); From ebe40a4030f979f46b64778a1eb8620d32fbb4d2 Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Fri, 3 Nov 2023 14:30:38 +0100 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=8E=A8=20Fix=20code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Image.php b/src/Models/Image.php index 3310e18..72b68b5 100644 --- a/src/Models/Image.php +++ b/src/Models/Image.php @@ -40,7 +40,7 @@ public function getUrl(Size | string $size = Size::THUMBNAIL, bool $retina = fal ->toArray(); if (!in_array($parsedSize, $cases, true)) { - throw new InvalidArgumentException('Size must be one of ' . implode(', ', $cases)); + throw new InvalidArgumentException('Size must be one of ' . implode(', ', $cases)); } if ($retina) {