@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param array $context |
41 | 41 | * @return static |
42 | 42 | */ |
43 | - public function alert( $message, array $context = [] ) |
|
43 | + public function alert( $message, array $context = [ ] ) |
|
44 | 44 | { |
45 | 45 | return $this->log( static::ALERT, $message, $context ); |
46 | 46 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param array $context |
62 | 62 | * @return static |
63 | 63 | */ |
64 | - public function critical( $message, array $context = [] ) |
|
64 | + public function critical( $message, array $context = [ ] ) |
|
65 | 65 | { |
66 | 66 | return $this->log( static::CRITICAL, $message, $context ); |
67 | 67 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @param array $context |
73 | 73 | * @return static |
74 | 74 | */ |
75 | - public function debug( $message, array $context = [] ) |
|
75 | + public function debug( $message, array $context = [ ] ) |
|
76 | 76 | { |
77 | 77 | return $this->log( static::DEBUG, $message, $context ); |
78 | 78 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param array $context |
84 | 84 | * @return static |
85 | 85 | */ |
86 | - public function emergency( $message, array $context = [] ) |
|
86 | + public function emergency( $message, array $context = [ ] ) |
|
87 | 87 | { |
88 | 88 | return $this->log( static::EMERGENCY, $message, $context ); |
89 | 89 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param array $context |
96 | 96 | * @return static |
97 | 97 | */ |
98 | - public function error( $message, array $context = [] ) |
|
98 | + public function error( $message, array $context = [ ] ) |
|
99 | 99 | { |
100 | 100 | return $this->log( static::ERROR, $message, $context ); |
101 | 101 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param array $context |
108 | 108 | * @return static |
109 | 109 | */ |
110 | - public function info( $message, array $context = [] ) |
|
110 | + public function info( $message, array $context = [ ] ) |
|
111 | 111 | { |
112 | 112 | return $this->log( static::INFO, $message, $context ); |
113 | 113 | } |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | * @param string $message |
118 | 118 | * @return static |
119 | 119 | */ |
120 | - public function log( $level, $message, array $context = [] ) |
|
120 | + public function log( $level, $message, array $context = [ ] ) |
|
121 | 121 | { |
122 | - $constants = (new ReflectionClass( __NAMESPACE__.'\Log' ))->getConstants(); |
|
123 | - $constants = (array)apply_filters( Application::ID.'/log-levels', $constants ); |
|
124 | - if( in_array( $level, $constants, true )) { |
|
125 | - $date = get_date_from_gmt( gmdate('Y-m-d H:i:s') ); |
|
122 | + $constants = ( new ReflectionClass( __NAMESPACE__ . '\Log' ) )->getConstants(); |
|
123 | + $constants = (array) apply_filters( Application::ID . '/log-levels', $constants ); |
|
124 | + if( in_array( $level, $constants, true ) ) { |
|
125 | + $date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) ); |
|
126 | 126 | $level = strtoupper( $level ); |
127 | 127 | $message = $this->interpolate( $message, $context ); |
128 | 128 | $entry = "[$date] $level: $message" . PHP_EOL; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param array $context |
146 | 146 | * @return static |
147 | 147 | */ |
148 | - public function notice( $message, array $context = [] ) |
|
148 | + public function notice( $message, array $context = [ ] ) |
|
149 | 149 | { |
150 | 150 | return $this->log( static::NOTICE, $message, $context ); |
151 | 151 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param array $context |
159 | 159 | * @return static |
160 | 160 | */ |
161 | - public function warning( $message, array $context = [] ) |
|
161 | + public function warning( $message, array $context = [ ] ) |
|
162 | 162 | { |
163 | 163 | return $this->log( static::WARNING, $message, $context ); |
164 | 164 | } |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | * @param array $context |
169 | 169 | * @return array|string |
170 | 170 | */ |
171 | - protected function interpolate( $message, array $context = [] ) |
|
171 | + protected function interpolate( $message, array $context = [ ] ) |
|
172 | 172 | { |
173 | - if( $this->isObjectOrArray( $message )) { |
|
173 | + if( $this->isObjectOrArray( $message ) ) { |
|
174 | 174 | return print_r( $message, true ); |
175 | 175 | } |
176 | - $replace = []; |
|
176 | + $replace = [ ]; |
|
177 | 177 | foreach( $context as $key => $value ) { |
178 | - $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
178 | + $replace[ '{' . $key . '}' ] = $this->normalizeValue( $value ); |
|
179 | 179 | } |
180 | 180 | return strtr( $message, $replace ); |
181 | 181 | } |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | if( $value instanceof DateTime ) { |
199 | 199 | $value = $value->format( 'Y-m-d H:i:s' ); |
200 | 200 | } |
201 | - else if( $this->isObjectOrArray( $value )) { |
|
201 | + else if( $this->isObjectOrArray( $value ) ) { |
|
202 | 202 | $value = json_encode( $value ); |
203 | 203 | } |
204 | - else if( is_resource( $value )) { |
|
205 | - $value = (string)$value; |
|
204 | + else if( is_resource( $value ) ) { |
|
205 | + $value = (string) $value; |
|
206 | 206 | } |
207 | 207 | return $value; |
208 | 208 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public static function load() |
23 | 23 | { |
24 | - if( empty( static::$instance )) { |
|
24 | + if( empty( static::$instance ) ) { |
|
25 | 25 | static::$instance = new static; |
26 | 26 | } |
27 | 27 | return static::$instance; |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct() |
34 | 34 | { |
35 | - $this->file = trailingslashit( dirname( __DIR__ )).static::ID.'.php'; |
|
36 | - $this->log = new Log( $this->path( 'development.log' )); |
|
35 | + $this->file = trailingslashit( dirname( __DIR__ ) ) . static::ID . '.php'; |
|
36 | + $this->log = new Log( $this->path( 'development.log' ) ); |
|
37 | 37 | $plugin = get_file_data( $this->file, [ |
38 | 38 | 'languages' => 'Domain Path', |
39 | 39 | 'name' => 'Plugin Name', |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function init() |
51 | 51 | { |
52 | - add_action( 'admin_init', [$this, 'clearLog'] ); |
|
53 | - add_action( 'plugins_loaded', [$this, 'registerLanguages'] ); |
|
54 | - add_action( 'admin_menu', [$this, 'registerMenu'] ); |
|
55 | - add_action( 'admin_menu', [$this, 'registerSettings'] ); |
|
56 | - add_filter( 'all', [$this, 'initLogger'] ); |
|
52 | + add_action( 'admin_init', [ $this, 'clearLog' ] ); |
|
53 | + add_action( 'plugins_loaded', [ $this, 'registerLanguages' ] ); |
|
54 | + add_action( 'admin_menu', [ $this, 'registerMenu' ] ); |
|
55 | + add_action( 'admin_menu', [ $this, 'registerSettings' ] ); |
|
56 | + add_filter( 'all', [ $this, 'initLogger' ] ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function initLogger() |
64 | 64 | { |
65 | - $args = func_get_args() + ['', null, 'debug']; |
|
66 | - if( $args[0] !== static::ID || is_null( $args[1] ))return; |
|
67 | - return $this->log->log( $args[2], $args[1] ); |
|
65 | + $args = func_get_args() + [ '', null, 'debug' ]; |
|
66 | + if( $args[ 0 ] !== static::ID || is_null( $args[ 1 ] ) )return; |
|
67 | + return $this->log->log( $args[ 2 ], $args[ 1 ] ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function clearLog() |
74 | 74 | { |
75 | - $request = filter_input( INPUT_POST, static::ID, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY ); |
|
76 | - if( empty( $request['action'] ) || $request['action'] != 'clear-log' )return; |
|
77 | - check_admin_referer( $request['action'] ); |
|
75 | + $request = filter_input( INPUT_POST, static::ID, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
76 | + if( empty( $request[ 'action' ] ) || $request[ 'action' ] != 'clear-log' )return; |
|
77 | + check_admin_referer( $request[ 'action' ] ); |
|
78 | 78 | $this->log->clear(); |
79 | - add_action( 'admin_notices', [$this, 'renderNotice'] ); |
|
79 | + add_action( 'admin_notices', [ $this, 'renderNotice' ] ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function path( $file = '' ) |
87 | 87 | { |
88 | - $basepath = trailingslashit( realpath( plugin_dir_path( $this->file ))); |
|
89 | - return $basepath.ltrim( trim( $file ), '/' ); |
|
88 | + $basepath = trailingslashit( realpath( plugin_dir_path( $this->file ) ) ); |
|
89 | + return $basepath . ltrim( trim( $file ), '/' ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function registerLanguages() |
96 | 96 | { |
97 | 97 | load_plugin_textdomain( static::ID, '', |
98 | - trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
98 | + trailingslashit( plugin_basename( $this->path() ) . '/' . $this->languages ) |
|
99 | 99 | ); |
100 | 100 | } |
101 | 101 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | __( 'Logger', 'logger' ), |
112 | 112 | 'manage_options', |
113 | 113 | static::ID, |
114 | - [$this, 'renderSettingsPage'] |
|
114 | + [ $this, 'renderSettingsPage' ] |
|
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * @param string $view |
129 | 129 | * @return void|null |
130 | 130 | */ |
131 | - public function render( $view, array $data = [] ) |
|
131 | + public function render( $view, array $data = [ ] ) |
|
132 | 132 | { |
133 | - if( !file_exists( $file = $this->path( 'views/'.$view.'.php' )))return; |
|
133 | + if( !file_exists( $file = $this->path( 'views/' . $view . '.php' ) ) )return; |
|
134 | 134 | extract( $data ); |
135 | 135 | include $file; |
136 | 136 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $this->render( 'notice', [ |
144 | 144 | 'notice' => __( 'The log was cleared.', 'logger' ), |
145 | 145 | 'status' => 'success', |
146 | - ]); |
|
146 | + ] ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'log' => $this->log, |
158 | 158 | 'settings' => $this->getSettings(), |
159 | 159 | 'title' => __( 'Logger', 'logger' ), |
160 | - ]); |
|
160 | + ] ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function getSettings() |
167 | 167 | { |
168 | - $settings = get_option( static::ID, [] ); |
|
169 | - if( empty( $settings )) { |
|
168 | + $settings = get_option( static::ID, [ ] ); |
|
169 | + if( empty( $settings ) ) { |
|
170 | 170 | update_option( static::ID, $settings = [ |
171 | 171 | 'enabled' => 0, |
172 | - ]); |
|
172 | + ] ); |
|
173 | 173 | } |
174 | - return (object)$settings; |
|
174 | + return (object) $settings; |
|
175 | 175 | } |
176 | 176 | } |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | 'name' => 'Plugin Name', |
40 | 40 | 'version' => 'Version', |
41 | 41 | ], 'plugin' ); |
42 | - array_walk( $plugin, function( $value, $key ) { |
|
42 | + array_walk( $plugin, function( $value, $key ) |
|
43 | + { |
|
43 | 44 | $this->$key = $value; |
44 | 45 | }); |
45 | 46 | } |
@@ -63,7 +64,9 @@ discard block |
||
63 | 64 | public function initLogger() |
64 | 65 | { |
65 | 66 | $args = func_get_args() + ['', null, 'debug']; |
66 | - if( $args[0] !== static::ID || is_null( $args[1] ))return; |
|
67 | + if( $args[0] !== static::ID || is_null( $args[1] )) { |
|
68 | + return; |
|
69 | + } |
|
67 | 70 | return $this->log->log( $args[2], $args[1] ); |
68 | 71 | } |
69 | 72 | |
@@ -73,7 +76,9 @@ discard block |
||
73 | 76 | public function clearLog() |
74 | 77 | { |
75 | 78 | $request = filter_input( INPUT_POST, static::ID, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY ); |
76 | - if( empty( $request['action'] ) || $request['action'] != 'clear-log' )return; |
|
79 | + if( empty( $request['action'] ) || $request['action'] != 'clear-log' ) { |
|
80 | + return; |
|
81 | + } |
|
77 | 82 | check_admin_referer( $request['action'] ); |
78 | 83 | $this->log->clear(); |
79 | 84 | add_action( 'admin_notices', [$this, 'renderNotice'] ); |
@@ -130,7 +135,9 @@ discard block |
||
130 | 135 | */ |
131 | 136 | public function render( $view, array $data = [] ) |
132 | 137 | { |
133 | - if( !file_exists( $file = $this->path( 'views/'.$view.'.php' )))return; |
|
138 | + if( !file_exists( $file = $this->path( 'views/'.$view.'.php' ))) { |
|
139 | + return; |
|
140 | + } |
|
134 | 141 | extract( $data ); |
135 | 142 | include $file; |
136 | 143 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | |
18 | 18 | defined( 'WPINC' ) || die; |
19 | 19 | |
20 | -if( !class_exists( 'GL_Plugin_Check' )) { |
|
21 | - require_once __DIR__.'/activate.php'; |
|
20 | +if( !class_exists( 'GL_Plugin_Check' ) ) { |
|
21 | + require_once __DIR__ . '/activate.php'; |
|
22 | 22 | } |
23 | -require_once __DIR__.'/autoload.php'; |
|
24 | -if( GL_Plugin_Check::shouldDeactivate( __FILE__ ))return; |
|
23 | +require_once __DIR__ . '/autoload.php'; |
|
24 | +if( GL_Plugin_Check::shouldDeactivate( __FILE__ ) )return; |
|
25 | 25 | GeminiLabs\Logger\Application::load()->init(); |
26 | 26 | |
27 | 27 | /** |
@@ -30,6 +30,6 @@ discard block |
||
30 | 30 | function gllog() { |
31 | 31 | $app = GeminiLabs\Logger\Application::load(); |
32 | 32 | return func_num_args() > 0 |
33 | - ? call_user_func_array( [$app, 'initLogger'], ['logger', func_get_arg(0)] ) |
|
33 | + ? call_user_func_array( [ $app, 'initLogger' ], [ 'logger', func_get_arg( 0 ) ] ) |
|
34 | 34 | : $app->log->logger(); |
35 | 35 | } |
@@ -21,13 +21,16 @@ |
||
21 | 21 | require_once __DIR__.'/activate.php'; |
22 | 22 | } |
23 | 23 | require_once __DIR__.'/autoload.php'; |
24 | -if( GL_Plugin_Check::shouldDeactivate( __FILE__ ))return; |
|
24 | +if( GL_Plugin_Check::shouldDeactivate( __FILE__ )) { |
|
25 | + return; |
|
26 | +} |
|
25 | 27 | GeminiLabs\Logger\Application::load()->init(); |
26 | 28 | |
27 | 29 | /** |
28 | 30 | * @return GeminiLabs\Logger\Log |
29 | 31 | */ |
30 | -function gllog() { |
|
32 | +function gllog() |
|
33 | +{ |
|
31 | 34 | $app = GeminiLabs\Logger\Application::load(); |
32 | 35 | return func_num_args() > 0 |
33 | 36 | ? call_user_func_array( [$app, 'initLogger'], ['logger', func_get_arg(0)] ) |