Skip to content

Commit d9e9504

Browse files
committedJul 17, 2015
Merge branch 'PSR2-1.0' into PSR2-2.0
* PSR2-1.0: Fix indentation phpcbf did not fix. Remove PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket exception. Use phpcbf to fix PHP code to ruleset. Ignore coding guidelines in ANSI switch block. Base code sniffer ruleset on PSR2 rather than PEAR. Update PHP Code Sniffer to 2.3.3 Conflicts: build/code-sniffer-ruleset-tests.xml build/code-sniffer-ruleset.xml composer.lock phpseclib/Crypt/DES.php phpseclib/Crypt/Hash.php phpseclib/Crypt/RSA.php phpseclib/File/X509.php phpseclib/Math/BigInteger.php phpseclib/Net/SFTP.php phpseclib/Net/SSH1.php phpseclib/Net/SSH2.php tests/Functional/Net/SFTPUserStoryTest.php tests/Unit/Crypt/TwofishTest.php
2 parents 4b5cc0c + 847082a commit d9e9504

39 files changed

+649
-429
lines changed
 

‎build/code-sniffer-ruleset-tests.xml

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,12 @@
55

66
<!-- In general rules that apply to library code also apply to tests. -->
77
<rule ref="./code-sniffer-ruleset.xml">
8-
<!-- Exceptions to the library coding standard follow. -->
8+
<!-- Exceptions to the library coding standard follow. -->
99

10-
<!-- We do not care too much about method, class and file documentation,
11-
but having @author, @copyright and @license tags would be nice.
12-
The following configuration does not check for these tags, but
13-
complains if the file doc block is missing completely. -->
14-
<exclude name="PEAR.Commenting.ClassComment" />
15-
<exclude name="PEAR.Commenting.FunctionComment" />
16-
<exclude name="PEAR.Commenting.FileComment.MissingTag" />
17-
<exclude name="PEAR.Commenting.FileComment.MissingVersion" />
18-
<exclude name="PEAR.Commenting.FileComment.SpacingBeforeTags" />
19-
20-
<!-- Test classes do not have to be namespaced. -->
21-
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
10+
<!-- Test classes do not have to be namespaced but may use pseudo-namespacing
11+
using underscore. -->
12+
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
13+
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
2214
</rule>
2315

2416
</ruleset>

‎build/code-sniffer-ruleset.xml

+19-71
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,25 @@
33

44
<description>phpseclib coding standard</description>
55

6-
<!-- We are using the PEAR standard as a base -->
7-
<rule ref="PEAR">
8-
<!-- Temporary exceptions to the PEAR standard follow -->
9-
<exclude name="Generic.ControlStructures.InlineControlStructure.Discouraged" />
10-
<exclude name="Generic.Files.LineLength.TooLong" />
11-
<exclude name="PEAR.NamingConventions.ValidFunctionName.FunctionNoCapital" />
12-
<exclude name="PEAR.NamingConventions.ValidFunctionName.NotCamelCaps" />
13-
<exclude name="PEAR.Commenting.ClassComment.InvalidVersion" />
14-
<exclude name="PEAR.Commenting.ClassComment.MissingTag" />
15-
<exclude name="PEAR.Commenting.FileComment.EmptyCopyright" />
16-
<exclude name="PEAR.Commenting.FileComment.InvalidVersion" />
17-
<exclude name="PEAR.Commenting.FunctionComment.ExtraParamComment" />
18-
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn" />
19-
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment" />
20-
<exclude name="PEAR.Commenting.FunctionComment.MissingParamName" />
21-
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag" />
22-
<exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned" />
23-
<exclude name="PEAR.Commenting.FunctionComment.ParameterNamesNotAligned" />
24-
<exclude name="PEAR.Commenting.FunctionComment.ParamNameNoMatch" />
25-
<exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParams" />
26-
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeParams" />
27-
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags" />
28-
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
29-
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
30-
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket" />
31-
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.BreakIdent" />
32-
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.Indent" />
33-
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.Line" />
34-
<exclude name="PEAR.WhiteSpace.ScopeIndent.Incorrect" />
6+
<!-- We are using the PSR2 standard as a base -->
7+
<rule ref="PSR2">
8+
<!-- Exceptions due to legacy code with PHP4 compatibility -->
9+
<exclude name="PSR2.Classes.PropertyDeclaration.ScopeMissing" />
10+
<exclude name="PSR2.Classes.PropertyDeclaration.VarUsed" />
11+
<exclude name="Squiz.Scope.MethodScope.Missing" />
12+
13+
<!-- Exceptions for backward compatibility -->
14+
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
15+
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
16+
17+
<!-- Exceptions for whitespacing -->
18+
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma" />
19+
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE" />
20+
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT" />
21+
22+
<!-- Other Exceptions -->
23+
<exclude name="Generic.Files.LineLength.TooLong" />
24+
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
3525
</rule>
3626

