Skip to content

Commit

Permalink
Use Str to support PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara committed Dec 3, 2024
1 parent ac4647e commit 114c2ba
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Watchers/DeleteQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\LaravelRay\Watchers;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Str;
use Spatie\Ray\Settings\Settings;

class DeleteQueryWatcher extends ConditionalQueryWatcher
Expand All @@ -14,7 +15,7 @@ public function register(): void
$this->enabled = $settings->send_delete_queries_to_ray ?? false;

$this->setConditionalCallback(function (QueryExecuted $query) {
return str_starts_with(strtolower($query->toRawSql()), 'delete');
return Str::startsWith(strtolower($query->toRawSql()), 'delete');
});
}
}
3 changes: 2 additions & 1 deletion src/Watchers/InsertQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\LaravelRay\Watchers;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Str;
use Spatie\Ray\Settings\Settings;

class InsertQueryWatcher extends ConditionalQueryWatcher
Expand All @@ -14,7 +15,7 @@ public function register(): void
$this->enabled = $settings->send_insert_queries_to_ray ?? false;

$this->setConditionalCallback(function (QueryExecuted $query) {
return str_starts_with(strtolower($query->toRawSql()), 'insert');
return Str::startsWith(strtolower($query->toRawSql()), 'insert');
});
}
}
3 changes: 2 additions & 1 deletion src/Watchers/SelectQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\LaravelRay\Watchers;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Str;
use Spatie\Ray\Settings\Settings;

class SelectQueryWatcher extends ConditionalQueryWatcher
Expand All @@ -14,7 +15,7 @@ public function register(): void
$this->enabled = $settings->send_select_queries_to_ray ?? false;

$this->setConditionalCallback(function (QueryExecuted $query) {
return str_starts_with(strtolower($query->toRawSql()), 'select');
return Str::startsWith(strtolower($query->toRawSql()), 'select');
});
}
}
3 changes: 2 additions & 1 deletion src/Watchers/UpdateQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\LaravelRay\Watchers;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Str;
use Spatie\Ray\Settings\Settings;

class UpdateQueryWatcher extends ConditionalQueryWatcher
Expand All @@ -14,7 +15,7 @@ public function register(): void
$this->enabled = $settings->send_update_queries_to_ray ?? false;

$this->setConditionalCallback(function (QueryExecuted $query) {
return str_starts_with(strtolower($query->toRawSql()), 'update');
return Str::startsWith(strtolower($query->toRawSql()), 'update');
});
}
}
7 changes: 4 additions & 3 deletions tests/Unit/ConditionalQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Spatie\LaravelRay\Tests\TestClasses\User;
use Spatie\LaravelRay\Watchers\SelectQueryWatcher;
use Spatie\Ray\Settings\Settings;
Expand Down Expand Up @@ -51,7 +52,7 @@

it('can take a custom condition and only return those queries', function () {
ray()->showConditionalQueries(function (QueryExecuted $query) {
return str_contains($query->toRawSql(), 'joan');
return Str::contains($query->toRawSql(), 'joan');
});

User::query()->create(['email' => 'joan@example.com']);
Expand All @@ -72,12 +73,12 @@
it('can handle multiple conditional query watchers', function () {
$john = ray()->showConditionalQueries(
function (QueryExecuted $query) {
return str_contains($query->toRawSql(), 'joan');
return Str::contains($query->toRawSql(), 'joan');
},
function (): User {
ray()->showConditionalQueries(
function (QueryExecuted $query) {
return str_contains($query->toRawSql(), 'john');
return Str::contains($query->toRawSql(), 'john');
},
null,
'look for john'
Expand Down

0 comments on commit 114c2ba

Please # to comment.