Skip to content

Commit feb0e82

Browse files
authored
chore: fixes cs and adds cs checking to travis (#284)
1 parent 3811d69 commit feb0e82

10 files changed

+87
-136
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
/.gitignore export-ignore
66
/.travis.yml export-ignore
77
/phpunit.xml.dist export-ignore
8-
/run-tests.sh export-ignore

.travis.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: php
22

3+
branches:
4+
- only: [master]
5+
36
php:
47
- 5.6
58
- 7.0
@@ -16,8 +19,18 @@ matrix:
1619
dist: trusty
1720
- php: 5.5
1821
dist: trusty
22+
- name: "Check Style"
23+
php: "7.4"
24+
env: RUN_CS_FIXER=true
1925

2026
sudo: false
2127

2228
before_script: composer install
23-
script: vendor/bin/phpunit
29+
script:
30+
- if [ "${RUN_CS_FIXER}" = "true" ]; then
31+
composer require friendsofphp/php-cs-fixer &&
32+
vendor/bin/php-cs-fixer fix --diff --dry-run . &&
33+
vendor/bin/php-cs-fixer fix --rules=native_function_invocation --allow-risky=yes --diff src;
34+
else
35+
vendor/bin/phpunit;
36+
fi

run-tests.sh

-37
This file was deleted.

src/BeforeValidException.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
class BeforeValidException extends \UnexpectedValueException
55
{
6-
76
}

src/ExpiredException.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
class ExpiredException extends \UnexpectedValueException
55
{
6-
76
}

src/JWK.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function parseKeySet(array $jwks)
5050
}
5151
}
5252

53-
if (0 === count($keys)) {
53+
if (0 === \count($keys)) {
5454
throw new UnexpectedValueException('No supported algorithms found in JWK Set');
5555
}
5656

@@ -81,18 +81,18 @@ private static function parseKey(array $jwk)
8181

8282
switch ($jwk['kty']) {
8383
case 'RSA':
84-
if (array_key_exists('d', $jwk)) {
84+
if (\array_key_exists('d', $jwk)) {
8585
throw new UnexpectedValueException('RSA private keys are not supported');
8686
}
8787
if (!isset($jwk['n']) || !isset($jwk['e'])) {
8888
throw new UnexpectedValueException('RSA keys must contain values for both "n" and "e"');
8989
}
9090

9191
$pem = self::createPemFromModulusAndExponent($jwk['n'], $jwk['e']);
92-
$publicKey = openssl_pkey_get_public($pem);
92+
$publicKey = \openssl_pkey_get_public($pem);
9393
if (false === $publicKey) {
9494
throw new DomainException(
95-
'OpenSSL error: ' . openssl_error_string()
95+
'OpenSSL error: ' . \openssl_error_string()
9696
);
9797
}
9898
return $publicKey;
@@ -118,32 +118,32 @@ private static function createPemFromModulusAndExponent($n, $e)
118118
$publicExponent = JWT::urlsafeB64Decode($e);
119119

120120
$components = array(
121-
'modulus' => pack('Ca*a*', 2, self::encodeLength(strlen($modulus)), $modulus),
122-
'publicExponent' => pack('Ca*a*', 2, self::encodeLength(strlen($publicExponent)), $publicExponent)
121+
'modulus' => \pack('Ca*a*', 2, self::encodeLength(\strlen($modulus)), $modulus),
122+
'publicExponent' => \pack('Ca*a*', 2, self::encodeLength(\strlen($publicExponent)), $publicExponent)
123123
);
124124

125-
$rsaPublicKey = pack(
125+
$rsaPublicKey = \pack(
126126
'Ca*a*a*',
127127
48,
128-
self::encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
128+
self::encodeLength(\strlen($components['modulus']) + \strlen($components['publicExponent'])),
129129
$components['modulus'],
130130
$components['publicExponent']
131131
);
132132

133133
// sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
134-
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
135-
$rsaPublicKey = chr(0) . $rsaPublicKey;
136-
$rsaPublicKey = chr(3) . self::encodeLength(strlen($rsaPublicKey)) . $rsaPublicKey;
134+
$rsaOID = \pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
135+
$rsaPublicKey = \chr(0) . $rsaPublicKey;
136+
$rsaPublicKey = \chr(3) . self::encodeLength(\strlen($rsaPublicKey)) . $rsaPublicKey;
137137

138-
$rsaPublicKey = pack(
138+
$rsaPublicKey = \pack(
139139
'Ca*a*',
140140
48,
141-
self::encodeLength(strlen($rsaOID . $rsaPublicKey)),
141+
self::encodeLength(\strlen($rsaOID . $rsaPublicKey)),
142142
$rsaOID . $rsaPublicKey
143143
);
144144

145145
$rsaPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
146-
chunk_split(base64_encode($rsaPublicKey), 64) .
146+
\chunk_split(\base64_encode($rsaPublicKey), 64) .
147147
'-----END PUBLIC KEY-----';
148148

149149
return $rsaPublicKey;
@@ -161,11 +161,11 @@ private static function createPemFromModulusAndExponent($n, $e)
161161
private static function encodeLength($length)
162162
{
163163
if ($length <= 0x7F) {
164-
return chr($length);
164+
return \chr($length);
165165
}
166166

167-
$temp = ltrim(pack('N', $length), chr(0));
167+
$temp = \ltrim(\pack('N', $length), \chr(0));
168168

169-
return pack('Ca*', 0x80 | strlen($temp), $temp);
169+
return \pack('Ca*', 0x80 | \strlen($temp), $temp);
170170
}
171171
}

0 commit comments

Comments
 (0)