Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ on:
jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.2, 8.3]
laravel: ["10.*", "11.*"]
laravel: ['10.*', '11.*', '12.*']
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: ^8.0
testbench: 8.*
- laravel: 11.*
testbench: ^9.0
- laravel: 12.*
testbench: ^10.0
exclude:
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: 8.1

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

Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
"require": {
"php": "^8.1",
"coderflexx/laravel-presenter": "^2.0",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0|^12.0",
"jaybizzle/crawler-detect": "^1.2",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0|^8.0",
"nunomaduro/larastan": "^1.0|^2.0",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^1.22|^2.34",
"nunomaduro/larastan": "^2.0.1|^3.0",
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5|^10.0"
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
"phpstan/phpstan-phpunit": "^1.0|^2.0",
"phpunit/phpunit": "^9.5|^10.0|^11.0",
"pestphp/pest": "^1.21|^2.0|^3.7"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions config/laravisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
| User Namespace
|--------------------------------------------------------------------------
|
| This value informs Laravist which namespace you will be
| This value informs Laravist which namespace you will be
| selecting to get the user model instance
| If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used
| If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used
| by default.
|
*/
Expand Down
48 changes: 4 additions & 44 deletions src/Concerns/FilterByPopularityTimeFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ trait FilterByPopularityTimeFrame
{
/**
* Get the total visit count
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWithTotalVisitCount(Builder $builder): Builder
{
Expand All @@ -24,21 +21,15 @@ public function scopeWithTotalVisitCount(Builder $builder): Builder

/**
* Get the popular visits all time
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularAllTime(Builder $builder): Builder
{
return $builder->withTotalVisitCount()
->orderBy('visit_count_total', 'desc');
->orderBy('visit_count_total', 'desc');
}

/**
* Get the popular visits today
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularToday(Builder $builder): Builder
{
Expand All @@ -50,10 +41,6 @@ public function scopePopularToday(Builder $builder): Builder

/**
* Get the popular visits last given days
*
* @param Builder $builder
* @param int $days
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularLastDays(Builder $builder, int $days): Builder
{
Expand All @@ -65,9 +52,6 @@ public function scopePopularLastDays(Builder $builder, int $days): Builder

/**
* Get the popular visits this week
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularThisWeek(Builder $builder): Builder
{
Expand All @@ -79,9 +63,6 @@ public function scopePopularThisWeek(Builder $builder): Builder

/**
* Get the popular visits last week
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularLastWeek(Builder $builder): Builder
{
Expand All @@ -93,9 +74,6 @@ public function scopePopularLastWeek(Builder $builder): Builder

/**
* Get the popular visits this month
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularThisMonth(Builder $builder): Builder
{
Expand All @@ -107,9 +85,6 @@ public function scopePopularThisMonth(Builder $builder): Builder

/**
* Get the popular visits last month
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularLastMonth(Builder $builder): Builder
{
Expand All @@ -121,9 +96,6 @@ public function scopePopularLastMonth(Builder $builder): Builder

/**
* Get the popular visits this year
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularThisYear(Builder $builder): Builder
{
Expand All @@ -135,9 +107,6 @@ public function scopePopularThisYear(Builder $builder): Builder

/**
* Get the popular visits last year
*
* @param Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularLastYear(Builder $builder): Builder
{
Expand All @@ -149,26 +118,17 @@ public function scopePopularLastYear(Builder $builder): Builder

/**
* Get the popular visits between two dates
*
* @param Builder $builder
* @param Carbon $from
* @param Carbon $to
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopularBetween(Builder $builder, Carbon $from, Carbon $to): Builder
{
return $builder->whereHas('visits', $this->betweenScope($from, $to))
->withCount([
'visits as visit_count_total' => $this->betweenScope($from, $to),
]);
->withCount([
'visits as visit_count_total' => $this->betweenScope($from, $to),
]);
}

/**
* Get the popular visits between two dates
*
* @param Carbon $from
* @param Carbon $to
* @return Closure
*/
protected function betweenScope(Carbon $from, Carbon $to): Closure
{
Expand Down
4 changes: 0 additions & 4 deletions src/Concerns/HasVisits.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ trait HasVisits

/**
* keep track of your pages
*
* @return PendingVisit
*/
public function visit(): PendingVisit
{
Expand All @@ -25,8 +23,6 @@ public function visit(): PendingVisit

/**
* Has Visits relationship many to many relationship
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function visits(): MorphMany
{
Expand Down
7 changes: 1 addition & 6 deletions src/Concerns/SetsPendingIntervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ trait SetsPendingIntervals
{
/**
* @var \Carbon\Carbon
*
*/
protected $interval;

/**
* Interval available functions
* key (method) => the name of carbon interval method
*
* @var array
*/
protected static $intervalsFunc = [
Expand All @@ -30,8 +30,6 @@ trait SetsPendingIntervals

/**
* Set Time Intervals
*
* @return mixed
*/
public function __call($name, $arguments): mixed
{
Expand All @@ -52,9 +50,6 @@ public function __call($name, $arguments): mixed

/**
* Set Custom Interval
*
* @param mixed $interval
* @return self
*/
public function customInterval(mixed $interval): self
{
Expand Down
2 changes: 0 additions & 2 deletions src/Exceptions/VisitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class VisitException extends Exception
{
/**
* Method for Presenter Implementation absence on the model
* @param Model $model
* @return self
*/
public static function interfaceNotImplemented(Model $model): self
{
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Coderflex\Laravisit\Models\Visit
*
* @property int $id
* @property array $data
* @property \Illuminate\Support\Carbon|null $created_at
Expand All @@ -23,7 +24,7 @@ class Visit extends Model implements CanPresent
*
* @var string
*/
protected $table = "laravisits";
protected $table = 'laravisits';

/**
* The attributes that are mass assignable.
Expand Down
27 changes: 5 additions & 22 deletions src/PendingVisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class PendingVisit
{
use SetsPendingIntervals;

/**
* @var array
*
*/
protected $attributes = [];

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

/**
* Set IP attribute
*
* @param string $ip
* @return self
*/
public function withIP(string $ip = null): self
public function withIP(?string $ip = null): self
{
$this->attributes['ip'] = $ip ?? request()->ip();

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

/**
* Set Session attribute
*
* @param string $session
* @return self
*/
public function withSession(string $session = null): self
public function withSession(?string $session = null): self
{
$this->attributes['session'] = $session ?? session()->getId();

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

/**
* Set Custom Data attribute
*
* @param array $data
* @return self
*/
public function withData(array $data): self
{
Expand All @@ -79,11 +70,8 @@ public function withData(array $data): self

/**
* Set User attribute
*
* @param Model $user
* @return self
*/
public function withUser(Model $user = null): self
public function withUser(?Model $user = null): self
{
$this->attributes['user_id'] = $user?->id ?? auth()->id();

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

/**
* Build Json Columns from the given attribues
*
* @return array
*/
protected function buildJsonColumns(): array
{
return collect($this->attributes)
->mapWithKeys(
fn ($value, $index) => ['data->' . $index => $value]
fn ($value, $index) => ['data->'.$index => $value]
)
->toArray();
}

/**
* Make sure that we need to log the current record or not
* based on the creation
*
* @param Visit $visit
* @return bool
*/
protected function shouldBeLoggedAgain(Visit $visit): bool
{
Expand Down
4 changes: 0 additions & 4 deletions src/Presenters/VisitPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class VisitPresenter extends Presenter
{
/**
* Get the associated IP from the model instance
*
* @return string
*/
public function ip(): string
{
Expand All @@ -19,8 +17,6 @@ public function ip(): string

/**
* Get the associated User from the model instance
*
* @return Model
*/
public function user(): Model
{
Expand Down
Loading
Loading