From d82adc25e33dd14508e5c2e253593efdc012d34a Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 30 Mar 2024 10:44:12 +0100 Subject: [PATCH 1/5] style: add laravel pint --- .github/dependabot.yml | 12 ---------- .github/workflows/lint.yml | 14 ++++++++++++ .styleci.yml | 3 --- composer.json | 19 +++++++++++++++- src/CloudflareProxies.php | 22 ++++--------------- src/LaravelCloudflare.php | 6 ++--- .../Unit/Http/Middleware/TrustProxiesTest.php | 1 - 7 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/lint.yml delete mode 100644 .styleci.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8edd0ed..1c0670e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,21 +6,9 @@ updates: directory: "/" schedule: interval: weekly - time: "11:00" - labels: - - actions - - dependencies - - auto-squash # Maintain dependencies for Composer - package-ecosystem: composer directory: "/" schedule: interval: weekly - time: "07:00" - open-pull-requests-limit: 10 - versioning-strategy: lockfile-only - labels: - - php - - dependencies - - auto-squash diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..42d8394 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,14 @@ +name: Lint files + +on: + pull_request: + types: [opened, synchronize, reopened] + +concurrency: + group: Lint files ${{ github.ref }} + cancel-in-progress: true + +jobs: + php: + name: Lint PHP files + uses: monicahq/workflows/.github/workflows/lint_php.yml@v2 diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 6a678b7..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,3 +0,0 @@ -preset: laravel -enabled: - - fully_qualified_strict_types \ No newline at end of file diff --git a/composer.json b/composer.json index d3c8280..d57cfd2 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,10 @@ }, "require-dev": { "guzzlehttp/guzzle": "^6.3 || ^7.0", - "mockery/mockery": "^1.4", + "jschaedl/composer-git-hooks": "^4.0", "larastan/larastan": "^1.0 || ^2.4", + "laravel/pint": "^1.15", + "mockery/mockery": "^1.4", "ocramius/package-versions": "^1.5 || ^2.1", "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", "phpstan/phpstan-deprecation-rules": "^1.0", @@ -50,8 +52,23 @@ "providers": [ "Monicahq\\Cloudflare\\TrustedProxyServiceProvider" ] + }, + "hooks": { + "config": { + "stop-on-failure": [ + "pre-commit" + ] + }, + "pre-commit": [ + "files=$(git diff --staged --name-only);\"$(dirname \"$0\")/../../vendor/bin/pint\" $files; git add $files" + ] } }, + "scripts": { + "cghooks": "vendor/bin/cghooks", + "post-install-cmd": "cghooks add --ignore-lock", + "post-update-cmd": "cghooks update" + }, "suggest": { "guzzlehttp/guzzle": "Required to get cloudflares ip addresses (^6.5.5|^7.0)." }, diff --git a/src/CloudflareProxies.php b/src/CloudflareProxies.php index 81c8b72..8fa34d7 100644 --- a/src/CloudflareProxies.php +++ b/src/CloudflareProxies.php @@ -16,27 +16,13 @@ class CloudflareProxies public const IP_VERSION_ANY = self::IP_VERSION_4 | self::IP_VERSION_6; - /** - * The config repository instance. - * - * @var Repository - */ - protected $config; - - /** - * The http factory instance. - * - * @var HttpClient - */ - protected $http; - /** * Create a new instance of CloudflareProxies. */ - public function __construct(Repository $config, HttpClient $http) - { - $this->config = $config; - $this->http = $http; + public function __construct( + protected Repository $config, + protected HttpClient $http + ) { } /** diff --git a/src/LaravelCloudflare.php b/src/LaravelCloudflare.php index 97b7ad0..73c4e26 100644 --- a/src/LaravelCloudflare.php +++ b/src/LaravelCloudflare.php @@ -19,8 +19,8 @@ final class LaravelCloudflare */ public static function getProxies(): array { - if (static::$getProxiesCallback !== null) { - return call_user_func(static::$getProxiesCallback); + if (self::$getProxiesCallback !== null) { + return call_user_func(self::$getProxiesCallback); } return CloudflareProxies::load(); @@ -31,6 +31,6 @@ public static function getProxies(): array */ public static function getProxiesUsing(?Closure $callback): void { - static::$getProxiesCallback = $callback; + self::$getProxiesCallback = $callback; } } diff --git a/tests/Unit/Http/Middleware/TrustProxiesTest.php b/tests/Unit/Http/Middleware/TrustProxiesTest.php index 092b20f..ecc8f6d 100644 --- a/tests/Unit/Http/Middleware/TrustProxiesTest.php +++ b/tests/Unit/Http/Middleware/TrustProxiesTest.php @@ -4,7 +4,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Route; use Monicahq\Cloudflare\Http\Middleware\TrustProxies; use Monicahq\Cloudflare\LaravelCloudflare; use Monicahq\Cloudflare\Tests\FeatureTestCase; From 7b6b221540dd86924ec0c7136a1d49d04adf9687 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 4 May 2024 11:49:24 +0200 Subject: [PATCH 2/5] update --- .github/workflows/static.yml | 2 +- .github/workflows/tests.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0cb958d..3a8db18 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -9,4 +9,4 @@ jobs: name: Static analysis uses: monicahq/workflows/.github/workflows/static.yml@v2 with: - php-version: 8.2 + php-version: 8.3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 88ef9d6..c88b67d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,11 +26,11 @@ jobs: name: Run tests uses: monicahq/workflows/.github/workflows/library.yml@v2 with: - php-versions: "['8.0', '8.1', '8.2', '8.3']" - laravel-versions: "['8.*', '9.*', '10.*', '11.*']" - default-php-version: '8.2' - default-laravel-version: '10.*' - matrix-exclude: "[{'php-version': '8.0', 'laravel-version': '10.*'},{'php-version': '8.0', 'laravel-version': '11.*'},{'php-version': '8.1', 'laravel-version': '11.*'}]" + php-versions: "['8.1', '8.2', '8.3']" + laravel-versions: "['^9.0', '^10.0', '^11.0']" + default-php-version: '8.3' + default-laravel-version: '^11.0' + matrix-exclude: "[{'php-version': '8.1', 'laravel-version': '^11.0'}]" project: monicahq_laravel-cloudflare secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 46c120ecfa9d53be4b4cfaad8e9c6ac9acca2b97 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 4 May 2024 11:58:49 +0200 Subject: [PATCH 3/5] test --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 3a8db18..1e94ce6 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -7,6 +7,6 @@ on: jobs: statics: name: Static analysis - uses: monicahq/workflows/.github/workflows/static.yml@v2 + uses: monicahq/workflows/.github/workflows/static.yml@20240504-static with: php-version: 8.3 From 8688942b35094d0724087493b4f15c8f3cbf505f Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 4 May 2024 12:03:40 +0200 Subject: [PATCH 4/5] fix --- src/CloudflareProxies.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/CloudflareProxies.php b/src/CloudflareProxies.php index 8fa34d7..fb94fa6 100644 --- a/src/CloudflareProxies.php +++ b/src/CloudflareProxies.php @@ -10,10 +10,25 @@ class CloudflareProxies { + /** + * Use IPv4 addresses. + * + * @var int + */ public const IP_VERSION_4 = 1 << 0; + /** + * Use IPv6 addresses. + * + * @var int + */ public const IP_VERSION_6 = 1 << 1; + /** + * Use any IP addresses. + * + * @var int + */ public const IP_VERSION_ANY = self::IP_VERSION_4 | self::IP_VERSION_6; /** From ed844ce9fcef5d1c6bc84fe0ce594e536a590830 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 4 May 2024 12:53:14 +0200 Subject: [PATCH 5/5] fix --- .github/workflows/static.yml | 2 +- psalm.xml | 46 +++++++++++++----------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 1e94ce6..3a8db18 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -7,6 +7,6 @@ on: jobs: statics: name: Static analysis - uses: monicahq/workflows/.github/workflows/static.yml@20240504-static + uses: monicahq/workflows/.github/workflows/static.yml@v2 with: php-version: 8.3 diff --git a/psalm.xml b/psalm.xml index 5106cb4..4c78738 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,6 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + findUnusedBaselineEntry="true" + findUnusedCode="false" > @@ -13,41 +15,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + + + + + - + - + - +