Skip to content

Commit 452d31b

Browse files
committed
Merge branch 'fix-code-sniffs'
2 parents 14e90c3 + 58d3354 commit 452d31b

19 files changed

+202
-151
lines changed

lib/Providers/Qr/BaseHTTPQRCodeProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class BaseHTTPQRCodeProvider implements IQRCodeProvider
99
protected function getContent($url)
1010
{
1111
$curlhandle = curl_init();
12-
12+
1313
curl_setopt_array($curlhandle, array(
1414
CURLOPT_URL => $url,
1515
CURLOPT_RETURNTRANSFER => true,
@@ -20,8 +20,8 @@ protected function getContent($url)
2020
CURLOPT_USERAGENT => 'TwoFactorAuth'
2121
));
2222
$data = curl_exec($curlhandle);
23-
23+
2424
curl_close($curlhandle);
2525
return $data;
2626
}
27-
}
27+
}

lib/Providers/Qr/IQRCodeProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ interface IQRCodeProvider
66
{
77
public function getQRCodeImage($qrtext, $size);
88
public function getMimeType();
9-
}
9+
}

lib/Providers/Qr/ImageChartsQRCodeProvider.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,38 @@
33
namespace RobThree\Auth\Providers\Qr;
44

55
// https://image-charts.com
6-
class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider
6+
class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider
77
{
88
public $errorcorrectionlevel;
99
public $margin;
1010

11-
function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 1)
11+
public function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 1)
1212
{
13-
if (!is_bool($verifyssl))
14-
throw new \QRException('VerifySSL must be bool');
13+
if (!is_bool($verifyssl)) {
14+
throw new QRException('VerifySSL must be bool');
15+
}
1516

1617
$this->verifyssl = $verifyssl;
17-
18+
1819
$this->errorcorrectionlevel = $errorcorrectionlevel;
1920
$this->margin = $margin;
2021
}
21-
22-
public function getMimeType()
22+
23+
public function getMimeType()
2324
{
2425
return 'image/png';
2526
}
26-
27-
public function getQRCodeImage($qrtext, $size)
27+
28+
public function getQRCodeImage($qrtext, $size)
2829
{
2930
return $this->getContent($this->getUrl($qrtext, $size));
3031
}
31-
32-
public function getUrl($qrtext, $size)
32+
33+
public function getUrl($qrtext, $size)
3334
{
3435
return 'https://image-charts.com/chart?cht=qr'
35-
. '&chs=' . ceil($size/2) . 'x' . ceil($size/2)
36+
. '&chs=' . ceil($size / 2) . 'x' . ceil($size / 2)
3637
. '&chld=' . $this->errorcorrectionlevel . '|' . $this->margin
3738
. '&chl=' . rawurlencode($qrtext);
3839
}
39-
}
40+
}

lib/Providers/Qr/QRException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace RobThree\Auth\Providers\Qr;
4+
35
use RobThree\Auth\TwoFactorAuthException;
46

5-
class QRException extends TwoFactorAuthException {}
7+
class QRException extends TwoFactorAuthException {}

lib/Providers/Qr/QRServerProvider.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace RobThree\Auth\Providers\Qr;
44

