Skip to content

Commit

Permalink
Merge pull request #80 from marcreichel/refactoring
Browse files Browse the repository at this point in the history
♻️ Refactor code
  • Loading branch information
marcreichel committed Nov 3, 2023
2 parents 20d98ae + ebe40a4 commit e8b5965
Show file tree
Hide file tree
Showing 278 changed files with 2,497 additions and 4,292 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/code-style-pr.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": "^1.13"
},
"license": "MIT",
"authors": [
Expand All @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<?php

declare(strict_types=1);

return [
/*
* These are the credentials you got from https://dev.twitch.tv/console/apps
/**
* These are the credentials you got from https://dev.twitch.tv/console/apps.
*/
'credentials' => [
'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
Expand Down
6 changes: 3 additions & 3 deletions docs/12-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is supported for:
- `CharacterMugShot`
- `CompanyLogo`
- `Cover`
- `EventLogo`
- `GameEngineLogo`
- `PlatformLogo`
- `Screenshot`
Expand All @@ -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}
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
Expand Down
130 changes: 130 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
10 changes: 4 additions & 6 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

declare(strict_types=1);

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use MarcReichel\IGDBLaravel\Models\Webhook;

/**
* @deprecated
*/
Route::post('{model}/{method}', 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}', 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');
5 changes: 3 additions & 2 deletions src/ApiHelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MarcReichel\IGDBLaravel;

use Exception;
Expand All @@ -14,7 +16,6 @@ class ApiHelper
/**
* Retrieves an Access Token from Twitch.
*
* @return string
* @throws AuthenticationException
*/
public static function retrieveAccessToken(): string
Expand All @@ -38,7 +39,7 @@ public static function retrieveAccessToken(): string
->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'];
}
Expand Down
Loading

0 comments on commit e8b5965

Please sign in to comment.