Classes::getClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace SoliDry\Helpers;
3
4
use SoliDry\Types\DirsInterface;
5
use SoliDry\Types\PhpInterface;
6
7
class Classes
8
{
9
10
    /**
11
     * @param string $class
12
     *
13
     * @return string
14
     * @throws \ReflectionException
15
     */
16
    public static function getName(string $class): string
17
    {
18
        $ref = new \ReflectionClass($class);
19
20
        return (string) $ref->getShortName();
21
    }
22
23
    /**
24
     * @param $object
25
     *
26
     * @return string
27
     * @throws \ReflectionException
28
     */
29
    public static function getObjectName($object): string
30
    {
31
        $ref = new \ReflectionClass($object);
32
33
        return (string) $ref->getShortName();
34
    }
35
36
    /**
37
     * @param string $str
38
     * @param string $postfix
39
     *
40
     * @return mixed
41
     */
42
    public static function cutEntity(string $str, string $postfix)
43
    {
44
        return substr($str, 0, strpos($str, $postfix));
45
    }
46
47
    /**
48
     * @param string $entity
49
     * @return string
50
     */
51
    public static function getModelEntity(string $entity): string
52
    {
53
        return DirsInterface::MODULES_DIR . PhpInterface::BACKSLASH . ConfigHelper::getModuleName() .
54
        PhpInterface::BACKSLASH . DirsInterface::ENTITIES_DIR .
55
        PhpInterface::BACKSLASH . $entity;
56
    }
57
58
    /**
59
     * Gets class name ucwording 1st and replacing -_ in composite names
60
     * @param string $objectName
61
     *
62
     * @return string
63
     */
64
    public static function getClassName(string $objectName): string
65
    {
66
        return str_replace(
67
            [
68
                PhpInterface::DASH,
69
                PhpInterface::UNDERSCORE
70
            ], '', ucwords(
71
                $objectName, PhpInterface::DASH . PhpInterface::UNDERSCORE
72
            )
73
        );
74
    }
75
}