55
// http://goqr.me/api/doc/create-qr-code/
6-
class QRServerProvider extends BaseHTTPQRCodeProvider
6+
class QRServerProvider extends BaseHTTPQRCodeProvider
77
{
88
public $errorcorrectionlevel;
99
public $margin;
@@ -12,51 +12,51 @@ class QRServerProvider extends BaseHTTPQRCodeProvider
1212
public $color;
1313
public $format;
1414

15-
function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 4, $qzone = 1, $bgcolor = 'ffffff', $color = '000000', $format = 'png')
15+
public function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 4, $qzone = 1, $bgcolor = 'ffffff', $color = '000000', $format = 'png')
1616
{
17-
if (!is_bool($verifyssl))
17+
if (!is_bool($verifyssl)) {
1818
throw new QRException('VerifySSL must be bool');
19+
}
1920

2021
$this->verifyssl = $verifyssl;
21-
22+
2223
$this->errorcorrectionlevel = $errorcorrectionlevel;
2324
$this->margin = $margin;
2425
$this->qzone = $qzone;
2526
$this->bgcolor = $bgcolor;
2627
$this->color = $color;
2728
$this->format = $format;
2829
}
29-
30-
public function getMimeType()
30+
31+
public function getMimeType()
3132
{
32-
switch (strtolower($this->format))
33-
{
34-
case 'png':
33+
switch (strtolower($this->format)) {
34+
case 'png':
3535
return 'image/png';
36-
case 'gif':
36+
case 'gif':
3737
return 'image/gif';
38-
case 'jpg':
39-
case 'jpeg':
38+
case 'jpg':
39+
case 'jpeg':
4040
return 'image/jpeg';
41-
case 'svg':
41+
case 'svg':
4242
return 'image/svg+xml';
43-
case 'eps':
43+
case 'eps':
4444
return 'application/postscript';
4545
}
46-
throw new \QRException(sprintf('Unknown MIME-type: %s', $this->format));
46+
throw new QRException(sprintf('Unknown MIME-type: %s', $this->format));
4747
}
48-
49-
public function getQRCodeImage($qrtext, $size)
48+
49+
public function getQRCodeImage($qrtext, $size)
5050
{
5151
return $this->getContent($this->getUrl($qrtext, $size));
5252
}
53-
54-
private function decodeColor($value)
53+
54+
private function decodeColor($value)
5555
{
5656
return vsprintf('%d-%d-%d', sscanf($value, "%02x%02x%02x"));
5757
}
58-
59-
public function getUrl($qrtext, $size)
58+
59+
public function getUrl($qrtext, $size)
6060
{
6161
return 'https://api.qrserver.com/v1/create-qr-code/'
6262
. '?size=' . $size . 'x' . $size
@@ -68,4 +68,4 @@ public function getUrl($qrtext, $size)
6868
. '&format=' . strtolower($this->format)
6969
. '&data=' . rawurlencode($qrtext);
7070
}
71-
}
71+
}

lib/Providers/Qr/QRicketProvider.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace RobThree\Auth\Providers\Qr;
44

55
// http://qrickit.com/qrickit_apps/qrickit_api.php
6-
class QRicketProvider extends BaseHTTPQRCodeProvider
6+
class QRicketProvider extends BaseHTTPQRCodeProvider
77
{
88
public $errorcorrectionlevel;
99
public $margin;
@@ -12,36 +12,35 @@ class QRicketProvider extends BaseHTTPQRCodeProvider
1212
public $color;
1313
public $format;
1414

15-
function __construct($errorcorrectionlevel = 'L', $bgcolor = 'ffffff', $color = '000000', $format = 'p')
15+
public function __construct($errorcorrectionlevel = 'L', $bgcolor = 'ffffff', $color = '000000', $format = 'p')
1616
{
1717
$this->verifyssl = false;
18-
18+
1919
$this->errorcorrectionlevel = $errorcorrectionlevel;
2020
$this->bgcolor = $bgcolor;
2121
$this->color = $color;
2222
$this->format = $format;
2323
}
24-
25-
public function getMimeType()
24+
25+
public function getMimeType()
2626
{
27-
switch (strtolower($this->format))
28-
{
29-
case 'p':
27+
switch (strtolower($this->format)) {
28+
case 'p':
3029
return 'image/png';
31-
case 'g':
30+
case 'g':
3231
return 'image/gif';
33-
case 'j':
32+
case 'j':
3433
return 'image/jpeg';
3534
}
36-
throw new \QRException(sprintf('Unknown MIME-type: %s', $this->format));
35+
throw new QRException(sprintf('Unknown MIME-type: %s', $this->format));
3736
}
38-
39-
public function getQRCodeImage($qrtext, $size)
37+
38+
public function getQRCodeImage($qrtext, $size)
4039
{
4140
return $this->getContent($this->getUrl($qrtext, $size));
4241
}
43-
44-
public function getUrl($qrtext, $size)
42+
43+
public function getUrl($qrtext, $size)
4544
{
4645
return 'http://qrickit.com/api/qr'
4746
. '?qrsize=' . $size
@@ -51,4 +50,4 @@ public function getUrl($qrtext, $size)
5150
. '&t=' . strtolower($this->format)
5251
. '&d=' . rawurlencode($qrtext);
5352
}
54-
}
53+
}

