Skip to content

Commit e6f9f64

Browse files
Better adherence to WordPress coding standards.
1 parent 0840edc commit e6f9f64

31 files changed

Lines changed: 255 additions & 238 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/yaml": "~2.8",
2626
"squizlabs/php_codesniffer": "~2.2",
2727
"tinify/tinify": "dev-create-key",
28-
"wp-coding-standards/wpcs": "*"
28+
"wp-coding-standards/wpcs": "dev-master"
2929
},
3030
"scripts": {
3131
"post-install-cmd": "bin/post-install",

composer.lock

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/class-tiny-compress-client.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Tiny_Compress_Client extends Tiny_Compress {
3333
private $last_message = '';
3434
private $proxy;
3535

36-
protected function __construct($api_key, $after_compress_callback) {
36+
protected function __construct( $api_key, $after_compress_callback ) {
3737
parent::__construct( $after_compress_callback );
3838

3939
$this->proxy = new WP_HTTP_Proxy();
@@ -55,7 +55,7 @@ public function get_key() {
5555
}
5656

5757
public function limit_reached() {
58-
return $this->last_error_code == 429;
58+
return 429 == $this->last_error_code;
5959
}
6060

6161
protected function validate() {
@@ -66,10 +66,10 @@ protected function validate() {
6666
\Tinify\Tinify::getClient()->request( 'post', '/shrink' );
6767
return true;
6868

69-
} catch(\Tinify\Exception $err) {
69+
} catch (\Tinify\Exception $err) {
7070
$this->last_error_code = $err->status;
7171

72-
if ( $err->status == 429 || $err->status == 400 ) {
72+
if ( 429 == $err->status || 400 == $err->status ) {
7373
return true;
7474
}
7575

@@ -81,7 +81,7 @@ protected function validate() {
8181
}
8282
}
8383

84-
protected function compress($input, $resize_opts, $preserve_opts) {
84+
protected function compress( $input, $resize_opts, $preserve_opts ) {
8585
try {
8686
$this->last_error_code = 0;
8787
$this->set_request_options( \Tinify\Tinify::getClient() );
@@ -109,13 +109,13 @@ protected function compress($input, $resize_opts, $preserve_opts) {
109109
'width' => $result->width(),
110110
'height' => $result->height(),
111111
'ratio' => round( $result->size() / strlen( $input ), 4 ),
112-
)
112+
),
113113
);
114114

115115
$buffer = $result->toBuffer();
116116
return array( $buffer, $meta );
117117

118-
} catch(\Tinify\Exception $err) {
118+
} catch (\Tinify\Exception $err) {
119119
$this->last_error_code = $err->status;
120120

121121
throw new Tiny_Exception(
@@ -126,15 +126,15 @@ protected function compress($input, $resize_opts, $preserve_opts) {
126126
}
127127
}
128128

129-
public function create_key($email, $options) {
129+
public function create_key( $email, $options ) {
130130
try {
131131
$this->last_error_code = 0;
132132
$this->set_request_options(
133133
\Tinify\Tinify::getClient( \Tinify\Tinify::ANONYMOUS )
134134
);
135135

136136
\Tinify\createKey( $email, $options );
137-
} catch(\Tinify\Exception $err) {
137+
} catch (\Tinify\Exception $err) {
138138
$this->last_error_code = $err->status;
139139

140140
throw new Tiny_Exception(
@@ -145,7 +145,7 @@ public function create_key($email, $options) {
145145
}
146146
}
147147

148-
private function set_request_options($client) {
148+
private function set_request_options( $client ) {
149149
/* The client does not let us override cURL properties yet, so we have
150150
to use a reflection property. */
151151
$property = new ReflectionProperty( $client, 'options' );

src/class-tiny-compress-fopen.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected static function identifier() {
2727
parent::identifier() . ' fopen';
2828
}
2929

30-
protected function __construct($api_key, $after_compress_callback) {
30+
protected function __construct( $api_key, $after_compress_callback ) {
3131
parent::__construct( $after_compress_callback );
3232

3333
$this->api_key = $api_key;
@@ -46,14 +46,14 @@ public function get_key() {
4646
}
4747

4848
public function limit_reached() {
49-
return $this->last_error_code == 429;
49+
return 429 == $this->last_error_code;
5050
}
5151

5252
protected function validate() {
5353
$params = $this->request_options( 'POST' );
5454
list($details, $headers, $status_code) = $this->request( $params );
5555

56-
if ( $status_code == 429 || $status_code == 400 ) {
56+
if ( 429 == $status_code || 400 == $status_code ) {
5757
return true;
5858
} else if ( is_array( $details ) && isset( $details['error'] ) ) {
5959
throw new Tiny_Exception(
@@ -70,7 +70,7 @@ protected function validate() {
7070
}
7171
}
7272

73-
protected function compress($input, $resize_opts, $preserve_opts) {
73+
protected function compress( $input, $resize_opts, $preserve_opts ) {
7474
$params = $this->request_options( 'POST', $input );
7575
list($details, $headers, $status_code) = $this->request( $params );
7676

@@ -87,7 +87,7 @@ protected function compress($input, $resize_opts, $preserve_opts) {
8787
'Tinify\Exception',
8888
$status_code
8989
);
90-
} else if ( $output_url === null ) {
90+
} else if ( null === $output_url ) {
9191
throw new Tiny_Exception(
9292
'Could not find output location',
9393
'Tinify\Exception'
@@ -129,13 +129,13 @@ protected function compress($input, $resize_opts, $preserve_opts) {
129129
'width' => intval( $headers['image-width'] ),
130130
'height' => intval( $headers['image-height'] ),
131131
'ratio' => round( strlen( $output ) / strlen( $input ), 4 ),
132-
)
132+
),
133133
);
134134

135135
return array( $output, $meta );
136136
}
137137

138-
private function request($params, $url = Tiny_Config::URL) {
138+
private function request( $params, $url = Tiny_Config::URL ) {
139139
$context = stream_context_create( $params );
140140
$request = fopen( $url, 'rb', false, $context );
141141

@@ -172,7 +172,7 @@ private function request($params, $url = Tiny_Config::URL) {
172172
return array( $response, $headers, $status_code );
173173
}
174174

175-
private function parse_status_code($headers) {
175+
private function parse_status_code( $headers ) {
176176
if ( $headers && count( $headers ) > 0 ) {
177177
$http_code_values = explode( ' ', $headers[0] );
178178
if ( count( $http_code_values ) > 1 ) {
@@ -182,7 +182,7 @@ private function parse_status_code($headers) {
182182
return null;
183183
}
184184

185-
private function parse_headers($headers) {
185+
private function parse_headers( $headers ) {
186186
$res = array();
187187
foreach ( $headers as $header ) {
188188
$split = explode( ':', $header, 2 );
@@ -193,7 +193,7 @@ private function parse_headers($headers) {
193193
return $res;
194194
}
195195

196-
private function request_options($method, $body = null) {
196+
private function request_options( $method, $body = null ) {
197197
return array(
198198
'http' => array(
199199
'method' => $method,
@@ -210,11 +210,11 @@ private function request_options($method, $body = null) {
210210
'ssl' => array(
211211
'cafile' => $this->get_ca_file(),
212212
'verify_peer' => true,
213-
)
213+
),
214214
);
215215
}
216216

217-
private function output_request_options($resize_opts, $preserve_opts) {
217+
private function output_request_options( $resize_opts, $preserve_opts ) {
218218
$body = array();
219219

220220
if ( $preserve_opts ) {
@@ -237,9 +237,9 @@ private static function get_ca_file() {
237237
return dirname( __FILE__ ) . '/data/cacert.pem';
238238
}
239239

240-
private static function decode($text) {
240+
private static function decode( $text ) {
241241
$result = json_decode( $text, true );
242-
if ( $result === null ) {
242+
if ( null === $result ) {
243243
$message = sprintf(
244244
'JSON: %s [%d]',
245245
(PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Unknown error'),

0 commit comments

Comments
 (0)