Skip to content

Commit

Permalink
Use bacon 2
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Dec 1, 2018
1 parent b93d790 commit e467439
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": ">=7.1",
"ext-gd": "*",
"bacon/bacon-qr-code": "^1.0.3",
"bacon/bacon-qr-code": "^2.0",
"endroid/installer": "^1.0.3",
"khanamiryan/qrcode-detector-decoder": "^1.0.2",
"myclabs/php-enum": "^1.5",
Expand Down
8 changes: 8 additions & 0 deletions src/ErrorCorrectionLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
namespace Endroid\QrCode;

use MyCLabs\Enum\Enum;
use BaconQrCode\Common\ErrorCorrectionLevel as BaconErrorCorrectionLevel;

class ErrorCorrectionLevel extends Enum
{
const LOW = 'low';
const MEDIUM = 'medium';
const QUARTILE = 'quartile';
const HIGH = 'high';

public function toBaconErrorCorrectionLevel(): BaconErrorCorrectionLevel
{
$name = strtoupper(substr($this->getValue(), 0, 1));

return BaconErrorCorrectionLevel::valueOf($name);
}
}
8 changes: 4 additions & 4 deletions src/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ public function getRoundBlockSize(): bool
return $this->roundBlockSize;
}

public function setErrorCorrectionLevel(string $errorCorrectionLevel): void
public function setErrorCorrectionLevel(ErrorCorrectionLevel $errorCorrectionLevel): void
{
$this->errorCorrectionLevel = new ErrorCorrectionLevel($errorCorrectionLevel);
$this->errorCorrectionLevel = $errorCorrectionLevel;
}

public function getErrorCorrectionLevel(): string
public function getErrorCorrectionLevel(): ErrorCorrectionLevel
{
return $this->errorCorrectionLevel->getValue();
return $this->errorCorrectionLevel;
}

public function setLogoPath(string $logoPath): void
Expand Down
2 changes: 1 addition & 1 deletion src/QrCodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getEncoding(): string;

public function getRoundBlockSize(): bool;

public function getErrorCorrectionLevel(): string;
public function getErrorCorrectionLevel(): ErrorCorrectionLevel;

public function getLogoPath(): ?string;

Expand Down
7 changes: 3 additions & 4 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@

namespace Endroid\QrCode\Writer;

use BaconQrCode\Common\ErrorCorrectionLevel;
use BaconQrCode\Encoder\Encoder;
use Endroid\QrCode\QrCodeInterface;

abstract class AbstractWriter implements WriterInterface
{
protected function getData(QrCodeInterface $qrCode): array
{
$name = strtoupper(substr($qrCode->getErrorCorrectionLevel(), 0, 1));
$errorCorrectionLevel = constant('BaconQrCode\Common\ErrorCorrectionLevel::'.$name);
$baconErrorCorrectionLevel = $qrCode->getErrorCorrectionLevel()->toBaconErrorCorrectionLevel();

$baconQrCode = Encoder::encode($qrCode->getText(), new ErrorCorrectionLevel($errorCorrectionLevel), $qrCode->getEncoding());
$baconQrCode = Encoder::encode($qrCode->getText(), $baconErrorCorrectionLevel, $qrCode->getEncoding());

$matrix = $baconQrCode->getMatrix()->getArray()->toArray();

foreach ($matrix as &$row) {
$row = $row->toArray();
}
Expand Down

0 comments on commit e467439

Please sign in to comment.