Skip to content

Commit 7891322

Browse files
author
Max Snow
committed
uncommited changes
1 parent 258a037 commit 7891322

File tree

4 files changed

+64
-70
lines changed

4 files changed

+64
-70
lines changed

phpunit.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="false"
7+
cacheDirectory=".phpunit.result.cache"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<coverage>
12+
<report>
13+
<clover outputFile="build/logs/clover.xml"/>
14+
<html outputDirectory="build/coverage"/>
15+
<text outputFile="build/coverage.txt"/>
16+
</report>
17+
</coverage>
18+
<testsuites>
19+
<testsuite name="jwt-auth Test Suite">
20+
<directory>tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
<logging>
24+
<junit outputFile="build/report.junit.xml"/>
25+
</logging>
26+
<source>
27+
<include>
28+
<directory suffix=".php">src/</directory>
29+
</include>
30+
<exclude>
31+
<file>src/Providers/LumenServiceProvider.php</file>
32+
<directory suffix=".php">src/Facades/</directory>
33+
<directory suffix=".php">src/Console/</directory>
34+
</exclude>
35+
</source>
36+
</phpunit>

src/Claims/Claim.php

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,30 @@ abstract class Claim implements Arrayable, ClaimContract, Jsonable, \JsonSeriali
2121
{
2222
/**
2323
* The claim name.
24-
*
25-
* @var string
2624
*/
27-
protected $name;
25+
protected string $name;
2826

2927
/**
3028
* The claim value.
3129
*/
32-
private $value;
30+
private mixed $value;
3331

3432
/**
3533
* @return void
3634
*
3735
* @throws InvalidClaimException
3836
*/
39-
public function __construct($value)
37+
public function __construct(mixed $value)
4038
{
4139
$this->setValue($value);
4240
}
4341

4442
/**
4543
* Set the claim value, and call a validate method.
4644
*
47-
* @return $this
48-
*
4945
* @throws InvalidClaimException
5046
*/
51-
public function setValue($value)
47+
public function setValue(mixed $value): static
5248
{
5349
$this->value = $this->validateCreate($value);
5450

@@ -58,7 +54,7 @@ public function setValue($value)
5854
/**
5955
* Get the claim value.
6056
*/
61-
public function getValue()
57+
public function getValue(): mixed
6258
{
6359
return $this->value;
6460
}
@@ -70,7 +66,7 @@ public function getValue()
7066
*
7167
* @return $this
7268
*/
73-
public function setName($name)
69+
public function setName(string $name): static
7470
{
7571
$this->name = $name;
7672

@@ -82,17 +78,15 @@ public function setName($name)
8278
*
8379
* @return string
8480
*/
85-
public function getName()
81+
public function getName(): string
8682
{
8783
return $this->name;
8884
}
8985

9086
/**
9187
* Validate the claim in a standalone Claim context.
92-
*
93-
* @return bool
9488
*/
95-
public function validateCreate($value)
89+
public function validateCreate(mixed $value): mixed
9690
{
9791
return $value;
9892
}
@@ -102,42 +96,33 @@ public function validateCreate($value)
10296
*
10397
* @return bool
10498
*/
105-
public function validatePayload()
99+
public function validatePayload(): mixed
106100
{
107101
return $this->getValue();
108102
}
109103

110104
/**
111105
* Validate the Claim within a refresh context.
112-
*
113-
* @param int $refreshTTL
114-
*
115-
* @return bool
116106
*/
117-
public function validateRefresh($refreshTTL)
107+
public function validateRefresh(int $refreshTTL): bool
118108
{
119109
return $this->getValue();
120110
}
121111

122112
/**
123113
* Checks if the value matches the claim.
124-
*
125-
* @param bool $strict
126-
*
127-
* @return bool
128114
*/
129-
public function matches($value, $strict = true)
115+
public function matches(mixed $value, bool $strict = true): bool
130116
{
131117
return $strict ? $this->value === $value : $this->value == $value;
132118
}
133119

134120
/**
135121
* Convert the object into something JSON serializable.
136-
*
137-
* @return array
138122
*/
123+
// @todo: what the hell is this attribute
139124
#[\ReturnTypeWillChange]
140-
public function jsonSerialize()
125+
public function jsonSerialize(): array
141126
{
142127
return $this->toArray();
143128
}
@@ -147,7 +132,7 @@ public function jsonSerialize()
147132
*
148133
* @return array
149134
*/
150-
public function toArray()
135+
public function toArray(): array
151136
{
152137
return [$this->getName() => $this->getValue()];
153138
}
@@ -156,20 +141,16 @@ public function toArray()
156141
* Get the claim as JSON.
157142
*
158143
* @param int $options
159-
*
160-
* @return string
161144
*/
162-
public function toJson($options = JSON_UNESCAPED_SLASHES)
145+
public function toJson($options = JSON_UNESCAPED_SLASHES): string
163146
{
164147
return json_encode($this->toArray(), $options);
165148
}
166149

167150
/**
168151
* Get the payload as a string.
169-
*
170-
* @return string
171152
*/
172-
public function __toString()
153+
public function __toString(): string
173154
{
174155
return $this->toJson();
175156
}

src/Contracts/Providers/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface Storage
2020
*
2121
* @return void
2222
*/
23-
public function add($key, $value, $minutes);
23+
public function add(string $key, $value, int $minutes);
2424

2525
/**
2626
* @param string $key

src/Providers/JWT/Provider.php

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ abstract class Provider
3636
/**
3737
* Constructor.
3838
*
39-
* @param string $secret
40-
* @param string $algo
41-
*
42-
* @return void
39+
* @throws SecretMissingException
4340
*/
44-
public function __construct($secret, $algo, array $keys)
41+
public function __construct(?string $secret, string $algo, array $keys)
4542
{
46-
if (is_null($secret) && (is_null($keys['public']) || is_null($keys['private']))) {
43+
if (is_null($secret) && (empty($keys['public']) || empty($keys['private']))) {
4744
throw new SecretMissingException();
4845
}
4946

@@ -54,12 +51,8 @@ public function __construct($secret, $algo, array $keys)
5451

5552
/**
5653
* Set the algorithm used to sign the token.
57-
*
58-
* @param string $algo
59-
*
60-
* @return $this
6154
*/
62-
public function setAlgo($algo)
55+
public function setAlgo(string $algo): self
6356
{
6457
$this->algo = $algo;
6558

@@ -68,22 +61,16 @@ public function setAlgo($algo)
6861

6962
/**
7063
* Get the algorithm used to sign the token.
71-
*
72-
* @return string
7364
*/
74-
public function getAlgo()
65+
public function getAlgo(): string
7566
{
7667
return $this->algo;
7768
}
7869

7970
/**
8071
* Set the secret used to sign the token.
81-
*
82-
* @param string $secret
83-
*
84-
* @return $this
8572
*/
86-
public function setSecret($secret)
73+
public function setSecret(string $secret): self
8774
{
8875
$this->secret = $secret;
8976

@@ -92,20 +79,16 @@ public function setSecret($secret)
9279

9380
/**
9481
* Get the secret used to sign the token.
95-
*
96-
* @return string
9782
*/
98-
public function getSecret()
83+
public function getSecret(): string
9984
{
10085
return $this->secret;
10186
}
10287

10388
/**
10489
* Set the keys used to sign the token.
105-
*
106-
* @return $this
10790
*/
108-
public function setKeys(array $keys)
91+
public function setKeys(array $keys): self
10992
{
11093
$this->keys = $keys;
11194

@@ -115,10 +98,8 @@ public function setKeys(array $keys)
11598
/**
11699
* Get the array of keys used to sign tokens
117100
* with an asymmetric algorithm.
118-
*
119-
* @return array
120101
*/
121-
public function getKeys()
102+
public function getKeys(): array
122103
{
123104
return $this->keys;
124105
}
@@ -148,10 +129,8 @@ public function getPrivateKey()
148129
/**
149130
* Get the passphrase used to sign tokens
150131
* with an asymmetric algorithm.
151-
*
152-
* @return string
153132
*/
154-
public function getPassphrase()
133+
public function getPassphrase(): string
155134
{
156135
return Arr::get($this->keys, 'passphrase');
157136
}
@@ -180,9 +159,7 @@ protected function getVerificationKey()
180159
* Determine if the algorithm is asymmetric, and thus
181160
* requires a public/private key combo.
182161
*
183-
* @return bool
184-
*
185162
* @throws JWTException
186163
*/
187-
abstract protected function isAsymmetric();
164+
abstract protected function isAsymmetric(): bool;
188165
}

0 commit comments

Comments
 (0)