Code Duplication    Length = 26-26 lines in 2 locations

src/ServiceProvider.php 1 location

@@ 435-460 (lines=26) @@
432
     * @throws \InvalidArgumentException
433
     * @throws \UnexpectedValueException
434
     */
435
    public static function createSlug($model, string $attribute, string $fromString, array $config = null): string
436
    {
437
        if (is_string($model)) {
438
            $model = new $model;
439
        }
440
        /** @var static $instance */
441
        $instance = (new static())->setModel($model);
442
443
        if ($config === null) {
444
            $config = Arr::get($model->sluggable(), $attribute);
445
            if ($config === null) {
446
                $modelClass = get_class($model);
447
                throw new \InvalidArgumentException("Argument 2 passed to SlugService::createSlug ['{$attribute}'] is not a valid slug attribute for model {$modelClass}.");
448
            }
449
        } elseif (!is_array($config)) {
450
            throw new \UnexpectedValueException('SlugService::createSlug expects an array or null as the fourth argument; ' . gettype($config) . ' given.');
451
        }
452
453
        $config = $instance->getConfiguration($config);
454
455
        $slug = $instance->generateSlug($fromString, $config, $attribute);
456
        $slug = $instance->validateSlug($slug, $config, $attribute);
457
        $slug = $instance->makeSlugUnique($slug, $config, $attribute);
458
459
        return $slug;
460
    }
461
462
    /**
463
     * @param \Illuminate\Database\Eloquent\Model $model

src/Services/SlugService.php 1 location

@@ 421-446 (lines=26) @@
418
     * @throws \InvalidArgumentException
419
     * @throws \UnexpectedValueException
420
     */
421
    public static function createSlug($model, string $attribute, string $fromString, array $config = null): string
422
    {
423
        if (is_string($model)) {
424
            $model = new $model;
425
        }
426
        /** @var static $instance */
427
        $instance = (new static())->setModel($model);
428
429
        if ($config === null) {
430
            $config = Arr::get($model->sluggable(), $attribute);
431
            if ($config === null) {
432
                $modelClass = get_class($model);
433
                throw new \InvalidArgumentException("Argument 2 passed to SlugService::createSlug ['{$attribute}'] is not a valid slug attribute for model {$modelClass}.");
434
            }
435
        } elseif (!is_array($config)) {
436
            throw new \UnexpectedValueException('SlugService::createSlug expects an array or null as the fourth argument; ' . gettype($config) . ' given.');
437
        }
438
439
        $config = $instance->getConfiguration($config);
440
441
        $slug = $instance->generateSlug($fromString, $config, $attribute);
442
        $slug = $instance->validateSlug($slug, $config, $attribute);
443
        $slug = $instance->makeSlugUnique($slug, $config, $attribute);
444
445
        return $slug;
446
    }
447
448
    /**
449
     * @param \Illuminate\Database\Eloquent\Model $model