From cbc9491f75e7c36f9d847c4dd01cb02d07c20b45 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 12 Jan 2018 09:48:33 -0500 Subject: [PATCH] CS fixes and version bump --- lib/Arsse.php | 2 +- lib/Misc/Date.php | 2 +- lib/REST.php | 9 ++++----- lib/REST/Target.php | 8 ++++---- tests/cases/Lang/TestBasic.php | 1 - tests/cases/Misc/TestDate.php | 8 ++++---- tests/cases/REST/NextCloudNews/TestV1_2.php | 2 +- tests/cases/REST/TestREST.php | 14 +++++++------- tests/cases/REST/TestTarget.php | 2 +- tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php | 2 +- tests/lib/PDOTest.php | 4 ++-- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/Arsse.php b/lib/Arsse.php index 528cb80..26fd7f5 100644 --- a/lib/Arsse.php +++ b/lib/Arsse.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse; class Arsse { - const VERSION = "0.2.1"; + const VERSION = "0.3.0"; /** @var Lang */ public static $lang; diff --git a/lib/Misc/Date.php b/lib/Misc/Date.php index 0eacf8c..bf5e7a3 100644 --- a/lib/Misc/Date.php +++ b/lib/Misc/Date.php @@ -13,7 +13,7 @@ class Date { return null; } $out = ValueInfo::normalize($date, ValueInfo::T_STRING, null, $outFormat); - if($outFormat=="unix") { + if ($outFormat=="unix") { $out = (int) $out; } elseif ($outFormat=="float") { $out = (float) $out; diff --git a/lib/REST.php b/lib/REST.php index 3820308..340707a 100644 --- a/lib/REST.php +++ b/lib/REST.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace JKingWeb\Arsse; - use JKingWeb\Arsse\Arsse; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ServerRequestInterface; @@ -67,9 +66,9 @@ class REST { public function dispatch(ServerRequestInterface $req = null): ResponseInterface { // create a request object if not provided $req = $req ?? ServerRequestFactory::fromGlobals(); - // find the API to handle + // find the API to handle try { - list ($api, $target, $class) = $this->apiMatch($req->getRequestTarget(), $this->apis); + list($api, $target, $class) = $this->apiMatch($req->getRequestTarget(), $this->apis); // authenticate the request pre-emptively $req = $this->authenticateRequest($req); // modify the request to have an uppercase method and a stripped target @@ -119,7 +118,7 @@ class REST { return [$id, $target, $api['class']]; } } - // or throw an exception otherwise + // or throw an exception otherwise throw new REST\Exception501(); } @@ -197,7 +196,7 @@ class REST { if ($req->hasHeader("Access-Control-Request-Headers")) { $res = $res->withHeader("Access-Control-Allow-Headers", $req->getHeaderLine("Access-Control-Request-Headers")); } - $res = $res->withHeader("Access-Control-Max-Age", (string) (60 *60 *24) ); // one day + $res = $res->withHeader("Access-Control-Max-Age", (string) (60 *60 *24)); // one day } $res = $res->withHeader("Access-Control-Allow-Origin", $req->getHeaderLine("Origin")); $res = $res->withHeader("Access-Control-Allow-Credentials", "true"); diff --git a/lib/REST/Target.php b/lib/REST/Target.php index bde4c6c..e04a0e2 100644 --- a/lib/REST/Target.php +++ b/lib/REST/Target.php @@ -62,7 +62,7 @@ class Target { protected function parseFragment(string $target): string { // store and strip off any fragment identifier and return the target without a fragment - $pos = strpos($target,"#"); + $pos = strpos($target, "#"); if ($pos !== false) { $this->fragment = rawurldecode(substr($target, $pos + 1)); $target = substr($target, 0, $pos); @@ -74,7 +74,7 @@ class Target { // store and strip off any query string and return the target without a query // note that the function assumes any fragment identifier has already been stripped off // unlike the other parts the query string is currently neither parsed nor normalized - $pos = strpos($target,"?"); + $pos = strpos($target, "?"); if ($pos !== false) { $this->query = substr($target, $pos + 1); $target = substr($target, 0, $pos); @@ -106,7 +106,7 @@ class Target { $target = explode("/", $target); $out = []; // resolve relative path segments and decode each retained segment - foreach($target as $index => $segment) { + foreach ($target as $index => $segment) { if ($segment==".") { // self-referential segments can be ignored continue; @@ -128,4 +128,4 @@ class Target { return []; } } -} \ No newline at end of file +} diff --git a/tests/cases/Lang/TestBasic.php b/tests/cases/Lang/TestBasic.php index fbd7129..351ede8 100644 --- a/tests/cases/Lang/TestBasic.php +++ b/tests/cases/Lang/TestBasic.php @@ -9,7 +9,6 @@ namespace JKingWeb\Arsse\TestCase\Lang; use JKingWeb\Arsse\Lang as TestClass; use org\bovigo\vfs\vfsStream; - /** @covers \JKingWeb\Arsse\Lang */ class TestBasic extends \JKingWeb\Arsse\Test\AbstractTest { use \JKingWeb\Arsse\Test\Lang\Setup; diff --git a/tests/cases/Misc/TestDate.php b/tests/cases/Misc/TestDate.php index 4aaf0b2..e82f6c8 100644 --- a/tests/cases/Misc/TestDate.php +++ b/tests/cases/Misc/TestDate.php @@ -14,7 +14,7 @@ class TestDate extends \JKingWeb\Arsse\Test\AbstractTest { $this->clearData(); } - function testNormalizeADate() { + public function testNormalizeADate() { $exp = new \DateTimeImmutable("2018-01-01T00:00:00Z"); $this->assertEquals($exp, Date::normalize(1514764800)); $this->assertEquals($exp, Date::normalize("2018-01-01T00:00:00")); @@ -26,7 +26,7 @@ class TestDate extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertNull(Date::normalize("2018-01-01T00:00:00Z", "http")); } - function testFormatADate() { + public function testFormatADate() { $test = new \DateTimeImmutable("2018-01-01T00:00:00Z"); $this->assertNull(Date::transform(null, "http")); $this->assertNull(Date::transform("ook", "http")); @@ -40,7 +40,7 @@ class TestDate extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertSame(1514764800.265579, Date::transform("2018-01-01T00:00:00.265579Z", "float", "iso8601m")); } - function testMoveDateForward() { + public function testMoveDateForward() { $test = new \DateTimeImmutable("2018-01-01T00:00:00Z"); $this->assertNull(Date::add("P1D", null)); $this->assertNull(Date::add("P1D", "ook")); @@ -49,7 +49,7 @@ class TestDate extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertNull(Date::add("ook", $test)); } - function testMoveDateBack() { + public function testMoveDateBack() { $test = new \DateTimeImmutable("2018-01-01T00:00:00Z"); $this->assertNull(Date::sub("P1D", null)); $this->assertNull(Date::sub("P1D", "ook")); diff --git a/tests/cases/REST/NextCloudNews/TestV1_2.php b/tests/cases/REST/NextCloudNews/TestV1_2.php index a1b8a82..ab4baad 100644 --- a/tests/cases/REST/NextCloudNews/TestV1_2.php +++ b/tests/cases/REST/NextCloudNews/TestV1_2.php @@ -317,7 +317,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest { if (Arsse::$user->auth()) { $req = $req->withAttribute("authenticated", true)->withAttribute("authenticatedUser", "john.doe@example.com"); } - foreach($headers as $key => $value) { + foreach ($headers as $key => $value) { if (!is_null($value)) { $req = $req->withHeader($key, $value); } else { diff --git a/tests/cases/REST/TestREST.php b/tests/cases/REST/TestREST.php index 6cb7d91..1f78524 100644 --- a/tests/cases/REST/TestREST.php +++ b/tests/cases/REST/TestREST.php @@ -264,7 +264,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { public function provideUnnormalizedResponses() { $stream = fopen("php://memory", "w+b"); - fwrite($stream,"ook"); + fwrite($stream, "ook"); return [ [new EmptyResponse(204), new EmptyResponse(204)], [new EmptyResponse(401), new EmptyResponse(401, ['WWW-Authenticate' => "Fake Value"])], @@ -322,13 +322,13 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { public function provideMockRequests() { return [ - [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "GET"), "GET", true, NCN::Class, "/feeds"], - [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "HEAD"), "GET", true, NCN::Class, "/feeds"], - [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "get"), "GET", true, NCN::Class, "/feeds"], - [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "head"), "GET", true, NCN::Class, "/feeds"], - [new ServerRequest([], [], "/tt-rss/api/", "POST"), "POST", true, TTRSS::Class, "/"], + [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "GET"), "GET", true, NCN::class, "/feeds"], + [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "HEAD"), "GET", true, NCN::class, "/feeds"], + [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "get"), "GET", true, NCN::class, "/feeds"], + [new ServerRequest([], [], "/index.php/apps/news/api/v1-2/feeds", "head"), "GET", true, NCN::class, "/feeds"], + [new ServerRequest([], [], "/tt-rss/api/", "POST"), "POST", true, TTRSS::class, "/"], [new ServerRequest([], [], "/no/such/api/", "HEAD"), "GET", false], [new ServerRequest([], [], "/no/such/api/", "GET"), "GET", false], ]; } -} \ No newline at end of file +} diff --git a/tests/cases/REST/TestTarget.php b/tests/cases/REST/TestTarget.php index 5577af8..6b5a383 100644 --- a/tests/cases/REST/TestTarget.php +++ b/tests/cases/REST/TestTarget.php @@ -63,4 +63,4 @@ class TestTarget extends \JKingWeb\Arsse\Test\AbstractTest { ["#%2e?%2f", [], true, true, "", ".?/", "#.%3F%2F"], ]; } -} \ No newline at end of file +} diff --git a/tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php b/tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php index 9c9e36f..4acaf6d 100644 --- a/tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php +++ b/tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php @@ -10,4 +10,4 @@ namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS\PDO; * @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Exception */ class TestAPI extends \JKingWeb\Arsse\TestCase\REST\TinyTinyRSS\TestAPI { use \JKingWeb\Arsse\Test\PDOTest; -} \ No newline at end of file +} diff --git a/tests/lib/PDOTest.php b/tests/lib/PDOTest.php index 3013734..0147e28 100644 --- a/tests/lib/PDOTest.php +++ b/tests/lib/PDOTest.php @@ -11,7 +11,7 @@ trait PDOTest { if (!is_array($value)) { return $value; } - foreach($value as $k => $v) { + foreach ($value as $k => $v) { if (is_array($v)) { $value[$k] = $this->v($v); } elseif (is_int($v) || is_float($v)) { @@ -20,4 +20,4 @@ trait PDOTest { } return $value; } -} \ No newline at end of file +}