Classes   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 8 1
A getName() 0 5 1
A cutEntity() 0 3 1
A getObjectName() 0 5 1
A getModelEntity() 0 5 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
}