Passed
Push — master ( 69c271...cb615c )
by Valentin
07:24
created

utils.php ➔ getStubContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework. Cycle ProxyFactory
5
 *
6
 * @license MIT
7
 * @author  Valentin V (Vvval)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\ORM\Promise;
13
14
/**
15
 * @return string
16
 */
17
function getStubContent(): string
18
{
19
    $lines = [
20
        '<?php',
21
        'declare(strict_types=1);',
22
        'namespace StubNamespace;',
23
        'class ProxyStub {}'
24
    ];
25
26
    return join("\n", $lines);
27
}
28
29
/**
30
 * Remove trailing digits in the given name.
31
 *
32
 * @param string $name
33
 * @param int    $number
34
 * @return string
35
 */
36
function trimTrailingDigits(string $name, int $number): string
37
{
38
    $pos = mb_strripos($name, (string)$number);
39
    if ($pos === false) {
40
        return $name;
41
    }
42
43
    return mb_substr($name, 0, $pos);
44
}
45
46
/**
47
 * Remove any kinds of php open tags.
48
 *
49
 * @param string $code
50
 * @return string
51
 */
52
function trimPHPOpenTag(string $code): string
53
{
54
    if (mb_strpos($code, '<?php') === 0) {
55
        return mb_substr($code, 5);
56
    }
57
58
    if (mb_strpos($code, '<?') === 0) {
59
        return mb_substr($code, 2);
60
    }
61
62
    return $code;
63
}
64
65
66
/**
67
 * Create short name (without namespaces).
68
 *
69
 * @param string $name
70
 * @return string
71
 */
72
function shortName(string $name): string
73
{
74
    $pos = mb_strrpos($name, '\\');
75
    if ($pos === false) {
76
        return $name;
77
    }
78
79
    return mb_substr($name, $pos + 1);
80
}
81