Passed
Push — master ( 182ddb...cf05b0 )
by Gaetano
07:26
created

DeprecationLogger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A logDeprecation() 0 7 2
A logDeprecationUnlessCalledBy() 0 14 3
1
<?php
2
3
namespace PhpXmlRpc\Traits;
4
5
use PhpXmlRpc\PhpXmlRpc;
6
7
trait DeprecationLogger
8
{
9
    use LoggerAware;
10
11
    protected function logDeprecation($message)
12
    {
13
        if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
14
            return;
15
        }
16
17
        $this->getLogger()->warning('XML-RPC Deprecated: ' . $message);
18
    }
19
20
    /**
21
     * @param string $callee
22
     * @param string $expectedCaller atm only the method name is supported
23
     * @return void
24
     */
25
    protected function logDeprecationUnlessCalledBy($expectedCaller)
26
    {
27
        if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
28
            return;
29
        }
30
31
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
32
        /// @todo we should check as well $trace[2]['class'], and make sure that it is a descendent of the class passed in in $expectedCaller
33
        if ($trace[2]['function'] === $expectedCaller) {
34
            return;
35
        }
36
37
        $this->getLogger()->warning('XML-RPC Deprecated: ' . $trace[1]['class'] . '::' . $trace[1]['function'] .
38
            ' is only supposed to be called by ' . $expectedCaller);
39
    }
40
}
41