3727
<!-- Useful additional rules follow -->
@@ -42,46 +32,4 @@
4232
<!-- A method MUST not only call its parent -->
4333
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
4434

45-
<!-- All code files MUST use only UTF-8 without BOM. -->
46-
<rule ref="Generic.Files.ByteOrderMark" />
47-
48-
<!-- Constructors MUST be called __construct() instead of after the class. -->
49-
<rule ref="Generic.NamingConventions.ConstructorName" />
50-
51-
<!-- Classes etc. MUST be namespaced -->
52-
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace" />
53-
54-
<!-- A file MUST not contain more than one class/interface -->
55-
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses" />
56-
57-
<!-- Files containing classes MUST not have any side-effects -->
58-
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols" />
59-
60-
<!-- Each file MUST end with exactly one newline character -->
61-
<rule ref="PSR2.Files.EndFileNewline" />
62-
63-
<!-- In the argument list, there MUST NOT be a space before each comma,
64-
and there MUST be one space after each comma. -->
65-
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
66-
<properties>
67-
<property name="equalsSpacing" value="1"/>
68-
</properties>
69-
</rule>
70-
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint" />
71-
72-
<!-- There MUST NOT be trailing whitespace at the end of lines. -->
73-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
74-
75-
<!-- There MUST NOT be whitespace before the first content of a file -->
76-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" />
77-
78-
<!-- There MUST NOT be whitespace after the last content of a file -->
79-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" />
80-
81-
<!-- Functions MUST NOT contain multiple empty lines in a row -->
82-
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" />
83-
84-
<!-- The ?> closing tag MUST be omitted from files containing only PHP. -->
85-
<rule ref="Zend.Files.ClosingTag" />
86-
8735
</ruleset>

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"phing/phing": "~2.7",
5353
"phpunit/phpunit": "~4.0",
5454
"sami/sami": "~2.0",
55-
"squizlabs/php_codesniffer": "~1.5"
55+
"squizlabs/php_codesniffer": "~2.0"
5656
},
5757
"suggest": {
5858
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a wide variety of cryptographic operations.",

‎composer.lock

+13-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎phpseclib/Crypt/AES.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* PHP version 5
99
*
10-
* NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
10+
* NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
1111
* just a wrapper to Rijndael.php you may consider using Rijndael.php instead of
1212
* to save one include_once().
1313
*

‎phpseclib/Crypt/Base.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ function encrypt($plaintext)
707707
$iv = substr_replace($iv, $block, 0, $overflow);
708708
$ciphertext.= $block;
709709
$pos = $overflow;
710-
} else if ($len) {
710+
} elseif ($len) {
711711
$ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
712712
$iv = substr($ciphertext, -$this->block_size);
713713
}
@@ -1014,7 +1014,7 @@ function decrypt($ciphertext)
10141014
$plaintext.= $iv ^ substr($ciphertext, -$overflow);
10151015
$iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow);
10161016
$pos = $overflow;
1017-
} else if ($len) {
1017+
} elseif ($len) {
10181018
$plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
10191019
$iv = substr($ciphertext, -$this->block_size);
10201020
}
@@ -1290,7 +1290,7 @@ function _openssl_ctr_process($plaintext, &$encryptIV, &$buffer)
12901290
$buffer['ciphertext'] = substr($temp, $overflow);
12911291
$encryptIV = $temp;
12921292
}
1293-
} else if (!strlen($buffer['ciphertext'])) {
1293+
} elseif (!strlen($buffer['ciphertext'])) {
12941294
$ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
12951295
$temp = $this->_string_pop($ciphertext, $block_size);
12961296
if ($this->continuousBuffer) {

‎phpseclib/Crypt/DES.php

-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,6 @@ function _setupInlineCrypt()
13781378
// Creating code for en- and decryption.
13791379
$crypt_block = array();
13801380
foreach (array(self::ENCRYPT, self::DECRYPT) as $c) {
1381-
13821381
/* Do the initial IP permutation. */
13831382
$crypt_block[$c] = '
13841383
$in = unpack("N*", $in);

‎phpseclib/Crypt/Hash.php

+20-18
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Hash
139139
*/
140140
function __construct($hash = 'sha1')
141141
{
142-
if ( !defined('CRYPT_HASH_MODE') ) {
142+
if (!defined('CRYPT_HASH_MODE')) {
143143
switch (true) {
144144
case extension_loaded('hash'):
145145
define('CRYPT_HASH_MODE', self::MODE_HASH);
@@ -228,7 +228,7 @@ function setHash($hash)
228228
$mode = CRYPT_HASH_MODE;
229229
}
230230

231-
switch ( $mode ) {
231+
switch ($mode) {
232232
case self::MODE_MHASH:
233233
switch ($hash) {
234234
case 'md5':
@@ -262,26 +262,26 @@ function setHash($hash)
262262

263263
switch ($hash) {
264264
case 'md2':
265-
$this->b = 16;
266-
$this->hash = array($this, '_md2');
267-
break;
265+
$this->b = 16;
266+
$this->hash = array($this, '_md2');
267+
break;
268268
case 'md5':
269-
$this->b = 64;
270-
$this->hash = array($this, '_md5');
271-
break;
269+
$this->b = 64;
270+
$this->hash = array($this, '_md5');
271+
break;
272272
case 'sha256':
273-
$this->b = 64;
274-
$this->hash = array($this, '_sha256');
275-
break;
273+
$this->b = 64;
274+
$this->hash = array($this, '_sha256');
275+
break;
276276
case 'sha384':
277277
case 'sha512':
278-
$this->b = 128;
279-
$this->hash = array($this, '_sha512');
280-
break;
278+
$this->b = 128;
279+
$this->hash = array($this, '_sha512');
280+
break;
281281
case 'sha1':
282282
default:
283-
$this->b = 64;
284-
$this->hash = array($this, '_sha1');
283+
$this->b = 64;
284+
$this->hash = array($this, '_sha1');
285285
}
286286

287287
$this->ipad = str_repeat(chr(0x36), $this->b);
@@ -300,7 +300,7 @@ function hash($text)
300300
$mode = is_array($this->hash) ? self::MODE_INTERNAL : CRYPT_HASH_MODE;
301301

302302
if (!empty($this->key) || is_string($this->key)) {
303-
switch ( $mode ) {
303+
switch ($mode) {
304304
case self::MODE_MHASH:
305305
$output = mhash($this->hash, $text, $this->key);
306306
break;
@@ -323,7 +323,7 @@ function hash($text)
323323
$output = call_user_func($this->hash, $output); // step 7
324324
}
325325
} else {
326-
switch ( $mode ) {
326+
switch ($mode) {
327327
case self::MODE_MHASH:
328328
$output = mhash($this->hash, $text);
329329
break;
@@ -497,12 +497,14 @@ function _sha256($m)
497497

498498
// Extend the sixteen 32-bit words into sixty-four 32-bit words
499499
for ($i = 16; $i < 64; $i++) {
500+
// @codingStandardsIgnoreStart
500501
$s0 = $this->_rightRotate($w[$i - 15], 7) ^
501502
$this->_rightRotate($w[$i - 15], 18) ^
502503
$this->_rightShift( $w[$i - 15], 3);
503504
$s1 = $this->_rightRotate($w[$i - 2], 17) ^
504505
$this->_rightRotate($w[$i - 2], 19) ^
505506
$this->_rightShift( $w[$i - 2], 10);
507+
// @codingStandardsIgnoreEnd
506508
$w[$i] = $this->_add($w[$i - 16], $s0, $w[$i - 7], $s1);
507509

508510
}

‎phpseclib/Crypt/RC2.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function setKey($key, $t1 = 0)
316316

317317
if ($t1 <= 0) {
318318
$t1 = $this->default_key_length;
319-
} else if ($t1 > 1024) {
319+
} elseif ($t1 > 1024) {
320320
$t1 = 1024;
321321
}
322322
$this->current_key_length = $t1;

0 commit comments

Comments
 (0)
Please sign in to comment.