lib/Providers/Rng/CSRNGProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
class CSRNGProvider implements IRNGProvider
66
{
7-
public function getRandomBytes($bytecount) {
7+
public function getRandomBytes($bytecount)
8+
{
89
return random_bytes($bytecount); // PHP7+
910
}
10-
11-
public function isCryptographicallySecure() {
11+
12+
public function isCryptographicallySecure()
13+
{
1214
return true;
1315
}
14-
}
16+
}

lib/Providers/Rng/HashRNGProvider.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
<?php
2+
23
namespace RobThree\Auth\Providers\Rng;
34

45
class HashRNGProvider implements IRNGProvider
56
{
67
private $algorithm;
7-
8-
function __construct($algorithm = 'sha256' ) {
8+
9+
public function __construct($algorithm = 'sha256')
10+
{
911
$algos = array_values(hash_algos());
10-
if (!in_array($algorithm, $algos, true))
11-
throw new \RNGException('Unsupported algorithm specified');
12+
if (!in_array($algorithm, $algos, true)) {
13+
throw new RNGException('Unsupported algorithm specified');
14+
}
1215
$this->algorithm = $algorithm;
1316
}
14-
15-
public function getRandomBytes($bytecount) {
17+
18+
public function getRandomBytes($bytecount)
19+
{
1620
$result = '';
1721
$hash = mt_rand();
1822
for ($i = 0; $i < $bytecount; $i++) {
19-
$hash = hash($this->algorithm, $hash.mt_rand(), true);
20-
$result .= $hash[mt_rand(0, strlen($hash)-1)];
23+
$hash = hash($this->algorithm, $hash . mt_rand(), true);
24+
$result .= $hash[mt_rand(0, strlen($hash) - 1)];
2125
}
2226
return $result;
2327
}
24-
25-
public function isCryptographicallySecure() {
28+
29+
public function isCryptographicallySecure()
30+
{
2631
return false;
2732
}
2833
}

lib/Providers/Rng/IRNGProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ interface IRNGProvider
66
{
77
public function getRandomBytes($bytecount);
88
public function isCryptographicallySecure();
9-
}
9+
}

lib/Providers/Rng/MCryptRNGProvider.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
class MCryptRNGProvider implements IRNGProvider
66
{
77
private $source;
8-
9-
function __construct($source = MCRYPT_DEV_URANDOM) {
8+
9+
public function __construct($source = MCRYPT_DEV_URANDOM)
10+
{
1011
$this->source = $source;
1112
}
12-
13-
public function getRandomBytes($bytecount) {
13+
14+
public function getRandomBytes($bytecount)
15+
{
1416
$result = @mcrypt_create_iv($bytecount, $this->source);
15-
if ($result === false)
16-
throw new \RNGException('mcrypt_create_iv returned an invalid value');
17+
if ($result === false) {
18+
throw new RNGException('mcrypt_create_iv returned an invalid value');
19+
}
1720
return $result;
1821
}
19-
20-
public function isCryptographicallySecure() {
22+
23+
public function isCryptographicallySecure()
24+
{
2125
return true;
2226
}
23-
}
27+
}

0 commit comments

Comments
 (0)