Passed
Push — main ( d57b89...a3c66a )
by Andrey
14:07 queued 12:05
created

Deprecation::getDeprecatedNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Helldar\Support\Concerns;
4
5
/**
6
 * If you use this trait, you need to install the dependency:.
7
 *
8
 * composer require symfony/deprecation-contracts
9
 */
10
trait Deprecation
11
{
12
    protected static $next_version = '4.0';
13
14 20
    protected static function deprecatedClass(string $new_class): void
15
    {
16 20
        $old_class = static::getDeprecatedNamespace();
17
18 20
        static::deprecated(
19 20
            'The %s class has been deprecated and will be removed in version %s, use %s instead.',
20
            $old_class,
21 20
            static::$next_version,
22
            $new_class
23
        );
24 20
    }
25
26
    protected static function deprecatedMethod(string $old_method, string $new_class, string $new_method = null): void
27
    {
28
        $namespace = static::getDeprecatedNamespace();
29
30
        static::deprecated(
31
            'The %s::%s() method has been deprecated and will be removed in version %s, use  %s::%s() instead.',
32
            $namespace,
33
            $old_method,
34
            static::$next_version,
35
            $new_class,
36
            $new_method ?: $old_method
37
        );
38
    }
39
40 20
    protected static function getDeprecatedNamespace(): string
41
    {
42 20
        return static::class;
43
    }
44
45 20
    protected static function deprecated(string $message, ...$args): void
46
    {
47 20
        trigger_deprecation('andrey-helldar/support', static::$next_version, $message, ...$args);
48 20
    }
49
}
50