for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Thinktomorrow\Chief\Concerns\Sluggable;
class UniqueSlug
{
/** @var SluggableContract */
private $model;
/** @var array */
private $blacklist;
/** @var \Closure */
private $slugResolver;
public function __construct(SluggableContract $model, array $blacklist = [])
$this->model = $model;
$this->blacklist = $blacklist;
$this->slugResolver = function ($slug) {
return str_slug($slug);
str_slug()
If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated annotation
ignore-deprecated
return /** @scrutinizer ignore-deprecated */ str_slug($slug);
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
};
}
public static function make($model, array $blacklist = [])
return new static($model, $blacklist);
public function slugResolver(\Closure $resolver)
$this->slugResolver = $resolver;
return $this;
public function get($title, SluggableContract $entity = null)
$slug = $originalslug = $this->sluggify($title);
$i = 1;
while (!$this->isSlugUnique($slug, $entity)) {
$slug = $originalslug.'-'.$i;
$i++;
// Add to blacklist
$this->blacklist[] = $slug;
return $slug;
private function sluggify($value)
return call_user_func($this->slugResolver, $value);
/**
*
* @param $slug
* @param SluggableContract $entity
* @return bool
*/
private function isSlugUnique($slug, SluggableContract $entity = null)
$model = $this->model->findBySlug($slug);
if (!in_array($slug, $this->blacklist) && (!$model || ($entity && $entity->id && $model->id == $entity->id))) {
id
Thinktomorrow\Chief\Conc...gable\SluggableContract
instanceof
return true;
return false;
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.