Skip to content

Commit 9bf91f9

Browse files
committed
- updated to Laravel 12
- updated dependencies
1 parent 0865941 commit 9bf91f9

File tree

11 files changed

+122
-121
lines changed

11 files changed

+122
-121
lines changed

.github/workflows/lint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Fix Code Style
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
php: [8.2, 8.3, 8.4]
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
extensions: json, dom, curl, libxml, mbstring
22+
coverage: none
23+
24+
- name: Install Pint
25+
run: composer global require laravel/pint
26+
27+
- name: Run Pint
28+
run: pint
29+
30+
- name: Commit linted files
31+
uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/tests-php8.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
laravel: ['11.*']
21-
php: [8.1, 8.2, 8.3]
22-
exclude:
23-
- laravel: '11.*'
24-
php: 8.1
20+
laravel: ['12.*']
21+
php: [8.2, 8.3, 8.4]
2522
fail-fast: false
2623

2724
name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ php artisan vendor:publish --tag="utm-parameter"
3737
Once the package is installed, you can add the UtmParameters middleware to your Laravel application. Open the `bootstrap/app.php` file and append the `UtmParameters::class` inside the web-group.
3838

3939
```php
40-
# Laravel 11
40+
# Laravel 11+
4141
return Application::configure(basePath: dirname(__DIR__))
4242
...
4343
->withMiddleware(function (Middleware $middleware) {

composer.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
],
2020
"require": {
2121
"php": "^8.2",
22-
"illuminate/support": "^11.0",
23-
"illuminate/contracts": "^11.0"
22+
"illuminate/support": "^12.0",
23+
"illuminate/contracts": "^12.0"
2424
},
2525
"require-dev": {
26-
"nunomaduro/collision": "^8.1",
27-
"orchestra/testbench": "^9.0",
28-
"phpunit/phpunit": "^9.5|^10.0",
29-
"friendsofphp/php-cs-fixer": "^3.0"
26+
"friendsofphp/php-cs-fixer": "^3.0",
27+
"laravel/pint": "^1.13",
28+
"nunomaduro/collision": "^8.6",
29+
"orchestra/testbench": "^10.0",
30+
"phpunit/phpunit": "^11.5.3"
3031
},
3132
"autoload": {
3233
"psr-4": {
@@ -42,7 +43,8 @@
4243
}
4344
},
4445
"scripts": {
45-
"test": "vendor/bin/phpunit"
46+
"test": "./vendor/bin/phpunit",
47+
"lint": "./vendor/bin/pint"
4648
},
4749
"config": {
4850
"sort-packages": true

src/Facades/UtmParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class UtmParameter extends Facade
2121
{
22-
protected static function getFacadeAccessor()
22+
protected static function getFacadeAccessor(): string
2323
{
2424
return \Suarez\UtmParameter\UtmParameter::class;
2525
}

src/Middleware/UtmParameters.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class UtmParameters
1010
{
1111
/**
1212
* Handle an incoming request.
13-
*
14-
* @param \Illuminate\Http\Request $request
15-
* @param \Closure $next
16-
*
17-
* @return \Closure
1813
*/
1914
public function handle(Request $request, Closure $next)
2015
{
@@ -27,12 +22,8 @@ public function handle(Request $request, Closure $next)
2722

2823
/**
2924
* Determines whether the given request/response pair should accept UTM-Parameters.
30-
*
31-
* @param \Illuminate\Http\Request $request
32-
*
33-
* @return bool
3425
*/
35-
protected function shouldAcceptUtmParameter(Request $request)
26+
protected function shouldAcceptUtmParameter(Request $request): bool
3627
{
3728
return $request->isMethod('GET');
3829
}

src/Providers/UtmParameterServiceProvider.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,42 @@
22

33
namespace Suarez\UtmParameter\Providers;
44

5-
use Illuminate\Support\Facades\Blade;
6-
use Suarez\UtmParameter\UtmParameter;
75
use Illuminate\Foundation\AliasLoader;
6+
use Illuminate\Support\Facades\Blade;
87
use Illuminate\Support\ServiceProvider;
8+
use Suarez\UtmParameter\UtmParameter;
99

1010
class UtmParameterServiceProvider extends ServiceProvider
1111
{
1212
/**
1313
* Register any application services.
14-
*
15-
* @return void
1614
*/
17-
public function register()
15+
public function register(): void
1816
{
19-
$this->app->singleton(UtmParameter::class, fn () => new UtmParameter());
17+
$this->app->singleton(UtmParameter::class, fn () => new UtmParameter);
2018
$this->mergeConfigFrom(__DIR__.'/../config/utm-parameter.php', 'utm-parameter');
2119
}
2220

2321
/**
2422
* Bootstrap any application services.
25-
*
26-
* @return void
2723
*/
28-
public function boot()
24+
public function boot(): void
2925
{
3026
$this->publishes([__DIR__.'/../config/utm-parameter.php' => config_path('utm-parameter.php')], 'utm-parameter');
3127

32-
Blade::if('hasUtm', function (string $key, string|null $value = null) {
28+
Blade::if('hasUtm', function (string $key, ?string $value = null): bool {
3329
return has_utm($key, $value);
3430
});
3531

36-
Blade::if('hasNotUtm', function (string $key, string|null $value = null) {
32+
Blade::if('hasNotUtm', function (string $key, ?string $value = null): bool {
3733
return has_not_utm($key, $value);
3834
});
3935

40-
Blade::if('containsUtm', function (string $key, string|null $value = null) {
36+
Blade::if('containsUtm', function (string $key, ?string $value = null): bool {
4137
return contains_utm($key, $value);
4238
});
4339

44-
Blade::if('containsNotUtm', function (string $key, string|null $value = null) {
40+
Blade::if('containsNotUtm', function (string $key, ?string $value = null): bool {
4541
return contains_not_utm($key, $value);
4642
});
4743

src/UtmParameter.php

+22-50
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@ class UtmParameter
88
{
99
/**
1010
* Bag containing all UTM-Parameters.
11-
*
12-
* @var array
1311
*/
14-
public array|null $parameters;
12+
public ?array $parameters;
1513

1614
/**
1715
* Utm Parameter Session Key.
18-
*
19-
* @var string
2016
*/
2117
public string $sessionKey;
2218

23-
2419
public function __construct(array $parameters = [])
2520
{
2621
$this->sessionKey = config('utm-parameter.session_key');
@@ -29,36 +24,32 @@ public function __construct(array $parameters = [])
2924

3025
/**
3126
* Bootstrap UtmParameter.
32-
*
33-
* @param Request $request
34-
*
35-
* @return UtmParameter
3627
*/
37-
public function boot(Request $request)
28+
public function boot(Request $request): self
3829
{
3930
$this->parameters = $this->useRequestOrSession($request);
31+
4032
return $this;
4133
}
4234

4335
/**
4436
* Check which Parameters should be used.
45-
*
46-
* @param \Illuminate\Http\Request $request
47-
* @return array
4837
*/
49-
public function useRequestOrSession(Request $request)
38+
public function useRequestOrSession(Request $request): ?array
5039
{
5140
$currentRequestParameter = $this->getParameter($request);
5241
$sessionParameter = session($this->sessionKey);
5342

54-
if (!empty($currentRequestParameter) && empty($sessionParameter)) {
43+
if (! empty($currentRequestParameter) && empty($sessionParameter)) {
5544
session([$this->sessionKey => $currentRequestParameter]);
45+
5646
return $currentRequestParameter;
5747
}
5848

59-
if (!empty($currentRequestParameter) && !empty($sessionParameter) && config('utm-parameter.override_utm_parameters')) {
49+
if (! empty($currentRequestParameter) && ! empty($sessionParameter) && config('utm-parameter.override_utm_parameters')) {
6050
$mergedParameters = array_merge($sessionParameter, $currentRequestParameter);
6151
session([$this->sessionKey => $mergedParameters]);
52+
6253
return $mergedParameters;
6354
}
6455

@@ -67,27 +58,21 @@ public function useRequestOrSession(Request $request)
6758

6859
/**
6960
* Retrieve all UTM-Parameter.
70-
*
71-
* @return array
7261
*/
73-
public function all()
62+
public function all(): array
7463
{
7564
return session($this->sessionKey) ?? [];
7665
}
7766

7867
/**
7968
* Retrieve a UTM-Parameter by key.
80-
*
81-
* @param string $key
82-
*
83-
* @return string|null
8469
*/
85-
public function get(string $key)
70+
public function get(string $key): ?string
8671
{
8772
$parameters = $this->all();
8873
$key = $this->ensureUtmPrefix($key);
8974

90-
if (!array_key_exists($key, $parameters)) {
75+
if (! array_key_exists($key, $parameters)) {
9176
return null;
9277
}
9378

@@ -97,17 +82,14 @@ public function get(string $key)
9782
/**
9883
* Determine if a UTM-Parameter exists.
9984
*
100-
* @param string $key
101-
* @param string $value
102-
*
103-
* @return bool
85+
* @param string $value
10486
*/
105-
public function has(string $key, $value = null)
87+
public function has(string $key, $value = null): bool
10688
{
10789
$parameters = $this->all();
10890
$key = $this->ensureUtmPrefix($key);
10991

110-
if (!array_key_exists($key, $parameters)) {
92+
if (! array_key_exists($key, $parameters)) {
11193
return false;
11294
}
11395

@@ -120,17 +102,13 @@ public function has(string $key, $value = null)
120102

121103
/**
122104
* Determine if a value contains inside the key.
123-
*
124-
* @param string $key
125-
* @param string $value
126-
* @return bool
127105
*/
128-
public function contains(string $key, string $value)
106+
public function contains(string $key, string $value): bool
129107
{
130108
$parameters = $this->all();
131109
$key = $this->ensureUtmPrefix($key);
132110

133-
if (!array_key_exists($key, $parameters) || !is_string($value)) {
111+
if (! array_key_exists($key, $parameters) || ! is_string($value)) {
134112
return false;
135113
}
136114

@@ -139,44 +117,38 @@ public function contains(string $key, string $value)
139117

140118
/**
141119
* Clear and remove utm session.
142-
*
143-
* @return bool
144120
*/
145-
public function clear()
121+
public function clear(): bool
146122
{
147123
session()->forget($this->sessionKey);
148124
$this->parameters = null;
125+
149126
return true;
150127
}
151128

152129
/**
153130
* Retrieve all UTM-Parameter from the URI.
154-
*
155-
* @return array
156131
*/
157-
protected function getParameter(Request $request)
132+
protected function getParameter(Request $request): array
158133
{
159134
$allowedKeys = config('utm-parameter.allowed_utm_parameters', [
160-
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'
135+
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',
161136
]);
162137

163138
return collect($request->all())
164139
->filter(fn ($value, $key) => substr($key, 0, 4) === 'utm_')
165140
->filter(fn ($value, $key) => in_array($key, $allowedKeys))
166141
->mapWithKeys(fn ($value, $key) => [
167-
htmlspecialchars($key, ENT_QUOTES, 'UTF-8') => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
142+
htmlspecialchars($key, ENT_QUOTES, 'UTF-8') => htmlspecialchars($value, ENT_QUOTES, 'UTF-8'),
168143
])
169144
->toArray();
170145
}
171146

172147
/**
173148
* Ensure the key to start with 'utm_'.
174-
*
175-
* @param string $key
176-
* @return string
177149
*/
178150
protected function ensureUtmPrefix(string $key): string
179151
{
180-
return str_starts_with($key, 'utm_') ? $key : 'utm_' . $key;
152+
return str_starts_with($key, 'utm_') ? $key : 'utm_'.$key;
181153
}
182154
}

0 commit comments

Comments
 (0)