Skip to content

Commit

Permalink
💅 Add GreenPass::isFormallyValid check
Browse files Browse the repository at this point in the history
  • Loading branch information
masterix21 committed Jul 19, 2021
1 parent 99c29f0 commit 5ffa64b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/Concerns/ImplementsChecks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Masterix21\GreenPass\Concerns;

use Masterix21\GreenPass\GreenPass;

/** @mixin GreenPass */
trait ImplementsChecks
{
public static function isFormallyValid($qrcode): bool
{
return str_starts_with($qrcode, 'HC1:');
}
}
2 changes: 1 addition & 1 deletion src/Concerns/ImplementsDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait ImplementsDecode
*/
public static function decode(string $qrcode)
{
if (substr($qrcode, 0, 4) !== 'HC1:') {
if (! static::isFormallyValid($qrcode)) {
throw new InvalidQrcode();
}

Expand Down
2 changes: 2 additions & 0 deletions src/GreenPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Masterix21\GreenPass;

use Masterix21\GreenPass\Concerns\ImplementsChecks;
use Masterix21\GreenPass\Concerns\ImplementsDecode;
use Masterix21\GreenPass\Entities\Certificates\Concerns\CertificateType;
use Masterix21\GreenPass\Entities\Certificates\RecoveryStatement;
Expand All @@ -11,6 +12,7 @@

class GreenPass
{
use ImplementsChecks;
use ImplementsDecode;

/**
Expand Down

0 comments on commit 5ffa64b

Please sign in to comment.