Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit baf0f72

Browse files
committed
Switched to phpcs
Had issues running CS sniffs under `--prefer-lowest`, so switched to phpcs. Which helped uncover a ton of CS issues, including underscore-prefixed properties and methods (most were updated, though the methods defined in the abstract protocol class were left due to the fact that they are an extension point).
1 parent cb280cd commit baf0f72

39 files changed

+975
-800
lines changed

.php_cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ install:
5757
script:
5858
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
5959
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
60-
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
60+
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi
6161

6262
after_script:
6363
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"zendframework/zend-config": "^2.6",
2424
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
2525
"zendframework/zend-crypt": "^2.6",
26-
"fabpot/php-cs-fixer": "1.7.*",
26+
"squizlabs/php_codesniffer": "^2.3.1",
2727
"phpunit/phpunit": "^4.8"
2828
},
2929
"suggest": {

phpcs.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Zend Framework coding standard">
3+
<description>Zend Framework coding standard</description>
4+
5+
<!-- display progress -->
6+
<arg value="p"/>
7+
<arg name="colors"/>
8+
9+
<!-- inherit rules from: -->
10+
<rule ref="PSR2"/>
11+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
12+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
13+
<properties>
14+
<property name="ignoreBlankLines" value="false"/>
15+
</properties>
16+
</rule>
17+
18+
<!-- Paths to check -->
19+
<file>src</file>
20+
<file>test</file>
21+
<exclude-pattern>test/_files/*</exclude-pattern>
22+
</ruleset>

src/Header/AbstractAddressList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public static function fromString($headerLine)
4444
list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
4545
if (strtolower($fieldName) !== static::$type) {
4646
throw new Exception\InvalidArgumentException(sprintf(
47-
'Invalid header line for "%s" string',
48-
__CLASS__
49-
));
47+
'Invalid header line for "%s" string',
48+
__CLASS__
49+
));
5050
}
5151

5252
// split value on ","

src/Header/Sender.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public static function fromString($headerLine)
4949
* 'name' and 'email' capture groups correspond respectively to 'display-name' and 'addr-spec' in the ABNF
5050
* @see https://tools.ietf.org/html/rfc5322#section-3.4
5151
*/
52-
$hasMatches = preg_match('/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', $value, $matches);
52+
$hasMatches = preg_match(
53+
'/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/',
54+
$value,
55+
$matches
56+
);
5357

5458
if ($hasMatches !== 1) {
5559
throw new Exception\InvalidArgumentException('Invalid header value for Sender string');

src/Protocol/AbstractProtocol.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use Zend\Validator;
1313

1414
/**
15-
* Provides low-level methods for concrete adapters to communicate with a remote mail server and track requests and responses.
15+
* Provides low-level methods for concrete adapters to communicate with a
16+
* remote mail server and track requests and responses.
1617
*
1718
* @todo Implement proxy settings
1819
*/
@@ -128,7 +129,8 @@ public function getMaximumLog()
128129
/**
129130
* Create a connection to the remote host
130131
*
131-
* Concrete adapters for this class will implement their own unique connect scripts, using the _connect() method to create the socket resource.
132+
* Concrete adapters for this class will implement their own unique connect
133+
* scripts, using the _connect() method to create the socket resource.
132134
*/
133135
abstract public function connect();
134136

@@ -171,20 +173,23 @@ public function resetLog()
171173
$this->log = [];
172174
}
173175

176+
// @codingStandardsIgnoreStart
174177
/**
175178
* Add the transaction log
176179
*
177180
* @param string $value new transaction
178181
*/
179182
protected function _addLog($value)
180183
{
184+
// @codingStandardsIgnoreEnd
181185
if ($this->maximumLog >= 0 && count($this->log) >= $this->maximumLog) {
182186
array_shift($this->log);
183187
}
184188

185189
$this->log[] = $value;
186190
}
187191

192+
// @codingStandardsIgnoreStart
188193
/**
189194
* Connect to the server using the supplied transport and target
190195
*
@@ -196,6 +201,7 @@ protected function _addLog($value)
196201
*/
197202
protected function _connect($remote)
198203
{
204+
// @codingStandardsIgnoreEnd
199205
$errorNum = 0;
200206
$errorStr = '';
201207

@@ -216,17 +222,20 @@ protected function _connect($remote)
216222
return $result;
217223
}
218224

225+
// @codingStandardsIgnoreStart
219226
/**
220227
* Disconnect from remote host and free resource
221228
*
222229
*/
223230
protected function _disconnect()
224231
{
232+
// @codingStandardsIgnoreEnd
225233
if (is_resource($this->socket)) {
226234
fclose($this->socket);
227235
}
228236
}
229237

238+
// @codingStandardsIgnoreStart
230239
/**
231240
* Send the given request followed by a LINEEND to the server.
232241
*
@@ -236,6 +245,7 @@ protected function _disconnect()
236245
*/
237246
protected function _send($request)
238247
{
248+
// @codingStandardsIgnoreEnd
239249
if (!is_resource($this->socket)) {
240250
throw new Exception\RuntimeException('No connection has been established to ' . $this->host);
241251
}
@@ -254,6 +264,7 @@ protected function _send($request)
254264
return $result;
255265
}
256266

267+
// @codingStandardsIgnoreStart
257268
/**
258269
* Get a line from the stream.
259270
*
@@ -263,6 +274,7 @@ protected function _send($request)
263274
*/
264275
protected function _receive($timeout = null)
265276
{
277+
// @codingStandardsIgnoreEnd
266278
if (!is_resource($this->socket)) {
267279
throw new Exception\RuntimeException('No connection has been established to ' . $this->host);
268280
}
@@ -292,6 +304,7 @@ protected function _receive($timeout = null)
292304
return $response;
293305
}
294306

307+
// @codingStandardsIgnoreStart
295308
/**
296309
* Parse server response for successful codes
297310
*
@@ -305,6 +318,7 @@ protected function _receive($timeout = null)
305318
*/
306319
protected function _expect($code, $timeout = null)
307320
{
321+
// @codingStandardsIgnoreEnd
308322
$this->response = [];
309323
$errMsg = '';
310324

@@ -321,7 +335,9 @@ protected function _expect($code, $timeout = null)
321335
} elseif ($cmd === null || !in_array($cmd, $code)) {
322336
$errMsg = $msg;
323337
}
324-
} while (strpos($more, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
338+
339+
// The '-' message prefix indicates an information string instead of a response string.
340+
} while (strpos($more, '-') === 0);
325341

326342
if ($errMsg !== '') {
327343
throw new Exception\RuntimeException($errMsg);

src/Protocol/Imap.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function connect($host, $port = null, $ssl = false)
9696
), 0, $error);
9797
}
9898

