Passed
Pull Request — main (#57)
by Andrey
11:10 queued 10s
created

Deprecation::deprecatedRenameMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helldar\Support\Traits;
4
5
trait Deprecation
6
{
7
    protected static function deprecatedNamespace(): void
8
    {
9
        static::deprecated(
10
            'Namespace "%s" is deprecated, use "%s" instead.',
11
            static::getDeprecatedNamespace(),
12
            static::getActualNamespace()
13
        );
14
    }
15
16
    protected static function deprecatedClass(): void
17
    {
18
        static::deprecated('The %s class has been deprecated and will be removed.', static::getDeprecatedNamespace());
19
    }
20
21
    protected static function deprecatedRenameMethod(string $old, string $new): void
22
    {
23
        static::deprecated('Using "%s()" method is deprecated, use "%s()" instead.', $old, $new);
24
    }
25
26
    protected static function deprecatedMethodParameters(string $method): void
27
    {
28
        static::deprecated('The parameters or typisation of the "%s" method will be changed.', $method);
29
    }
30
31
    protected static function getDeprecatedNamespace(): string
32
    {
33
        return static::class;
34
    }
35
36
    protected static function getActualNamespace(): string
37
    {
38
        $classname = static::getDeprecatedNamespace();
39
        $basename  = static::getDeprecatedBasename();
40
41
        return in_array($basename, ['Directory', 'File'])
42
            ? str_replace('\\' . $basename, '\\Helpers\\Filesystem\\' . $basename, $classname)
43
            : str_replace('\\' . $basename, '\\Helpers\\' . $basename, $classname);
44
    }
45
46
    protected static function getDeprecatedBasename(): string
47
    {
48
        $class = static::getDeprecatedNamespace();
49
50
        return basename(str_replace('\\', '/', $class));
51
    }
52
53
    protected static function deprecated(string $message, ...$args): void
54
    {
55
        trigger_deprecation('andrey-helldar/support', '2.0', $message, ...$args);
56
    }
57
}
58