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

Deprecation   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getDeprecatedNamespace() 0 3 1
A deprecatedRenameMethod() 0 3 1
A deprecatedClass() 0 3 1
A deprecatedNamespace() 0 6 1
A getDeprecatedBasename() 0 5 1
A deprecatedMethodParameters() 0 3 1
A deprecated() 0 3 1
A getActualNamespace() 0 8 2
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