Permalink
Browse files

Use lcobucci/coding-standard

  • Loading branch information...
lcobucci committed Oct 14, 2018
1 parent 2f4fcdb commit f8dffb86fb294a465b0ea40e3d83b3526c3c90b3
Showing with 228 additions and 263 deletions.
  1. +1 −1 composer.json
  2. +1 −20 phpcs.xml.dist
  3. +2 −1 src/Builder.php
  4. +3 −1 src/Exception.php
  5. +1 −1 src/Signer/Key.php
  6. +2 −1 src/Token/Builder.php
  7. +1 −1 src/Validation/Constraint.php
  8. +2 −2 src/Validation/Constraint/IdentifiedBy.php
  9. +2 −2 src/Validation/Constraint/IssuedBy.php
  10. +2 −2 src/Validation/Constraint/PermittedFor.php
  11. +2 −2 src/Validation/Constraint/RelatedTo.php
  12. +4 −4 src/Validation/Constraint/SignedWith.php
  13. +7 −7 src/Validation/Constraint/ValidAt.php
  14. +1 −1 src/Validation/{ConstraintViolationException.php → ConstraintViolation.php}
  15. +6 −6 src/Validation/{InvalidTokenException.php → InvalidToken.php}
  16. +4 −4 src/Validation/Validator.php
  17. +2 −2 src/Validator.php
  18. +6 −11 test/functional/EcdsaTokenTest.php
  19. +4 −8 test/functional/HmacTokenTest.php
  20. +5 −10 test/functional/RsaTokenTest.php
  21. +7 −11 test/functional/UnsignedTokenTest.php
  22. +6 −6 test/unit/Signer/Ecdsa/Sha256Test.php
  23. +6 −6 test/unit/Signer/Ecdsa/Sha384Test.php
  24. +6 −6 test/unit/Signer/Ecdsa/Sha512Test.php
  25. +6 −6 test/unit/Signer/EcdsaTest.php
  26. +6 −8 test/unit/Signer/HmacTest.php
  27. +4 −4 test/unit/Signer/KeyTest.php
  28. +45 −45 test/unit/Token/BuilderTest.php
  29. +41 −41 test/unit/Token/ParserTest.php
  30. +14 −14 test/unit/Token/PlainTest.php
  31. +2 −2 test/unit/Validation/Constraint/IdentifiedByTest.php
  32. +3 −3 test/unit/Validation/Constraint/IssuedByTest.php
  33. +3 −3 test/unit/Validation/Constraint/PermittedForTest.php
  34. +2 −2 test/unit/Validation/Constraint/RelatedToTest.php
  35. +3 −3 test/unit/Validation/Constraint/SignedWithTest.php
  36. +3 −3 test/unit/Validation/Constraint/ValidAtTest.php
  37. +9 −9 test/unit/Validation/InvalidTokenExceptionTest.php
  38. +4 −4 test/unit/Validation/ValidatorTest.php
