Skip to content

Commit

Permalink
Bugs fixed
Browse files Browse the repository at this point in the history
Fix #257
Fix #258
Global imports
  • Loading branch information
Spomky committed May 29, 2020
1 parent 206ee91 commit 9aa087d
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 52 deletions.
5 changes: 3 additions & 2 deletions AbstractBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -14,6 +14,7 @@
namespace Jose\Easy;

use InvalidArgumentException;
use function is_string;
use Jose\Component\Core\Algorithm as JoseAlgorithm;
use Jose\Component\Signature\Algorithm;

Expand Down Expand Up @@ -101,7 +102,7 @@ public function alg($alg): self
$clone->jwt->header->set('alg', $alg->name());

break;
case \is_string($alg):
case is_string($alg):
$clone->jwt->header->set('alg', $alg);

break;
Expand Down
27 changes: 16 additions & 11 deletions AbstractLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Easy;

use function in_array;
use InvalidArgumentException;
use function is_array;
use function is_callable;
use function is_int;
use function is_string;
use Jose\Component\Checker;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\JWK;
Expand Down Expand Up @@ -113,12 +118,12 @@ public function claim(string $key, $checker, bool $inHeader = false): self
switch (true) {
case $checker instanceof Checker\ClaimChecker:
break;
case \is_callable($checker):
case is_callable($checker):
$checker = new CallableChecker($key, $checker);

break;
case \is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return \in_array($value, $checker, true); });
case is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return in_array($value, $checker, true); });

break;
default:
Expand Down Expand Up @@ -146,7 +151,7 @@ public function exp($leeway = 0, bool $inHeader = false): self

return $clone;
}
if (!\is_int($leeway) or $leeway < 0) {
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "exp" claim is invalid. Set false to disable or a positive integer.');
}

Expand All @@ -166,7 +171,7 @@ public function nbf($leeway = 0, bool $inHeader = false): self

return $clone;
}
if (!\is_int($leeway) or $leeway < 0) {
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "nbf" claim is invalid. Set false to disable or a positive integer.');
}

Expand All @@ -186,7 +191,7 @@ public function iat($leeway = 0, bool $inHeader = false): self

