Skip to content

Commit bf68799

Browse files
Bump minimum to 7.3, update deps, support PHP 8.0 (#2)
1 parent 380b0f8 commit bf68799

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
operating-system: [ubuntu-latest]
19-
php-versions: ['7.2', '7.3', '7.4']
20-
# TODO: When bacon/bacon-qr-code supports PHP 8:
21-
# php-versions: ['7.2', '7.3', '7.4', '8.0']
19+
php-versions: ['7.3', '7.4', '8.0']
2220

2321
steps:
2422
- name: Checkout
@@ -30,6 +28,7 @@ jobs:
3028
php-version: ${{ matrix.php-versions }}
3129
coverage: pcov
3230
tools: composer:v2
31+
extensions: gd
3332
env:
3433
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3534

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is a fork of https://github.com/PHPGangsta/GoogleAuthenticator with the fol
99
- No longer generates Google's Chart API to make QR code links
1010
- Uses namespacing
1111
- Augmented test coverage to 100%
12-
- Bumped minimum PHP version to 7.2
12+
- Bumped minimum PHP version to 7.3
1313

1414
Original License:
1515
-----------------

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"issues": "https://github.com/Vectorface/GoogleAuthenticator/issues"
2424
},
2525
"require": {
26-
"php": ">=7.2",
27-
"endroid/qr-code": "^3.9.3"
26+
"php": ">=7.3",
27+
"endroid/qr-code": "^4.0.0"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^8"
30+
"phpunit/phpunit": "^9"
3131
},
3232
"config": {
3333
"sort-packages": true

src/GoogleAuthenticator.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Vectorface;
44

5-
use Endroid\QrCode\ErrorCorrectionLevel;
6-
use Endroid\QrCode\QrCode;
5+
use Endroid\QrCode\Builder\Builder;
6+
use Endroid\QrCode\Writer\PngWriter;
77
use Exception;
88

99
/**
@@ -105,26 +105,25 @@ public function getCode(string $secret, int $timeSlice = null) : string
105105
public function getQRCodeUrl(string $name, string $secret) : string
106106
{
107107
$uri = "otpauth://totp/$name?secret=$secret";
108-
return 'data:image/png;base64,' . base64_encode($this->getQRCodeSRC($uri));
108+
return $this->getQRCodeDataUri($uri);
109109
}
110110

111111
/**
112112
* Generate a QRCode for a given string
113113
*
114114
* @param string $uri to encode into a QRCode
115115
* @return string binary data of the PNG of the QRCode
116+
* @throws Exception
116117
*/
117-
protected function getQRCodeSRC(string $uri) : string
118+
protected function getQRCodeDataUri(string $uri) : string
118119
{
119-
$qr_code = new QrCode($uri);
120-
$qr_code->setSize(260);
121-
$qr_code->setMargin(10);
122-
$qr_code->setErrorCorrectionLevel(ErrorCorrectionLevel::LOW());
123-
$qr_code->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
124-
$qr_code->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
125-
$qr_code->setValidateResult(false);
126-
127-
return $qr_code->writeString();
120+
return Builder::create()
121+
->data($uri)
122+
->writer(new PngWriter)
123+
->size(260)
124+
->margin(10)
125+
->build()
126+
->getDataUri();
128127
}
129128

130129
/**

tests/GoogleAuthenticatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testGetQRCodeUrl()
103103
$this->assertStringStartsWith($prefix, $url);
104104

105105
$base64part = substr($url, strlen($prefix));
106-
$this->assertRegExp("#^[a-zA-Z0-9/+]*={0,2}$#", $base64part);
106+
$this->assertMatchesRegularExpression("#^[a-zA-Z0-9/+]*={0,2}$#", $base64part);
107107
}
108108

109109
/**

0 commit comments

Comments
 (0)