Passed
Push — master ( da62c2...b88588 )
by Paul
03:15
created
plugin/Log.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	 * @param array $context
119 119
 	 * @return static
120 120
 	 */
121
-	public function log( $level, $message, array $context = [] )
121
+	public function log( $level, $message, array $context = [ ] )
122 122
 	{
123
-		$constants = (new ReflectionClass( __NAMESPACE__.'\Log' ))->getConstants();
124
-		$constants = (array)apply_filters( Application::ID.'/log-levels', $constants );
125
-		if( in_array( $level, $constants, true )) {
126
-			$date = get_date_from_gmt( gmdate('Y-m-d H:i:s') );
123
+		$constants = ( new ReflectionClass( __NAMESPACE__ . '\Log' ) )->getConstants();
124
+		$constants = (array) apply_filters( Application::ID . '/log-levels', $constants );
125
+		if( in_array( $level, $constants, true ) ) {
126
+			$date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) );
127 127
 			$level = strtoupper( $level );
128 128
 			$message = $this->interpolate( $message, $context );
129 129
 			$entry = "[$date] $level: $message" . PHP_EOL;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @param array $context
147 147
 	 * @return static
148 148
 	 */
149
-	public function notice( $message, array $context = [] )
149
+	public function notice( $message, array $context = [ ] )
150 150
 	{
151 151
 		return $this->log( static::NOTICE, $message, $context );
152 152
 	}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param array $context
160 160
 	 * @return static
161 161
 	 */
162
-	public function warning( $message, array $context = [] )
162
+	public function warning( $message, array $context = [ ] )
163 163
 	{
164 164
 		return $this->log( static::WARNING, $message, $context );
165 165
 	}
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 * @param array $context
170 170
 	 * @return array|string
171 171
 	 */
172
-	protected function interpolate( $message, array $context = [] )
172
+	protected function interpolate( $message, array $context = [ ] )
173 173
 	{
174
-		if( $this->isObjectOrArray( $value )) {
174
+		if( $this->isObjectOrArray( $value ) ) {
175 175
 			return print_r( $message, true );
176 176
 		}
177
-		$replace = [];
177
+		$replace = [ ];
178 178
 		foreach( $context as $key => $value ) {
179
-			$replace['{'.$key.'}'] = $this->normalizeValue( $value );
179
+			$replace[ '{' . $key . '}' ] = $this->normalizeValue( $value );
180 180
 		}
181 181
 		return strtr( $message, $replace );
182 182
 	}
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 		if( $value instanceof DateTime ) {
200 200
 			$value = $value->format( 'Y-m-d H:i:s' );
201 201
 		}
202
-		else if( $this->isObjectOrArray( $value )) {
202
+		else if( $this->isObjectOrArray( $value ) ) {
203 203
 			$value = json_encode( $value );
204 204
 		}
205
-		else if( is_resource( $value )) {
206
-			$value = (string)$value;
205
+		else if( is_resource( $value ) ) {
206
+			$value = (string) $value;
207 207
 		}
208 208
 		return $value;
209 209
 	}
Please login to merge, or discard this patch.
plugin/Application.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,11 +62,11 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function initLogger()
64 64
 	{
65
-		if( func_get_arg(0) != static::ID )return;
66
-		$type = func_get_arg(2)
67
-			? func_get_arg(2)
65
+		if( func_get_arg( 0 ) != static::ID )return;
66
+		$type = func_get_arg( 2 )
67
+			? func_get_arg( 2 )
68 68
 			: 'debug';
69
-		$this->log->log( $type, func_get_arg(1) );
69
+		$this->log->log( $type, func_get_arg( 1 ) );
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 	 */
75 75
 	public function clearLog()
76 76
 	{
77
-		$request = filter_input( INPUT_POST, static::ID, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY );
78
-		if( empty( $request['action'] ) || $request['action'] != 'clear-log' )return;
79
-		check_admin_referer( $request['action'] );
77
+		$request = filter_input( INPUT_POST, static::ID, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
78
+		if( empty( $request[ 'action' ] ) || $request[ 'action' ] != 'clear-log' )return;
79
+		check_admin_referer( $request[ 'action' ] );
80 80
 		$this->log->clear();
81
-		add_action( 'admin_notices', [$this, 'renderNotice'] );
81
+		add_action( 'admin_notices', [ $this, 'renderNotice' ] );
82 82
 	}
83 83
 
84 84
 	/**
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	public function path( $file = '' )
89 89
 	{
90
-		return plugin_dir_path( $this->file ).ltrim( trim( $file ), '/' );
90
+		return plugin_dir_path( $this->file ) . ltrim( trim( $file ), '/' );
91 91
 	}
92 92
 
93 93
 	/**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	public function registerLanguages()
97 97
 	{
98 98
 		load_plugin_textdomain( static::ID, '',
99
-			trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages )
99
+			trailingslashit( plugin_basename( $this->path() ) . '/' . $this->languages )
100 100
 		);
101 101
 	}
102 102
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			__( 'Logger', 'logger' ),
113 113
 			'manage_options',
114 114
 			static::ID,
115
-			[$this, 'renderSettingsPage']
115
+			[ $this, 'renderSettingsPage' ]
116 116
 		);
117 117
 	}
118 118
 
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 	 * @param string $view
130 130
 	 * @return void|null
131 131
 	 */
132
-	public function render( $view, array $data = [] )
132
+	public function render( $view, array $data = [ ] )
133 133
 	{
134
-		if( !file_exists( $file = $this->path( 'views/'.$view.'.php' )))return;
134
+		if( !file_exists( $file = $this->path( 'views/' . $view . '.php' ) ) )return;
135 135
 		extract( $data );
136 136
 		include $file;
137 137
 	}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		$this->render( 'notice', [
145 145
 			'notice' => __( 'The log was cleared.', 'logger' ),
146 146
 			'status' => 'success',
147
-		]);
147
+		] );
148 148
 	}
149 149
 
150 150
 	/**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			'log' => $this->log,
159 159
 			'settings' => $this->getSettings(),
160 160
 			'title' => __( 'Logger', 'logger' ),
161
-		]);
161
+		] );
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function getSettings()
168 168
 	{
169
-		$settings = get_option( static::ID, [] );
170
-		if( empty( $settings )) {
169
+		$settings = get_option( static::ID, [ ] );
170
+		if( empty( $settings ) ) {
171 171
 			update_option( static::ID, $settings = [
172 172
 				'enabled' => 0,
173
-			]);
173
+			] );
174 174
 		}
175
-		return (object)$settings;
175
+		return (object) $settings;
176 176
 	}
177 177
 }
Please login to merge, or discard this patch.