Skip to content

Commit e2a5a82

Browse files
committed
fixed
1 parent 4cf9e9b commit e2a5a82

File tree

8 files changed

+101
-88
lines changed

8 files changed

+101
-88
lines changed

config/verify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ValidateSupporter::class => 'ef1a42701af6dc36e052556a0ee1c762394f9428',
1414
ValidatePro::class => '482b48f1a026684b6c1754e45ca180ffc52483ff',
1515
ValidateSignature::class => '5a8a855d4b59c44c298daa66801c79f2aba20492',
16-
Verify::class => 'e5a8ebb4878c0fd3387ec0cb2f28d9caa463e5bb',
16+
Verify::class => 'ffd01909f5189bc7bae21266e356f83c898ccd37',
1717
VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed',
1818
VerifyProStatus::class => '212e6ada794587ee8e2b81cf76e243d134a7e823',
1919
VerifyServiceProvider::class => '923b63b15d25e69b95ed1d5ec1c82ba57f1a7d74',

src/Console/Commands/CheckKeyCommand.php

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,69 @@
66
use LycheeVerify\Contract\Status;
77
use LycheeVerify\Validators\ValidatePro;
88
use LycheeVerify\Validators\ValidateSupporter;
9-
109
use function Safe\json_encode;
1110

1211
class CheckKeyCommand extends Command
1312
{
14-
/**
15-
* The name and signature of the console command.
16-
*
17-
* @var string
18-
*/
19-
protected $signature = 'verify:check-key {key : The license key to check}';
20-
21-
/**
22-
* The console command description.
23-
*
24-
* @var string
25-
*/
26-
protected $description = 'Check the sponsorship level for a given license key';
27-
28-
/**
29-
* Execute the console command.
30-
*/
31-
public function handle(): int
32-
{
33-
$key = $this->argument('key');
34-
35-
$validateSupporter = new ValidateSupporter();
36-
$validatePro = new ValidatePro();
37-
38-
// We use a dummy verifiable string for checking
39-
$verifiable = json_encode(['url' => '', 'email' => '']);
40-
41-
// Check Pro edition first (highest tier)
42-
if ($validatePro->validate($verifiable, $key)) {
43-
$this->info('Key: ' . $key);
44-
$this->info('Sponsorship Level: ' . Status::PRO_EDITION->value . ' (Pro Edition)');
45-
return Command::SUCCESS;
46-
}
47-
48-
// Check Supporter edition
49-
if ($validateSupporter->validate($verifiable, $key)) {
50-
$this->info('Key: ' . $key);
51-
$this->info('Sponsorship Level: ' . Status::SUPPORTER_EDITION->value . ' (Supporter Edition)');
52-
return Command::SUCCESS;
53-
}
54-
55-
// Key doesn't match any known tier
56-
$this->warn('Key: ' . $key);
57-
$this->warn('Sponsorship Level: ' . Status::FREE_EDITION->value . ' (No valid sponsorship found)');
58-
59-
return Command::FAILURE;
60-
}
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'verify:check-key {key : The license key to check}';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Check the sponsorship level for a given license key';
26+
27+
/**
28+
* Execute the console command.
29+
*/
30+
public function handle(): int
31+
{
32+
if (!$this->hasArgument('key')) {
33+
$this->error('No key provided. Please provide a license key to check.');
34+
35+
return Command::FAILURE;
36+
}
37+
38+
if (!is_string($this->argument('key'))) {
39+
$this->error('Invalid key format. The key must be a string.');
40+
41+
return Command::FAILURE;
42+
}
43+
44+
$key = $this->argument('key');
45+
46+
$validateSupporter = new ValidateSupporter();
47+
$validatePro = new ValidatePro();
48+
49+
// We use a dummy verifiable string for checking
50+
$verifiable = json_encode(['url' => '', 'email' => '']);
51+
52+
// Check Pro edition first (highest tier)
53+
if ($validatePro->validate($verifiable, $key)) {
54+
$this->info('Key: ' . $key);
55+
$this->info('Sponsorship Level: ' . Status::PRO_EDITION->value . ' (Pro Edition)');
56+
57+
return Command::SUCCESS;
58+
}
59+
60+
// Check Supporter edition
61+
if ($validateSupporter->validate($verifiable, $key)) {
62+
$this->info('Key: ' . $key);
63+
$this->info('Sponsorship Level: ' . Status::SUPPORTER_EDITION->value . ' (Supporter Edition)');
64+
65+
return Command::SUCCESS;
66+
}
67+
68+
// Key doesn't match any known tier
69+
$this->warn('Key: ' . $key);
70+
$this->warn('Sponsorship Level: ' . Status::FREE_EDITION->value . ' (No valid sponsorship found)');
71+
72+
return Command::FAILURE;
73+
}
6174
}

