diff --git a/README.md b/README.md index 4a57d16..332de58 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ This is best placed in an application startup file. ```php use HttpSignatures\Context; -$context = new Context(array( - 'keys' => array('examplekey' => 'secret-key-here'), +$context = new Context([ + 'keys' => ['examplekey' => 'secret-key-here'], 'algorithm' => 'hmac-sha256', - 'headers' => array('(request-target)', 'Date', 'Accept'), -)); + 'headers' => ['(request-target)', 'Date', 'Accept'], +]); ``` If there's only one key in the `keys` hash, that will be used for signing. diff --git a/src/Algorithm.php b/src/Algorithm.php index 5c70a24..b35d768 100644 --- a/src/Algorithm.php +++ b/src/Algorithm.php @@ -2,13 +2,8 @@ namespace HttpSignatures; -class Algorithm +abstract class Algorithm { - private function __construct() - { - // static class. - } - /** * @param string $name * diff --git a/tests/ContextTest.php b/tests/ContextTest.php index 652b190..93cdda2 100644 --- a/tests/ContextTest.php +++ b/tests/ContextTest.php @@ -1,6 +1,6 @@ context = new Context(array( - 'keys' => array('pda' => 'secret'), + $this->context = new Context([ + 'keys' => ['pda' => 'secret'], 'algorithm' => 'hmac-sha256', - 'headers' => array('(request-target)', 'date'), - )); + 'headers' => ['(request-target)', 'date'], + ]); } public function testSigner() @@ -23,12 +23,12 @@ public function testSigner() $message = new Request('GET', '/path?query=123', ['date' => 'today', 'accept' => 'llamas']); $message = $this->context->signer()->sign($message); - $expectedString = implode(',', array( + $expectedString = implode(',', [ 'keyId="pda"', 'algorithm="hmac-sha256"', 'headers="(request-target) date"', 'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="', - )); + ]); $this->assertEquals( $expectedString, diff --git a/tests/HeaderListTest.php b/tests/HeaderListTest.php index 0b8a2d3..784cf2f 100644 --- a/tests/HeaderListTest.php +++ b/tests/HeaderListTest.php @@ -1,6 +1,6 @@ assertEquals('(request-target) date', $hl->string()); } diff --git a/tests/KeyStoreTest.php b/tests/KeyStoreTest.php index e77fda4..3f3b230 100644 --- a/tests/KeyStoreTest.php +++ b/tests/KeyStoreTest.php @@ -1,6 +1,6 @@ 'secret')); + $ks = new KeyStore(['id' => 'secret']); $key = $ks->fetch('id'); $this->assertEquals('id', $key->id); $this->assertEquals('secret', $key->secret); @@ -19,7 +19,7 @@ public function testFetchSuccess() */ public function testFetchFail() { - $ks = new KeyStore(array('id' => 'secret')); + $ks = new KeyStore(['id' => 'secret']); $key = $ks->fetch('nope'); } } diff --git a/tests/SignatureParametersParserTest.php b/tests/SignatureParametersParserTest.php index 6de7fad..99d9a77 100644 --- a/tests/SignatureParametersParserTest.php +++ b/tests/SignatureParametersParserTest.php @@ -1,6 +1,6 @@ assertEquals( - array( + [ 'keyId' => 'example', 'algorithm' => 'hmac-sha1', 'headers' => '(request-target) date', 'signature' => 'b64', - ), + ], $parser->parse() ); } diff --git a/tests/SignatureParametersTest.php b/tests/SignatureParametersTest.php index 2858392..f1cb693 100644 --- a/tests/SignatureParametersTest.php +++ b/tests/SignatureParametersTest.php @@ -1,9 +1,9 @@ getMockBuilder('HttpSignatures\Signature') ->disableOriginalConstructor() diff --git a/tests/SigningStringTest.php b/tests/SigningStringTest.php index ea297ee..0cd2fdb 100644 --- a/tests/SigningStringTest.php +++ b/tests/SigningStringTest.php @@ -1,19 +1,18 @@ message('/path')); $this->assertEquals( @@ -24,7 +23,7 @@ public function testWithoutQueryString() public function testSigningStringWithOrderedQueryParameters() { - $headerList = new HeaderList(array('(request-target)', 'date')); + $headerList = new HeaderList(['(request-target)', 'date']); $ss = new SigningString($headerList, $this->message('/path?a=antelope&z=zebra')); $this->assertEquals( @@ -35,7 +34,7 @@ public function testSigningStringWithOrderedQueryParameters() public function testSigningStringWithUnorderedQueryParameters() { - $headerList = new HeaderList(array('(request-target)', 'date')); + $headerList = new HeaderList(['(request-target)', 'date']); $ss = new SigningString($headerList, $this->message('/path?z=zebra&a=antelope')); $this->assertEquals( @@ -46,7 +45,7 @@ public function testSigningStringWithUnorderedQueryParameters() public function testSigningStringWithOrderedQueryParametersSymfonyRequest() { - $headerList = new HeaderList(array('(request-target)', 'date')); + $headerList = new HeaderList(['(request-target)', 'date']); $ss = new SigningString($headerList, $this->symfonyMessage('/path?a=antelope&z=zebra')); $this->assertEquals( @@ -57,7 +56,7 @@ public function testSigningStringWithOrderedQueryParametersSymfonyRequest() public function testSigningStringWithUnorderedQueryParametersSymfonyRequest() { - $headerList = new HeaderList(array('(request-target)', 'date')); + $headerList = new HeaderList(['(request-target)', 'date']); $ss = new SigningString($headerList, $this->symfonyMessage('/path?z=zebra&a=antelope')); $this->assertEquals( @@ -71,7 +70,7 @@ public function testSigningStringWithUnorderedQueryParametersSymfonyRequest() */ public function testSigningStringErrorForMissingHeader() { - $headerList = new HeaderList(array('nope')); + $headerList = new HeaderList(['nope']); $ss = new SigningString($headerList, $this->message('/')); $ss->string(); } @@ -84,7 +83,7 @@ private function message($path) private function symfonyMessage($path) { $symfonyRequest = SymfonyRequest::create($path, 'GET'); - $symfonyRequest->headers->replace(array('date' => 'Mon, 28 Jul 2014 15:39:13 -0700')); + $symfonyRequest->headers->replace(['date' => 'Mon, 28 Jul 2014 15:39:13 -0700']); $psr7Factory = new HttpMessageFactory(); $psrRequest = $psr7Factory->createRequest($symfonyRequest); diff --git a/tests/VerifierTest.php b/tests/VerifierTest.php index 5d40e0b..b33c27c 100644 --- a/tests/VerifierTest.php +++ b/tests/VerifierTest.php @@ -1,6 +1,6 @@ "secret")); + $keyStore = new KeyStore(["pda" => "secret"]); $this->verifier = new Verifier($keyStore); } @@ -103,7 +103,7 @@ public function testRejectMessageWithPartialSignatureHeader() public function testRejectsMessageWithUnknownKeyId() { - $keyStore = new KeyStore(array("nope" => "secret")); + $keyStore = new KeyStore(["nope" => "secret"]); $verifier = new Verifier($keyStore); $this->assertFalse($verifier->isValid($this->message)); }