View
@@ -26,8 +26,8 @@
"lcobucci/jose-parsing": "~2.1"
},
"require-dev": {
"doctrine/coding-standard": "^4.0",
"infection/infection": "^0.10",
"lcobucci/coding-standard": "^2.0",
"mikey179/vfsStream": "^1.6",
"phpbench/phpbench": "dev-master@dev",
"phpmd/phpmd": "^2.5",
View
@@ -10,25 +10,6 @@
<file>src</file>
<file>test</file>
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment.MultiLinePropertyComment" />
<!-- temporarily disabling this one -->
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
<property name="newlinesCountAfterDeclare" value="2"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>
<rule ref="Lcobucci" />
</ruleset>
View
@@ -4,6 +4,7 @@
namespace Lcobucci\JWT;
use DateTimeImmutable;
use InvalidArgumentException;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Token\Plain;
@@ -56,7 +57,7 @@ public function withHeader(string $name, $value): Builder;
*
* @param mixed $value
*
* @throws \InvalidArgumentException When trying to set a registered claim.
* @throws InvalidArgumentException When trying to set a registered claim.
*/
public function withClaim(string $name, $value): Builder;
View
@@ -3,6 +3,8 @@
namespace Lcobucci\JWT;
abstract class Exception extends \RuntimeException
use RuntimeException;
abstract class Exception extends RuntimeException
{
}
View
@@ -42,7 +42,7 @@ private function setContent(string $content): void
}
/**
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
private function readFile(string $content): string
{
View
@@ -4,6 +4,7 @@
namespace Lcobucci\JWT\Token;
use DateTimeImmutable;
use InvalidArgumentException;
use Lcobucci\Jose\Parsing;
use Lcobucci\JWT\Builder as BuilderInterface;
use Lcobucci\JWT\Signer;
@@ -112,7 +113,7 @@ public function withHeader(string $name, $value): BuilderInterface
public function withClaim(string $name, $value): BuilderInterface
{
if (in_array($name, RegisteredClaims::ALL, true)) {
throw new \InvalidArgumentException('You should use the correct methods to set registered claims');
throw new InvalidArgumentException('You should use the correct methods to set registered claims');
}
return $this->setClaim($name, $value);
@@ -8,7 +8,7 @@
interface Constraint
{
/**
* @throws ConstraintViolationException
* @throws ConstraintViolation
*/
public function assert(Token $token): void;
}
@@ -5,7 +5,7 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class IdentifiedBy implements Constraint
{
@@ -25,7 +25,7 @@ public function __construct(string $id)
public function assert(Token $token): void
{
if (! $token->isIdentifiedBy($this->id)) {
throw new ConstraintViolationException(
throw new ConstraintViolation(
'The token is not identified with the expected ID'
);
}
@@ -5,7 +5,7 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class IssuedBy implements Constraint
{
@@ -25,7 +25,7 @@ public function __construct(string ...$issuers)
public function assert(Token $token): void
{
if (! $token->hasBeenIssuedBy(...$this->issuers)) {
throw new ConstraintViolationException(
throw new ConstraintViolation(
'The token was not issued by the given issuers'
);
}
@@ -5,7 +5,7 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class PermittedFor implements Constraint
{
@@ -25,7 +25,7 @@ public function __construct(string $audience)
public function assert(Token $token): void
{
if (! $token->isPermittedFor($this->audience)) {
throw new ConstraintViolationException(
throw new ConstraintViolation(
'The token is not allowed to be used by this audience'
);
}
@@ -5,7 +5,7 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class RelatedTo implements Constraint
{
@@ -25,7 +25,7 @@ public function __construct(string $subject)
public function assert(Token $token): void
{
if (! $token->isRelatedTo($this->subject)) {
throw new ConstraintViolationException(
throw new ConstraintViolation(
'The token is not related to the expected subject'
);
}
@@ -6,7 +6,7 @@
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class SignedWith implements Constraint
{
@@ -32,15 +32,15 @@ public function __construct(Signer $signer, Signer\Key $key)
public function assert(Token $token): void
{
if (! $token instanceof Token\Plain) {
throw new ConstraintViolationException('You should pass a plain token');
throw new ConstraintViolation('You should pass a plain token');
}
if ($token->headers()->get('alg') !== $this->signer->getAlgorithmId()) {
throw new ConstraintViolationException('Token signer mismatch');
throw new ConstraintViolation('Token signer mismatch');
}
if (! $this->signer->verify($token->signature()->hash(), $token->payload(), $this->key)) {
throw new ConstraintViolationException('Token signature mismatch');
throw new ConstraintViolation('Token signature mismatch');
}
}
}
@@ -7,7 +7,7 @@
use Lcobucci\Clock\Clock;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolationException;
use Lcobucci\JWT\Validation\ConstraintViolation;
final class ValidAt implements Constraint
{
@@ -34,32 +34,32 @@ public function assert(Token $token): void
}
/**
* @throws ConstraintViolationException
* @throws ConstraintViolation
*/
private function assertExpiration(Token $token, DateTimeInterface $now): void
{
if ($token->isExpired($now)) {
throw new ConstraintViolationException('The token is expired');
throw new ConstraintViolation('The token is expired');
}
}
/**
* @throws ConstraintViolationException
* @throws ConstraintViolation
*/
private function assertMinimumTime(Token $token, DateTimeInterface $now): void
{
if (! $token->isMinimumTimeBefore($now)) {
throw new ConstraintViolationException('The token cannot be used yet');
throw new ConstraintViolation('The token cannot be used yet');
}
}
/**
* @throws ConstraintViolationException
* @throws ConstraintViolation
*/
private function assertIssueTime(Token $token, DateTimeInterface $now): void
{
if (! $token->hasBeenIssuedBefore($now)) {
throw new ConstraintViolationException('The token was issued in the future');
throw new ConstraintViolation('The token was issued in the future');
}
}
}
@@ -5,6 +5,6 @@
use Lcobucci\JWT\Exception;
final class ConstraintViolationException extends Exception
final class ConstraintViolation extends Exception
{
}
@@ -7,14 +7,14 @@
use function array_map;
use function implode;
final class InvalidTokenException extends Exception
final class InvalidToken extends Exception
{
/**
* @var ConstraintViolationException[]
* @var ConstraintViolation[]
*/
private $violations = [];
public static function fromViolations(ConstraintViolationException ...$violations): self
public static function fromViolations(ConstraintViolation ...$violations): self
{
$exception = new self(self::buildMessage($violations));
$exception->violations = $violations;
@@ -23,12 +23,12 @@ public static function fromViolations(ConstraintViolationException ...$violation
}
/**
* @param ConstraintViolationException[] $violations
* @param ConstraintViolation[] $violations
*/
private static function buildMessage(array $violations): string
{
$violations = array_map(
function (ConstraintViolationException $violation): string {
static function (ConstraintViolation $violation): string {
return '- ' . $violation->getMessage();
},
$violations
@@ -41,7 +41,7 @@ function (ConstraintViolationException $violation): string {
}
/**
* @return ConstraintViolationException[]
* @return ConstraintViolation[]
*/
public function violations(): array
{
@@ -19,12 +19,12 @@ public function assert(Token $token, Constraint ...$constraints): void
}
if ($violations) {
throw InvalidTokenException::fromViolations(...$violations);
throw InvalidToken::fromViolations(...$violations);
}
}
/**
* @param ConstraintViolationException[] $violations
* @param ConstraintViolation[] $violations
*/
private function checkConstraint(
Constraint $constraint,
@@ -33,7 +33,7 @@ private function checkConstraint(
): void {
try {
$constraint->assert($token);
} catch (ConstraintViolationException $e) {
} catch (ConstraintViolation $e) {
$violations[] = $e;
}
}
@@ -46,7 +46,7 @@ public function validate(Token $token, Constraint ...$constraints): bool
}
return true;
} catch (ConstraintViolationException $e) {
} catch (ConstraintViolation $e) {
return false;
}
}
View
@@ -4,12 +4,12 @@
namespace Lcobucci\JWT;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\InvalidTokenException;
use Lcobucci\JWT\Validation\InvalidToken;
interface Validator
{
/**
* @throws InvalidTokenException
* @throws InvalidToken
*/
public function assert(Token $token, Constraint ...$constraints): void;
Oops, something went wrong.

0 comments on commit f8dffb8

Please sign in to comment.