src/Contract/Status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ enum Status: string
1010
case FREE_EDITION = 'free';
1111
case SUPPORTER_EDITION = 'se';
1212
case PRO_EDITION = 'pro';
13-
case SIGNATURE_EDITION = 'signature';
13+
case SIGNATURE_EDITION = 'signature';
1414
}

src/Contract/VerifyInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public function is_supporter(): bool;
3636
*/
3737
public function is_pro(): bool;
3838

39-
/**
40-
* Return true if the user is a signature user
41-
*
42-
* @return bool
43-
*/
44-
public function is_signature(): bool;
39+
/**
40+
* Return true if the user is a signature user.
41+
*
42+
* @return bool
43+
*/
44+
public function is_signature(): bool;
4545

4646
/**
4747
* Authorize the operation if the installation is verified.

src/Exceptions/SupporterOnlyOperationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class SupporterOnlyOperationException extends BaseVerifyException
1212
public function __construct(Status $status = Status::SUPPORTER_EDITION)
1313
{
1414
$users = match ($status) {
15-
Status::SIGNATURE_EDITION => 'signature users',
15+
Status::SIGNATURE_EDITION => 'signature users',
1616
Status::PRO_EDITION => 'pro users',
1717
default => 'supporters',
1818
};

src/Verify.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use LycheeVerify\Validators\ValidatePro;
1010
use LycheeVerify\Validators\ValidateSignature;
1111
use LycheeVerify\Validators\ValidateSupporter;
12-
1312
use function Safe\json_encode;
1413
use function Safe\preg_replace;
1514

@@ -18,7 +17,7 @@ class Verify implements VerifyInterface
1817
private string $config_email;
1918
private string $license_key;
2019
private ValidateSignature $validateSignature;
21-
private ValidateSupporter $validateSupporter;
20+
private ValidateSupporter $validateSupporter;
2221
private ValidatePro $validatePro;
2322

2423
public function __construct(
@@ -32,7 +31,7 @@ public function __construct(
3231
$this->license_key = $license_key ?? DB::table('configs')->where('key', 'license_key')->first()?->value ?? ''; // @phpstan-ignore-line
3332
$this->validateSignature = new ValidateSignature($public_key);
3433
$this->validatePro = new ValidatePro($hash_pro);
35-
$this->validateSupporter = new ValidateSupporter($hash_supporter);
34+
$this->validateSupporter = new ValidateSupporter($hash_supporter);
3635
}
3736

3837
/**
@@ -52,7 +51,7 @@ public function get_status(): Status
5251
return $this->validatePro->grant();
5352
}
5453

55-
if ($this->config_email !== '' && $this->validateSignature->validate($base, $this->license_key)) {
54+
if ($this->config_email !== '' && $this->validateSignature->validate($base, $this->license_key)) {
5655
return $this->validateSignature->grant();
5756
}
5857

@@ -73,12 +72,13 @@ public function check(Status $required_status = Status::SUPPORTER_EDITION): bool
7372
}
7473

7574
$status = $this->get_status();
76-
return match ($status) {
77-
Status::SIGNATURE_EDITION => true,
78-
Status::PRO_EDITION => in_array($required_status, [Status::PRO_EDITION, Status::SUPPORTER_EDITION], true),
79-
Status::SUPPORTER_EDITION => in_array($required_status, [Status::SUPPORTER_EDITION], true),
80-
default => false,
81-
};
75+
76+
return match ($status) {
77+
Status::SIGNATURE_EDITION => true,
78+
Status::PRO_EDITION => in_array($required_status, [Status::PRO_EDITION, Status::SUPPORTER_EDITION], true),
79+
Status::SUPPORTER_EDITION => in_array($required_status, [Status::SUPPORTER_EDITION], true),
80+
default => false,
81+
};
8282
}
8383

8484
/**
@@ -101,15 +101,15 @@ public function is_pro(): bool
101101
return $this->check(Status::PRO_EDITION);
102102
}
103103

104-
/**
105-
* Return true if the user is a signature user
106-
*
107-
* @return bool
108-
*/
109-
public function is_signature(): bool
110-
{
111-
return $this->check(Status::SIGNATURE_EDITION);
112-
}
104+
/**
105+
* Return true if the user is a signature user.
106+
*
107+
* @return bool
108+
*/
109+
public function is_signature(): bool
110+
{
111+
return $this->check(Status::SIGNATURE_EDITION);
112+
}
113113

