Issues (68)

src/Utils/Utils.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bakery\Utils;
4
5
use Illuminate\Support\Str;
6
use Bakery\Exceptions\InvariantViolation;
7
8
class Utils
9
{
10
    /**
11
     * @param $test
12
     * @param string $message
13
     * @param array $args
14
     */
15
    public static function invariant($test, $message = '', ...$args)
16
    {
17
        if (! $test) {
18
            if (count($args)) {
19
                $message = sprintf($message, $args);
0 ignored issues
show
$args of type array is incompatible with the type string expected by parameter $args of sprintf(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
                $message = sprintf($message, /** @scrutinizer ignore-type */ $args);
Loading history...
20
            }
21
22
            throw new InvariantViolation($message);
23
        }
24
    }
25
26
    public static function single($class)
27
    {
28
        return Str::camel(Str::singular(class_basename($class)));
29
    }
30
31
    public static function plural($class)
32
    {
33
        return Str::camel(Str::plural(class_basename($class)));
34
    }
35
36
    public static function typename($class)
37
    {
38
        return Str::studly(Str::singular(class_basename($class)));
39
    }
40
41
    public static function pluralTypename($class)
42
    {
43
        return Str::studly(Str::plural(class_basename($class)));
44
    }
45
}
46