Passed
Push — main ( 35cea8...263c2f )
by Andrey
21:51 queued 20:06
created

Deprecation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
c 3
b 0
f 0
dl 0
loc 38
ccs 0
cts 17
cp 0
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A deprecatedMethod() 0 11 2
A deprecated() 0 3 1
A getDeprecatedNamespace() 0 3 2
A deprecatedClass() 0 9 1
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 = '5.0';
13
14
    protected static function deprecatedClass(string $new_class, string $old_class = null): void
15
    {
16
        $old_class = static::getDeprecatedNamespace($old_class);
17
18
        static::deprecated(
19
            'The %s class has been deprecated and will be removed in version %s, use %s instead.',
20
            $old_class,
21
            static::$next_version,
22
            $new_class
23
        );
24
    }
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
    protected static function getDeprecatedNamespace(string $old_namespace = null): string
41
    {
42
        return $old_namespace ?: static::class;
43
    }
44
45
    protected static function deprecated(string $message, ...$args): void
46
    {
47
        trigger_deprecation('andrey-helldar/support', static::$next_version, $message, ...$args);
0 ignored issues
show
Bug introduced by
The function trigger_deprecation was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        /** @scrutinizer ignore-call */ 
48
        trigger_deprecation('andrey-helldar/support', static::$next_version, $message, ...$args);
Loading history...
48
    }
49
}
50