return $clone;
}
if (!\is_int($leeway) or $leeway < 0) {
if (!is_int($leeway) or $leeway < 0) {
throw new InvalidArgumentException('First parameter for "iat" claim is invalid. Set false to disable or a positive integer.');
}

Expand All @@ -202,7 +207,7 @@ public function alg($alg): self
{
$clone = clone $this;
switch (true) {
case \is_string($alg):
case is_string($alg):
$clone->allowedAlgorithms[] = $alg;

return $clone;
Expand Down Expand Up @@ -244,12 +249,12 @@ public function header(string $key, $checker): self
switch (true) {
case $checker instanceof Checker\HeaderChecker:
break;
case \is_callable($checker):
case is_callable($checker):
$checker = new CallableChecker($key, $checker);

break;
case \is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return \in_array($value, $checker, true); });
case is_array($checker):
$checker = new CallableChecker($key, static function ($value) use ($checker) {return in_array($value, $checker, true); });

break;
default:
Expand Down
5 changes: 3 additions & 2 deletions AlgorithmProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -14,6 +14,7 @@
namespace Jose\Easy;

use Jose\Component\Core\Algorithm;
use Throwable;

final class AlgorithmProvider
{
Expand Down Expand Up @@ -50,7 +51,7 @@ private function addClass(string $algorithmClass): void
if (class_exists($algorithmClass)) {
try {
$this->algorithms[] = new $algorithmClass();
} catch (\Throwable $throwable) {
} catch (Throwable $throwable) {
//does nothing
}
}
Expand Down
2 changes: 1 addition & 1 deletion Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down
2 changes: 1 addition & 1 deletion CallableChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down
8 changes: 5 additions & 3 deletions ContentEncryptionAlgorithmChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Easy;

use function in_array;
use function is_string;
use Jose\Component\Checker\HeaderChecker;
use Jose\Component\Checker\InvalidHeaderException;

Expand Down Expand Up @@ -50,10 +52,10 @@ public function __construct(array $supportedAlgorithms, bool $protectedHeader =
*/
public function checkHeader($value): void
{
if (!\is_string($value)) {
if (!is_string($value)) {
throw new InvalidHeaderException('"enc" must be a string.', self::HEADER_NAME, $value);
}
if (!\in_array($value, $this->supportedAlgorithms, true)) {
if (!in_array($value, $this->supportedAlgorithms, true)) {
throw new InvalidHeaderException('Unsupported algorithm.', self::HEADER_NAME, $value);
}
}
Expand Down
10 changes: 6 additions & 4 deletions Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Easy;

use function count;
use InvalidArgumentException;
use function is_string;
use Jose\Component\Checker;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\AlgorithmManager;
Expand Down Expand Up @@ -60,7 +62,7 @@ public function enc($enc): self
{
$clone = clone $this;
switch (true) {
case \is_string($enc):
case is_string($enc):
$clone->allowedContentEncryptionAlgorithms[] = $enc;

return $clone;
Expand Down Expand Up @@ -89,10 +91,10 @@ public function encs($encs): self

public function run(): JWT
{
if (0 !== \count($this->allowedAlgorithms)) {
if (0 !== count($this->allowedAlgorithms)) {
$this->headerCheckers[] = new Checker\AlgorithmChecker($this->allowedAlgorithms, true);
}
if (0 !== \count($this->allowedContentEncryptionAlgorithms)) {
if (0 !== count($this->allowedContentEncryptionAlgorithms)) {
$this->headerCheckers[] = new ContentEncryptionAlgorithmChecker($this->allowedContentEncryptionAlgorithms, true);
}
$jwe = (new CompactSerializer())->unserialize($this->token);
Expand Down
7 changes: 4 additions & 3 deletions JWEBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -14,6 +14,7 @@
namespace Jose\Easy;

use InvalidArgumentException;
use function is_string;
use Jose\Component\Core\Algorithm;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\JWK;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function enc($enc): self
$clone->jwt->header->set('enc', $enc->name());

break;
case \is_string($enc):
case is_string($enc):
$clone->jwt->header->set('enc', $enc);

break;
Expand All @@ -80,7 +81,7 @@ public function zip($zip): self
$clone->jwt->header->set('zip', $zip->name());

break;
case \is_string($zip):
case is_string($zip):
$clone->jwt->header->set('zip', $zip);

break;
Expand Down
2 changes: 1 addition & 1 deletion JWSBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down
2 changes: 1 addition & 1 deletion JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down
2 changes: 1 addition & 1 deletion Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down
17 changes: 10 additions & 7 deletions ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Easy;

use function array_key_exists;
use ArrayIterator;
use function call_user_func_array;
use function count;
use Countable;
use InvalidArgumentException;
use IteratorAggregate;
Expand All @@ -31,15 +34,15 @@ class ParameterBag implements IteratorAggregate, Countable
public function __call(string $name, array $arguments)
{
if (method_exists($this, $name)) {
return \call_user_func_array([$this, $name], $arguments);
return call_user_func_array([$this, $name], $arguments);
}

if (0 === \count($arguments)) {
if (0 === count($arguments)) {
return $this->get($name);
}
array_unshift($arguments, $name);

return \call_user_func_array([$this, 'set'], $arguments);
return call_user_func_array([$this, 'set'], $arguments);
}

public function all(): array
Expand Down Expand Up @@ -76,7 +79,7 @@ public function add(array $parameters): void
*/
public function get(string $key)
{
if (!\array_key_exists($key, $this->parameters)) {
if (!array_key_exists($key, $this->parameters)) {
throw new InvalidArgumentException(sprintf('Parameter "%s" is missing', $key));
}

Expand All @@ -93,7 +96,7 @@ public function set(string $key, $value): void

public function has(string $key): bool
{
return \array_key_exists($key, $this->parameters);
return array_key_exists($key, $this->parameters);
}

public function remove(string $key): void
Expand All @@ -108,6 +111,6 @@ public function getIterator(): ArrayIterator

public function count(): int
{
return \count($this->parameters);
return count($this->parameters);
}
}
Loading

0 comments on commit 9aa087d

Please sign in to comment.