Browse Source

CS fixes and version bump

microsub 0.3.0
J. King 6 years ago
parent
commit
cbc9491f75
  1. 2
      lib/Arsse.php
  2. 2
      lib/Misc/Date.php
  3. 9
      lib/REST.php
  4. 8
      lib/REST/Target.php
  5. 1
      tests/cases/Lang/TestBasic.php
  6. 8
      tests/cases/Misc/TestDate.php
  7. 2
      tests/cases/REST/NextCloudNews/TestV1_2.php
  8. 14
      tests/cases/REST/TestREST.php
  9. 2
      tests/cases/REST/TestTarget.php
  10. 2
      tests/cases/REST/TinyTinyRSS/PDO/TestAPI.php
  11. 4
      tests/lib/PDOTest.php

2
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;

2
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;

9
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");

8
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 [];
}
}
}
}

1
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;

8
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"));

2
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 {

14
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],
];
}
}
}

2
tests/cases/REST/TestTarget.php

@ -63,4 +63,4 @@ class TestTarget extends \JKingWeb\Arsse\Test\AbstractTest {
["#%2e?%2f", [], true, true, "", ".?/", "#.%3F%2F"],
];
}
}
}

2
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;
}
}

4
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;
}
}
}

Loading…
Cancel
Save