Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Oct 3, 2024
1 parent 2dda36b commit 7fbd169
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public function scopeContaining(Builder $query, string $name, $locale = null): B
{
$locale = $locale ?? static::getLocale();

return $query->whereRaw('lower('.$this->getQuery()->getGrammar()->wrap('name->'.$locale).') like ?',
['%'.mb_strtolower($name).'%']);
return $query->whereRaw(
'lower('.$this->getQuery()->getGrammar()->wrap('name->'.$locale).') like ?',
['%'.mb_strtolower($name).'%']
);
}

public static function findOrCreate(
Expand Down Expand Up @@ -98,7 +100,7 @@ public static function findOrCreateFromString(string $name, string $type = null,

$tag = static::findFromString($name, $type, $locale);

if (!$tag) {
if (! $tag) {
$tag = static::create([
'name' => [$locale => $name],
'type' => $type,
Expand All @@ -115,7 +117,7 @@ public static function getTypes(): Collection

public function setAttribute($key, $value)
{
if (in_array($key, $this->translatable) && !is_array($value)) {
if (in_array($key, $this->translatable) && ! is_array($value)) {
return $this->setTranslation($key, static::getLocale(), $value);
}

Expand Down
27 changes: 17 additions & 10 deletions src/TaggedToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

class TaggedToMany extends Relation
{

public function __construct(Model $parent, string $related, public string|null $type = null)
{
$instance = new $related;
$instance = new $related();

parent::__construct($instance->query(), $parent);
}
Expand All @@ -24,8 +23,11 @@ public function __construct(Model $parent, string $related, public string|null $
#[\Override] public function addConstraints()
{
$this->query->select($this->related->getTable().".*")
->join("taggables as taggables_related", "taggables_related.taggable_id",
$this->related->getTable().".".$this->related->getKeyName())
->join(
"taggables as taggables_related",
"taggables_related.taggable_id",
$this->related->getTable().".".$this->related->getKeyName()
)
->join("taggables as taggables_parent", "taggables_parent.tag_id", "taggables_related.tag_id")
->join("tags", "taggables_parent.tag_id", "tags.id")
->where("taggables_parent.taggable_type", get_class($this->parent))
Expand All @@ -45,7 +47,7 @@ public function __construct(Model $parent, string $related, public string|null $
public function addEagerConstraints(array $models)
{
$this->query->select([$this->related->getTable().".*", "taggables_parent.taggable_id"])
->whereIn("taggables_parent.taggable_id", array_map(fn(Model $model) => $model->getKey(), $models))
->whereIn("taggables_parent.taggable_id", array_map(fn (Model $model) => $model->getKey(), $models))
;
}

Expand Down Expand Up @@ -98,12 +100,17 @@ public function addEagerConstraints(array $models)
*/
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
{
$query->join("taggables as taggables_related", "taggables_related.taggable_id",
$this->related->getTable().".".$this->related->getKeyName())
$query->join(
"taggables as taggables_related",
"taggables_related.taggable_id",
$this->related->getTable().".".$this->related->getKeyName()
)
->join("taggables as taggables_parent", function (JoinClause $join) {
$join->on("taggables_parent.tag_id", "taggables_related.tag_id")
->on("taggables_parent.taggable_id",
$this->parent->getTable().".".$this->parent->getKeyName())
->on(
"taggables_parent.taggable_id",
$this->parent->getTable().".".$this->parent->getKeyName()
)
;
})
->join("tags", "taggables_parent.tag_id", "tags.id")
Expand All @@ -112,4 +119,4 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,

return $query;
}
}
}
2 changes: 0 additions & 2 deletions tests/TaggedToManyTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Spatie\Tags\Tag;
use Spatie\Tags\Test\TestClasses\TestAnotherModel;
use Spatie\Tags\Test\TestClasses\TestModel;

Expand Down

0 comments on commit 7fbd169

Please sign in to comment.