Browse Source

CS fixes

microsub
J. King 7 years ago
parent
commit
5c4772d95a
  1. 2
      .php_cs.dist
  2. 4
      lib/Misc/ValueInfo.php
  3. 22
      lib/REST/TinyTinyRSS/API.php
  4. 16
      tests/Misc/TestValueInfo.php
  5. 2
      tests/REST/TinyTinyRSS/TestTinyTinyAPI.php

2
.php_cs.dist

@ -1,7 +1,7 @@
<?php
namespace JKingWeb\Arsse;
require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php";
const BASE = __DIR__.DIRECTORY_SEPARATOR;
$paths = [
__FILE__,

4
lib/Misc/ValueInfo.php

@ -134,7 +134,7 @@ class ValueInfo {
return $out->format(Date::FORMAT['iso8601'][1]);
} elseif (is_float($value) && is_finite($value)) {
$out = (string) $value;
if(!strpos($out, "E")) {
if (!strpos($out, "E")) {
return $out;
} else {
$out = sprintf("%F", $value);
@ -174,7 +174,7 @@ class ValueInfo {
if ($dateFormat=="microtime") {
// PHP is not able to correctly handle the output of microtime() as the input of DateTime::createFromFormat(), so we fudge it to look like a float
if (preg_match("<^0\.\d{6}00 \d+$>", $value)) {
$value = substr($value,11).".".substr($value,2,6);
$value = substr($value, 11).".".substr($value, 2, 6);
} else {
throw new \Exception;
}

22
lib/REST/TinyTinyRSS/API.php

@ -106,7 +106,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
$data['seq'] = isset($data['seq']) ? $data['seq'] : 0;
$data = $this->normalizeInput($data, self::VALID_INPUT, "unix");
} catch(ExceptionType $e) {
} catch (ExceptionType $e) {
throw new Exception("INCORRECT_USAGE");
}
if (strtolower((string) $data['op']) != "login") {
@ -392,7 +392,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// attempt to remove the folder
Arsse::$db->folderRemove(Arsse::$user->id, (int) $data['category_id']);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -409,7 +409,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// try to move the folder
Arsse::$db->folderPropertiesSet(Arsse::$user->id, (int) $data['category_id'], $in);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -427,7 +427,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// try to rename the folder
Arsse::$db->folderPropertiesSet(Arsse::$user->id, $data['category_id'], $in);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -486,7 +486,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
// if we didn't find the ID we perform feed discovery for the next iteration; this is pretty messy: discovery ends up being done twice because it was already done in $db->subscriptionAdd()
try {
$url = Feed::discover($url, $fetchUser, $fetchPassword);
} catch(FeedException $e) {
} catch (FeedException $e) {
// feed errors (handled above)
return $this->feedError($e);
}
@ -510,7 +510,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// attempt to remove the feed
Arsse::$db->subscriptionRemove(Arsse::$user->id, (int) $data['feed_id']);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
throw new Exception("FEED_NOT_FOUND");
}
return ['status' => "OK"];
@ -527,7 +527,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// try to move the feed
Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $data['feed_id'], $in);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -545,7 +545,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// try to rename the feed
Arsse::$db->subscriptionPropertiesSet(Arsse::$user->id, $data['feed_id'], $in);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -558,7 +558,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
}
try {
Arsse::$db->feedUpdate(Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, $data['feed_id'])['feed']);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
throw new Exception("FEED_NOT_FOUND");
}
return ['status' => "OK"];
@ -619,7 +619,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// attempt to remove the label
Arsse::$db->labelRemove(Arsse::$user->id, $id);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
// ignore all errors
}
return null;
@ -632,7 +632,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
try {
// try to rename the folder
Arsse::$db->labelPropertiesSet(Arsse::$user->id, $id, ['name' => $name]);
} catch(ExceptionInput $e) {
} catch (ExceptionInput $e) {
if ($e->getCode()==10237) {
// if the supplied ID was invalid, report an error; other errors are to be ignored
throw new Exception("INCORRECT_USAGE");

16
tests/Misc/TestValueInfo.php

@ -385,10 +385,10 @@ class TestValueInfo extends Test\AbstractTest {
[0.5, [null,true], [true, false], [0, false], [0.5, true], ["0.5", true], [[0.5], false]],
["2.5", [null,true], [true, false], [2, false], [2.5, true], ["2.5", true], [["2.5"], false]],
["0.5", [null,true], [true, false], [0, false], [0.5, true], ["0.5", true], [["0.5"], false]],
[$this->d("2010-01-01T00:00:00",0,0), [null,true], [true, false], [1262304000, false], [1262304000.0, false], ["2010-01-01T00:00:00Z",true], [[$this->d("2010-01-01T00:00:00",0,0)],false]],
[$this->d("2010-01-01T00:00:00",0,1), [null,true], [true, false], [1262304000, false], [1262304000.0, false], ["2010-01-01T00:00:00Z",true], [[$this->d("2010-01-01T00:00:00",0,1)],false]],
[$this->d("2010-01-01T00:00:00",1,0), [null,true], [true, false], [1262322000, false], [1262322000.0, false], ["2010-01-01T05:00:00Z",true], [[$this->d("2010-01-01T00:00:00",1,0)],false]],
[$this->d("2010-01-01T00:00:00",1,1), [null,true], [true, false], [1262322000, false], [1262322000.0, false], ["2010-01-01T05:00:00Z",true], [[$this->d("2010-01-01T00:00:00",1,1)],false]],
[$this->d("2010-01-01T00:00:00", 0, 0), [null,true], [true, false], [1262304000, false], [1262304000.0, false], ["2010-01-01T00:00:00Z",true], [[$this->d("2010-01-01T00:00:00", 0, 0)],false]],
[$this->d("2010-01-01T00:00:00", 0, 1), [null,true], [true, false], [1262304000, false], [1262304000.0, false], ["2010-01-01T00:00:00Z",true], [[$this->d("2010-01-01T00:00:00", 0, 1)],false]],
[$this->d("2010-01-01T00:00:00", 1, 0), [null,true], [true, false], [1262322000, false], [1262322000.0, false], ["2010-01-01T05:00:00Z",true], [[$this->d("2010-01-01T00:00:00", 1, 0)],false]],
[$this->d("2010-01-01T00:00:00", 1, 1), [null,true], [true, false], [1262322000, false], [1262322000.0, false], ["2010-01-01T05:00:00Z",true], [[$this->d("2010-01-01T00:00:00", 1, 1)],false]],
[1e14, [null,true], [true, false], [100000000000000,true], [1e14, true], ["100000000000000", true], [[1e14], false]],
[1e-6, [null,true], [true, false], [0, false], [1e-6, true], ["0.000001", true], [[1e-6], false]],
[[1,2,3], [null,true], [true, false], [0, false], [0.0, false], ["", false], [[1,2,3], true] ],
@ -432,10 +432,10 @@ class TestValueInfo extends Test\AbstractTest {
$tests = [
/* Input value microtime iso8601 iso8601m http sql date time unix float '!M j, Y (D)' *strtotime* (null) */
[null, null, null, null, null, null, null, null, null, null, null, null, ],
[$this->d("2010-01-01T00:00:00",0,0), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), ],
[$this->d("2010-01-01T00:00:00",0,1), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), ],
[$this->d("2010-01-01T00:00:00",1,0), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), ],
[$this->d("2010-01-01T00:00:00",1,1), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), ],
[$this->d("2010-01-01T00:00:00", 0, 0), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), ],
[$this->d("2010-01-01T00:00:00", 0, 1), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), ],
[$this->d("2010-01-01T00:00:00", 1, 0), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), ],
[$this->d("2010-01-01T00:00:00", 1, 1), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), $this->t(1262322000), ],
[1262304000, $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), $this->t(1262304000), ],
[1262304000.123456, $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), $this->t(1262304000.123456), ],
[1262304000.42, $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), $this->t(1262304000.42), ],

2
tests/REST/TinyTinyRSS/TestTinyTinyAPI.php

@ -522,7 +522,7 @@ class TestTinyTinyAPI extends Test\AbstractTest {
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in))));
}
public function testRetrieveTheServerConfiguration () {
public function testRetrieveTheServerConfiguration() {
$in = ['op' => "getConfig", 'sid' => "PriestsOfSyrinx"];
$interval = Service::interval();
$valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval);

Loading…
Cancel
Save