114114
/**
115115
* Authorize the operation if the installation is verified.
@@ -153,7 +153,7 @@ public function when(mixed $valIfTrue, mixed $valIfFalse, Status $required_statu
153153
*/
154154
public function validate(): bool
155155
{
156-
/** @var array<class-string,string>|null $checks */
156+
/** @var array<class-string,string>|null $checks */
157157
$checks = config('verify.validation');
158158
if ($checks === null || count($checks) === 0) {
159159
return false;

tests/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Constants
1010
public const HASH = '$2y$10$TBBCJeXOa10Y5WwLU.yeQ.4fQS/BujBknIvISyhlPzp.LU9jWIH2W';
1111
public const HASH_KEY = 'BSIM4-MEVVQ-HVQKG-Q6VNT-KP3EZ';
1212

13-
public const HASH2 = '$2y$10$QZe2zo7.0ymBbHTfg7j2YOLjVQV7St5.mHDaMUro0Kx2Ca/c0ZZZ2';
13+
public const HASH2 = '$2y$10$QZe2zo7.0ymBbHTfg7j2YOLjVQV7St5.mHDaMUro0Kx2Ca/c0ZZZ2';
1414
public const HASH2_KEY = 'OFVZ4-ZRIID-UIDXT-D6IAG-XC3RM';
1515

1616
public const EMAIL_TEST = '[email protected]';

tests/Verify/VerifyTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testVerifyDefault(): void
2020
self::assertTrue($verify->check(Status::FREE_EDITION));
2121
self::assertFalse($verify->check(Status::SUPPORTER_EDITION));
2222
self::assertFalse($verify->check(Status::PRO_EDITION));
23-
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
23+
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
2424
self::assertFalse($verify->is_supporter()); // User is not recognised as supporter.
2525
self::assertFalse($verify->is_pro()); // User is not recognised as pro.
2626

@@ -33,39 +33,39 @@ public function testVerifySupporter(): void
3333
$verify = new Verify(
3434
license_key: Constants::HASH_KEY,
3535
hash_supporter: Constants::HASH,
36-
hash_pro: Constants::HASH2,
36+
hash_pro: Constants::HASH2,
3737
);
3838
self::assertEquals($verify->get_status(), Status::SUPPORTER_EDITION);
3939

4040
self::assertTrue($verify->check());
4141
self::assertTrue($verify->check(Status::FREE_EDITION));
4242
self::assertTrue($verify->check(Status::SUPPORTER_EDITION));
4343
self::assertFalse($verify->check(Status::PRO_EDITION));
44-
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
44+
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
4545
self::assertTrue($verify->is_supporter()); // User is recognised as supporter.
4646
self::assertFalse($verify->is_pro()); // User is not recognised as pro.
47-
self::assertFalse($verify->is_signature()); // User is not recognised as signature.
47+
self::assertFalse($verify->is_signature()); // User is not recognised as signature.
4848

4949
$this->assertThrows(fn () => $verify->authorize(Status::PRO_EDITION), SupporterOnlyOperationException::class, 'pro');
5050
}
5151

52-
public function testVerifyPro(): void
52+
public function testVerifyPro(): void
5353
{
5454
$verify = new Verify(
5555
license_key: Constants::HASH2_KEY,
5656
hash_supporter: Constants::HASH,
57-
hash_pro: Constants::HASH2,
57+
hash_pro: Constants::HASH2,
5858
);
5959
self::assertEquals($verify->get_status(), Status::PRO_EDITION);
6060

6161
self::assertTrue($verify->check());
6262
self::assertTrue($verify->check(Status::FREE_EDITION));
6363
self::assertTrue($verify->check(Status::SUPPORTER_EDITION));
6464
self::assertTrue($verify->check(Status::PRO_EDITION));
65-
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
65+
self::assertFalse($verify->check(Status::SIGNATURE_EDITION));
6666
self::assertTrue($verify->is_supporter()); // User is recognised as supporter.
6767
self::assertTrue($verify->is_pro()); // User is recognised as pro.
68-
self::assertFalse($verify->is_signature()); // User is not recognised as signature.
68+
self::assertFalse($verify->is_signature()); // User is not recognised as signature.
6969
}
7070

7171
public function testVerifySignature(): void
@@ -83,15 +83,15 @@ public function testVerifySignature(): void
8383
self::assertTrue($verify->check(Status::SIGNATURE_EDITION));
8484
self::assertTrue($verify->is_supporter()); // user is recognised as supporter.
8585
self::assertTrue($verify->is_pro()); // user is recognised as pro.
86-
self::assertTrue($verify->is_signature()); // User is not recognised as signature.
86+
self::assertTrue($verify->is_signature()); // User is not recognised as signature.
8787
}
8888

8989
public function testVerifyValidate(): void
9090
{
9191
$verify = new Verify();
9292

9393
// Check config before executing validation
94-
/** @var array<class-string,string> $checks */
94+
/** @var array<class-string,string> $checks */
9595
$checks = config('verify.validation');
9696
foreach ($checks as $class => $value) {
9797
$file = (new \ReflectionClass($class))->getFileName();

0 commit comments

Comments
 (0)