Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

engine/classes/Elgg/DeprecationService.php (1 issue)

methods always have a scope defined.

Best Practice Minor
1
<?php
2
namespace Elgg;
3
4
/**
5
 * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
6
 *
7
 * Use the elgg_* versions instead.
8
 *
9
 * @access private
10
 *
11
 * @package    Elgg.Core
12
 * @subpackage Deprecation
13
 * @since      1.11.0
14
 */
15
class DeprecationService {
16
17
	/**
18
	 * @var Logger
19
	 */
20
	protected $logger;
21
22
	/**
23
	 * Constructor
24
	 *
25
	 * @param Logger $logger Logger service
26
	 */
27 150
	public function __construct(Logger $logger) {
28 150
		$this->logger = $logger;
29 150
	}
30
31
	/**
32
	 * Sends a notice about deprecated use of a function, view, etc.
33
	 *
34
	 * @param string $msg             Message to log
35
	 * @param string $dep_version     Human-readable *release* version: 1.7, 1.8, ...
36
	 * @param int    $backtrace_level How many levels back to display the backtrace.
37
	 *                                Useful if calling from functions that are called
38
	 *                                from other places (like elgg_view()). Set to -1
39
	 *                                for a full backtrace.
40
	 * @return bool
41
	 */
42 656
	function sendNotice($msg, $dep_version, $backtrace_level = 1) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
43
44 656
		$msg = "Deprecated in $dep_version: $msg Called from ";
45
46
		// Get a file and line number for the log. Skip over the function that
47
		// sent this notice and see who called the deprecated function itself.
48 656
		$stack = [];
49 656
		$backtrace = debug_backtrace();
50
		// never show this call.
51 656
		array_shift($backtrace);
52 656
		$i = count($backtrace);
53
54 656
		foreach ($backtrace as $trace) {
55 656
			if (empty($trace['file'])) {
56
				// file/line not set for Closures
57
				$stack[] = "[#$i] unknown";
58
			} else {
59 656
				$stack[] = "[#$i] {$trace['file']}:{$trace['line']}";
60
			}
61
62 656
			$i--;
63
64 656
			if ($backtrace_level > 0) {
65 656
				if ($backtrace_level <= 1) {
66 656
					break;
67
				}
68 656
				$backtrace_level--;
69
			}
70
		}
71
72 656
		$msg .= implode("<br /> -> ", $stack);
73
74 656
		$this->logger->warn($msg);
75
76 656
		return true;
77
	}
78
}
79