Skip to content

Commit

Permalink
php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
cviebrock committed Dec 20, 2024
1 parent 21a0efd commit ed757b7
Show file tree
Hide file tree
Showing 28 changed files with 279 additions and 418 deletions.
32 changes: 16 additions & 16 deletions resources/config/taggable.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
<?php

return [
use Cviebrock\EloquentTaggable\Models\Tag;

/**
return [
/*
* List of characters that can delimit the tags passed to the
* tag() / untag() / etc. functions.
*/
'delimiters' => ',;',
'delimiters' => ',;',

/**
/*
* Character used to delimit tag lists returned in the
* tagList, tagListNormalized, etc. attributes.
*/
'glue' => ',',
'glue' => ',',

/**
/*
* Method used to "normalize" tag names. Can either be a global function name,
* a closure function, or a callable, e.g. ['Classname', 'method'].
*/
'normalizer' => 'mb_strtolower',
'normalizer' => 'mb_strtolower',

/**
/*
* The database connection to use for the Tag model and associated tables.
* By default, we use the default database connection, but this can be defined
* so that all the tag-related tables are stored in a different connection.
*/
'connection' => null,
'connection' => null,

/**
/*
* How to handle passing empty values to the scope queries. When set to false,
* the scope queries will return no models. When set to true, passing an empty
* value to the scope queries will throw an exception instead.
*/
'throwEmptyExceptions' => false,

/**
/*
* If you want to be able to find all the models that share a tag, you will need
* to define the inverse relations here. The array keys are the relation names
* you would use to access them (e.g. "posts") and the values are the qualified
Expand All @@ -54,20 +55,19 @@

'taggedModels' => [],

/**
/*
* The model used to store the tags in the database. You can
* create your own class that extends the package's Tag model,
* then update the configuration below.
*/
'model' => \Cviebrock\EloquentTaggable\Models\Tag::class,

'model' => Tag::class,

/**
/*
* The tables used to store the tags in the database. You can
* publish the package's migrations and use custom names.
*/
'tables' => [
'taggable_tags' => 'taggable_tags',
'taggable_taggables' => 'taggable_taggables',
]
],
];
15 changes: 7 additions & 8 deletions src/Events/ModelTagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace Cviebrock\EloquentTaggable\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelTagged
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

private $model;
private $tags;
Expand All @@ -36,7 +34,8 @@ public function getTags()
/**
* Create a new event instance.
*
* @return void
* @param mixed $model
* @param mixed $tags
*/
public function __construct($model, $tags)
{
Expand Down
16 changes: 7 additions & 9 deletions src/Events/ModelUntagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace Cviebrock\EloquentTaggable\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelUntagged
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

private $model;
private $tags;
Expand All @@ -36,12 +34,12 @@ public function getTags()
/**
* Create a new event instance.
*
* @return void
* @param mixed $model
* @param mixed $tags
*/
public function __construct($model, $tags)
{
$this->model = $model;
$this->tags = $tags;
}

}
11 changes: 5 additions & 6 deletions src/Exceptions/NoTagsSpecifiedException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php namespace Cviebrock\EloquentTaggable\Exceptions;
<?php

namespace Cviebrock\EloquentTaggable\Exceptions;

/**
* Class NoTagsSpecifiedException
* Class NoTagsSpecifiedException.
*/
class NoTagsSpecifiedException extends \Exception
{

}
class NoTagsSpecifiedException extends \Exception {}
36 changes: 12 additions & 24 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<?php namespace Cviebrock\EloquentTaggable\Models;
<?php

namespace Cviebrock\EloquentTaggable\Models;

use Cviebrock\EloquentTaggable\Services\TagService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Arr;


/**
* Class Tag
* Class Tag.
*
* @property int $tag_id
* @property int $tag_id
* @property string $name
* @property string $normalized
*/
class Tag extends Model
{

/**
* @inheritdoc
* {@inheritdoc}
*/
protected $table;

/**
* @inheritdoc
* {@inheritdoc}
*/
protected $primaryKey = 'tag_id';

/**
* @inheritdoc
* {@inheritdoc}
*/
protected $fillable = [
'name',
'normalized',
];

/**
* @inheritdoc
* {@inheritdoc}
*/
public function __construct(array $attributes = [])
{
Expand Down Expand Up @@ -64,11 +64,6 @@ public function setNameAttribute($value)

/**
* Scope to find tags by name.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $value
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeByName(Builder $query, string $value): Builder
{
Expand All @@ -78,7 +73,7 @@ public function scopeByName(Builder $query, string $value): Builder
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function isRelation($key)
{
Expand All @@ -93,7 +88,7 @@ public function isRelation($key)
if ($relatedClass) {
$relation = $this->taggedModels($relatedClass);

return tap($relation->getResults(), function($results) use ($key) {
return tap($relation->getResults(), function ($results) use ($key) {
$this->setRelation($key, $results);
});
}
Expand All @@ -104,10 +99,6 @@ public function isRelation($key)
/**
* Get the inverse of the polymorphic relation, via an attribute
* defining the type of models to return.
*
* @param string $class
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
protected function taggedModels(string $class): MorphToMany
{
Expand All @@ -119,8 +110,6 @@ protected function taggedModels(string $class): MorphToMany
/**
* Find the tag with the given name.
*
* @param string $value
*
* @return static|null
*/
public static function findByName(string $value)
Expand All @@ -129,11 +118,10 @@ public static function findByName(string $value)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function __toString(): string
{
return (string) $this->getAttribute('name');
}

}
18 changes: 7 additions & 11 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php namespace Cviebrock\EloquentTaggable;
<?php

namespace Cviebrock\EloquentTaggable;

use Cviebrock\EloquentTaggable\Services\TagService;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;


/**
* Class ServiceProvider
*
* @package Cviebrock\EloquentTaggable
* Class ServiceProvider.
*/
class ServiceProvider extends LaravelServiceProvider
{

/**
* @inheritdoc
* {@inheritdoc}
*/
protected $defer = false;

Expand All @@ -28,19 +26,17 @@ public function boot(): void

if (!class_exists('CreateTaggableTable')) {
$this->publishes([
__DIR__.'/../resources/database/migrations/create_taggable_table.php.stub' => database_path('migrations/' . date('Y_m_d_His') . '_create_taggable_table.php'),
__DIR__ . '/../resources/database/migrations/create_taggable_table.php.stub' => database_path('migrations/' . date('Y_m_d_His') . '_create_taggable_table.php'),
], 'migrations');
}

$this->loadMigrationsFrom(
__DIR__.'/../resources/database/migrations'
__DIR__ . '/../resources/database/migrations'
);
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
Expand Down
Loading

0 comments on commit ed757b7

Please sign in to comment.