Skip to content

Explicitly use parameter binding to prevent generating mangled FQN pr… #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2025
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
2 changes: 1 addition & 1 deletion src/Models/Projection.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function scopeName(Builder $query, string $projectorName): Builder
{
$this->projectionName = $projectorName;

return $query->where('projection_name', $projectorName);
return $query->whereRaw('projection_name = ?', [$projectorName]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Scopes/ProjectionScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProjectionScope implements Scope
public function apply(Builder $builder, Model $model): void
{
if (! $this->isAbstractProjection($model)) {
$builder->where('projection_name', $model::class);
$builder->whereRaw('projection_name = ?', [$model::class]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Traits/Projectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function projections(
$query = $this->morphToMany(Projection::class, 'projectable', 'time_series_projectables');

if (isset($projectionName)) {
$query->where('projection_name', $projectionName);
$query->whereRaw('projection_name = ?', [$projectionName]);
}

if (isset($periods) && is_string($periods)) {
Expand Down
27 changes: 15 additions & 12 deletions src/Projector.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,28 @@ private function parsePeriod(string $period): void
*/
private function findGlobalProjection(): Projection|null
{
return Projection::firstWhere([
['projection_name', $this->projectionName],
['key', $this->hasKey() ? $this->key() : null],
['period', '*'],
['start_date', null],
]);
return Projection::whereRaw('projection_name = ?', [$this->projectionName])
->where([
['key', $this->hasKey() ? $this->key() : null],
['period', '*'],
['start_date', null],
])
->first();
}

/**
* Finds the projection if it exists.
*/
private function findProjection(string $period): Projection|null
{
return Projection::firstWhere([
['projection_name', $this->projectionName],
['key', $this->hasKey() ? $this->key() : null],
['period', $period],
['start_date', app(TimeSeries::class)->resolveFloorDate($this->projectedModel->{$this->dateColumn}, $period)],
]);
return Projection::whereRaw('projection_name = ?', [$this->projectionName])
->where([
['key', $this->hasKey() ? $this->key() : null],
['period', $period],
['start_date', app(TimeSeries::class)->resolveFloorDate($this->projectedModel->{$this->dateColumn}, $period),
],
])
->first();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Collections/ProjectionCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function (Projection $lastProjection) {
/** @test */
public function it_is_formatted_to_a_time_series()
{
Log::factory()->create(['created_at' => today()]);
Log::factory()->create(['created_at' => today(), 'updated_at' => today()]);

/** @var ProjectionCollection $collection */
$collection = Projection::all();
Expand Down