Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
NameUtils
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
8 / 8
8
100.00% covered (success)
100.00%
1 / 1
 titleCase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 studlyCase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModelName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getControllerName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRouteName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVariableName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVariableNamePlural
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPolicyName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace San\Crud\Utils;
4
5use Illuminate\Support\Str;
6
7class NameUtils {
8    public static function titleCase(string $name) {
9        return Str::title(str_replace('_', ' ', $name));
10    }
11
12    public static function studlyCase(string|array $tables) {
13        return join('', array_map(fn($tableName) => Str::studly(Str::singular($tableName)), (array) $tables));
14    }
15
16    public static function getModelName(string|array $tables) {
17        return self::studlyCase((array) $tables);
18    }
19
20    public static function getControllerName(string|array $tables) {
21        return self::studlyCase((array) $tables) . 'Controller';
22    }
23
24    public static function getRouteName(string|array $tables) {
25        return join('.', array_map(fn($tableName) => Str::kebab(Str::plural($tableName)), (array) $tables));
26    }
27
28    public static function getVariableName(string $table) {
29        return Str::singular(self::getVariableNamePlural($table));
30    }
31
32    public static function getVariableNamePlural(string $table) {
33        return Str::camel($table);
34    }
35
36    public static function getPolicyName(string|array $tables) {
37        return self::studlyCase((array) $tables) . 'Policy';
38    }
39}