99-
if (!$this->_assumedNextLine('* OK')) {
99+
if (!$this->assumedNextLine('* OK')) {
100100
throw new Exception\RuntimeException('host doesn\'t allow connection');
101101
}
102102

@@ -115,7 +115,7 @@ public function connect($host, $port = null, $ssl = false)
115115
* @throws Exception\RuntimeException
116116
* @return string next line
117117
*/
118-
protected function _nextLine()
118+
protected function nextLine()
119119
{
120120
$line = fgets($this->socket);
121121
if ($line === false) {
@@ -132,9 +132,9 @@ protected function _nextLine()
132132
* @param string $start the first bytes we assume to be in the next line
133133
* @return bool line starts with $start
134134
*/
135-
protected function _assumedNextLine($start)
135+
protected function assumedNextLine($start)
136136
{
137-
$line = $this->_nextLine();
137+
$line = $this->nextLine();
138138
return strpos($line, $start) === 0;
139139
}
140140

@@ -144,9 +144,9 @@ protected function _assumedNextLine($start)
144144
* @param string $tag tag of line is returned by reference
145145
* @return string next line
146146
*/
147-
protected function _nextTaggedLine(&$tag)
147+
protected function nextTaggedLine(&$tag)
148148
{
149-
$line = $this->_nextLine();
149+
$line = $this->nextLine();
150150

151151
// separate tag from line
152152
list($tag, $line) = explode(' ', $line, 2);
@@ -160,7 +160,7 @@ protected function _nextTaggedLine(&$tag)
160160
* @param string $line line to decode
161161
* @return array tokens, literals are returned as string, lists as array
162162
*/
163-
protected function _decodeLine($line)
163+
protected function decodeLine($line)
164164
{
165165
$tokens = [];
166166
$stack = [];
@@ -201,14 +201,14 @@ protected function _decodeLine($line)
201201
if (is_numeric($chars)) {
202202
$token = '';
203203
while (strlen($token) < $chars) {
204-
$token .= $this->_nextLine();
204+
$token .= $this->nextLine();
205205
}
206206
$line = '';
207207
if (strlen($token) > $chars) {
208208
$line = substr($token, $chars);
209209
$token = substr($token, 0, $chars);
210210
} else {
211-
$line .= $this->_nextLine();
211+
$line .= $this->nextLine();
212212
}
213213
$tokens[] = $token;
214214
$line = trim($line) . ' ';
@@ -262,9 +262,9 @@ protected function _decodeLine($line)
262262
public function readLine(&$tokens = [], $wantedTag = '*', $dontParse = false)
263263
{
264264
$tag = null; // define $tag variable before first use
265-
$line = $this->_nextTaggedLine($tag); // get next tag
265+
$line = $this->nextTaggedLine($tag); // get next tag
266266
if (!$dontParse) {
267-
$tokens = $this->_decodeLine($line);
267+
$tokens = $this->decodeLine($line);
268268
} else {
269269
$tokens = $line;
270270
}
@@ -324,7 +324,7 @@ public function sendRequest($command, $tokens = [], &$tag = null)
324324
if (fwrite($this->socket, $line . ' ' . $token[0] . "\r\n") === false) {
325325
throw new Exception\RuntimeException('cannot write - connection closed?');
326326
}
327-
if (!$this->_assumedNextLine('+ ')) {
327+
if (!$this->assumedNextLine('+ ')) {
328328
throw new Exception\RuntimeException('cannot send literal string');
329329
}
330330
$line = $token[1];

0 commit comments

Comments
 (0)