Skip to content

Commit 8b28bcb

Browse files
authored
Merge pull request #77 from coderflexx/pr-73
Laravel 12 Compatibility
2 parents 7748f4e + 4f6bafc commit 8b28bcb

File tree

13 files changed

+39
-105
lines changed

13 files changed

+39
-105
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ on:
1111
jobs:
1212
test:
1313
runs-on: ${{ matrix.os }}
14+
1415
strategy:
1516
fail-fast: true
1617
matrix:
1718
os: [ubuntu-latest, windows-latest]
1819
php: [8.1, 8.2, 8.3]
19-
laravel: ["10.*", "11.*"]
20+
laravel: ['10.*', '11.*', '12.*']
2021
stability: [prefer-lowest, prefer-stable]
2122
include:
2223
- laravel: 10.*
23-
testbench: ^8.0
24+
testbench: 8.*
2425
- laravel: 11.*
2526
testbench: ^9.0
27+
- laravel: 12.*
28+
testbench: ^10.0
2629
exclude:
2730
- laravel: 11.*
2831
php: 8.1
32+
- laravel: 12.*
33+
php: 8.1
2934

3035
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
3136

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
"require": {
1919
"php": "^8.1",
2020
"coderflexx/laravel-presenter": "^2.0",
21-
"illuminate/contracts": "^10.0|^11.0",
21+
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0",
2222
"jaybizzle/crawler-detect": "^1.2",
2323
"spatie/laravel-package-tools": "^1.9.2"
2424
},
2525
"require-dev": {
26+
"laravel/pint": "^1.0",
2627
"nunomaduro/collision": "^7.0|^8.0",
27-
"nunomaduro/larastan": "^1.0|^2.0",
28-
"orchestra/testbench": "^8.0|^9.0",
29-
"pestphp/pest": "^1.22|^2.34",
28+
"nunomaduro/larastan": "^2.0.1|^3.0",
29+
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
3030
"phpstan/extension-installer": "^1.1",
31-
"phpstan/phpstan-deprecation-rules": "^1.0",
32-
"phpstan/phpstan-phpunit": "^1.0",
33-
"phpunit/phpunit": "^9.5|^10.0"
31+
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
32+
"phpstan/phpstan-phpunit": "^1.0|^2.0",
33+
"phpunit/phpunit": "^9.5|^10.0|^11.0",
34+
"pestphp/pest": "^1.21|^2.0|^3.7"
3435
},
3536
"autoload": {
3637
"psr-4": {

config/laravisit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
| User Namespace
77
|--------------------------------------------------------------------------
88
|
9-
| This value informs Laravist which namespace you will be
9+
| This value informs Laravist which namespace you will be
1010
| selecting to get the user model instance
11-
| If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used
11+
| If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used
1212
| by default.
1313
|
1414
*/

src/Concerns/FilterByPopularityTimeFrame.php

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ trait FilterByPopularityTimeFrame
1313
{
1414
/**
1515
* Get the total visit count
16-
*
17-
* @param Builder $builder
18-
* @return \Illuminate\Database\Eloquent\Builder
1916
*/
2017
public function scopeWithTotalVisitCount(Builder $builder): Builder
2118
{
@@ -24,21 +21,15 @@ public function scopeWithTotalVisitCount(Builder $builder): Builder
2421

2522
/**
2623
* Get the popular visits all time
27-
*
28-
* @param Builder $builder
29-
* @return \Illuminate\Database\Eloquent\Builder
3024
*/
3125
public function scopePopularAllTime(Builder $builder): Builder
3226
{
3327
return $builder->withTotalVisitCount()
34-
->orderBy('visit_count_total', 'desc');
28+
->orderBy('visit_count_total', 'desc');
3529
}
3630

3731
/**
3832
* Get the popular visits today
39-
*
40-
* @param Builder $builder
41-
* @return \Illuminate\Database\Eloquent\Builder
4233
*/
4334
public function scopePopularToday(Builder $builder): Builder
4435
{
@@ -50,10 +41,6 @@ public function scopePopularToday(Builder $builder): Builder
5041

5142
/**
5243
* Get the popular visits last given days
53-
*
54-
* @param Builder $builder
55-
* @param int $days
56-
* @return \Illuminate\Database\Eloquent\Builder
5744
*/
5845
public function scopePopularLastDays(Builder $builder, int $days): Builder
5946
{
@@ -65,9 +52,6 @@ public function scopePopularLastDays(Builder $builder, int $days): Builder
6552

6653
/**
6754
* Get the popular visits this week
68-
*
69-
* @param Builder $builder
70-
* @return \Illuminate\Database\Eloquent\Builder
7155
*/
7256
public function scopePopularThisWeek(Builder $builder): Builder
7357
{
@@ -79,9 +63,6 @@ public function scopePopularThisWeek(Builder $builder): Builder
7963

8064
/**
8165
* Get the popular visits last week
82-
*
83-
* @param Builder $builder
84-
* @return \Illuminate\Database\Eloquent\Builder
8566
*/
8667
public function scopePopularLastWeek(Builder $builder): Builder
8768
{
@@ -93,9 +74,6 @@ public function scopePopularLastWeek(Builder $builder): Builder
9374

9475
/**
9576
* Get the popular visits this month
96-
*
97-
* @param Builder $builder
98-
* @return \Illuminate\Database\Eloquent\Builder
9977
*/
10078
public function scopePopularThisMonth(Builder $builder): Builder
10179
{
@@ -107,9 +85,6 @@ public function scopePopularThisMonth(Builder $builder): Builder
10785

10886
/**
10987
* Get the popular visits last month
110-
*
111-
* @param Builder $builder
112-
* @return \Illuminate\Database\Eloquent\Builder
11388
*/
11489
public function scopePopularLastMonth(Builder $builder): Builder
11590
{
@@ -121,9 +96,6 @@ public function scopePopularLastMonth(Builder $builder): Builder
12196

12297
/**
12398
* Get the popular visits this year
124-
*
125-
* @param Builder $builder
126-
* @return \Illuminate\Database\Eloquent\Builder
12799
*/
128100
public function scopePopularThisYear(Builder $builder): Builder
129101
{
@@ -135,9 +107,6 @@ public function scopePopularThisYear(Builder $builder): Builder
135107

136108
/**
137109
* Get the popular visits last year
138-
*
139-
* @param Builder $builder
140-
* @return \Illuminate\Database\Eloquent\Builder
141110
*/
142111
public function scopePopularLastYear(Builder $builder): Builder
143112
{
@@ -149,26 +118,17 @@ public function scopePopularLastYear(Builder $builder): Builder
149118

150119
/**
151120
* Get the popular visits between two dates
152-
*
153-
* @param Builder $builder
154-
* @param Carbon $from
155-
* @param Carbon $to
156-
* @return \Illuminate\Database\Eloquent\Builder
157121
*/
158122
public function scopePopularBetween(Builder $builder, Carbon $from, Carbon $to): Builder
159123
{
160124
return $builder->whereHas('visits', $this->betweenScope($from, $to))
161-
->withCount([
162-
'visits as visit_count_total' => $this->betweenScope($from, $to),
163-
]);
125+
->withCount([
126+
'visits as visit_count_total' => $this->betweenScope($from, $to),
127+
]);
164128
}
165129

166130
/**
167131
* Get the popular visits between two dates
168-
*
169-
* @param Carbon $from
170-
* @param Carbon $to
171-
* @return Closure
172132
*/
173133
protected function betweenScope(Carbon $from, Carbon $to): Closure
174134
{

src/Concerns/HasVisits.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ trait HasVisits
1515

1616
/**
1717
* keep track of your pages
18-
*
19-
* @return PendingVisit
2018
*/
2119
public function visit(): PendingVisit
2220
{
@@ -25,8 +23,6 @@ public function visit(): PendingVisit
2523

2624
/**
2725
* Has Visits relationship many to many relationship
28-
*
29-
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
3026
*/
3127
public function visits(): MorphMany
3228
{

src/Concerns/SetsPendingIntervals.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ trait SetsPendingIntervals
1111
{
1212
/**
1313
* @var \Carbon\Carbon
14-
*
1514
*/
1615
protected $interval;
1716

1817
/**
1918
* Interval available functions
2019
* key (method) => the name of carbon interval method
20+
*
2121
* @var array
2222
*/
2323
protected static $intervalsFunc = [
@@ -30,8 +30,6 @@ trait SetsPendingIntervals
3030

3131
/**
3232
* Set Time Intervals
33-
*
34-
* @return mixed
3533
*/
3634
public function __call($name, $arguments): mixed
3735
{
@@ -52,9 +50,6 @@ public function __call($name, $arguments): mixed
5250

5351
/**
5452
* Set Custom Interval
55-
*
56-
* @param mixed $interval
57-
* @return self
5853
*/
5954
public function customInterval(mixed $interval): self
6055
{

src/Exceptions/VisitException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class VisitException extends Exception
99
{
1010
/**
1111
* Method for Presenter Implementation absence on the model
12-
* @param Model $model
13-
* @return self
1412
*/
1513
public static function interfaceNotImplemented(Model $model): self
1614
{

src/Models/Visit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* Coderflex\Laravisit\Models\Visit
12+
*
1213
* @property int $id
1314
* @property array $data
1415
* @property \Illuminate\Support\Carbon|null $created_at
@@ -23,7 +24,7 @@ class Visit extends Model implements CanPresent
2324
*
2425
* @var string
2526
*/
26-
protected $table = "laravisits";
27+
protected $table = 'laravisits';
2728

2829
/**
2930
* The attributes that are mass assignable.

src/PendingVisit.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
class PendingVisit
1313
{
1414
use SetsPendingIntervals;
15+
1516
/**
1617
* @var array
17-
*
1818
*/
1919
protected $attributes = [];
2020

@@ -36,11 +36,8 @@ public function __construct(protected Model $model)
3636

3737
/**
3838
* Set IP attribute
39-
*
40-
* @param string $ip
41-
* @return self
4239
*/
43-
public function withIP(string $ip = null): self
40+
public function withIP(?string $ip = null): self
4441
{
4542
$this->attributes['ip'] = $ip ?? request()->ip();
4643

@@ -49,11 +46,8 @@ public function withIP(string $ip = null): self
4946

5047
/**
5148
* Set Session attribute
52-
*
53-
* @param string $session
54-
* @return self
5549
*/
56-
public function withSession(string $session = null): self
50+
public function withSession(?string $session = null): self
5751
{
5852
$this->attributes['session'] = $session ?? session()->getId();
5953

@@ -62,9 +56,6 @@ public function withSession(string $session = null): self
6256

6357
/**
6458
* Set Custom Data attribute
65-
*
66-
* @param array $data
67-
* @return self
6859
*/
6960
public function withData(array $data): self
7061
{
@@ -79,11 +70,8 @@ public function withData(array $data): self
7970

8071
/**
8172
* Set User attribute
82-
*
83-
* @param Model $user
84-
* @return self
8573
*/
86-
public function withUser(Model $user = null): self
74+
public function withUser(?Model $user = null): self
8775
{
8876
$this->attributes['user_id'] = $user?->id ?? auth()->id();
8977

@@ -92,24 +80,19 @@ public function withUser(Model $user = null): self
9280

9381
/**
9482
* Build Json Columns from the given attribues
95-
*
96-
* @return array
9783
*/
9884
protected function buildJsonColumns(): array
9985
{
10086
return collect($this->attributes)
10187
->mapWithKeys(
102-
fn ($value, $index) => ['data->' . $index => $value]
88+
fn ($value, $index) => ['data->'.$index => $value]
10389
)
10490
->toArray();
10591
}
10692

10793
/**
10894
* Make sure that we need to log the current record or not
10995
* based on the creation
110-
*
111-
* @param Visit $visit
112-
* @return bool
11396
*/
11497
protected function shouldBeLoggedAgain(Visit $visit): bool
11598
{

src/Presenters/VisitPresenter.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class VisitPresenter extends Presenter
99
{
1010
/**
1111
* Get the associated IP from the model instance
12-
*
13-
* @return string
1412
*/
1513
public function ip(): string
1614
{
@@ -19,8 +17,6 @@ public function ip(): string
1917

2018
/**
2119
* Get the associated User from the model instance
22-
*
23-
* @return Model
2420
*/
2521
public function user(): Model
2622
{

0 commit comments

Comments
 (0)