1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Style fixes

This commit is contained in:
J. King 2018-12-05 17:28:11 -05:00
parent f2245861e3
commit cf896121b2
27 changed files with 53 additions and 59 deletions

View file

@ -17,6 +17,7 @@ $paths = [
$rules = [ $rules = [
'@PSR2' => true, '@PSR2' => true,
'braces' => ['position_after_functions_and_oop_constructs' => "same"], 'braces' => ['position_after_functions_and_oop_constructs' => "same"],
'function_declaration' => ['closure_function_spacing' => "none"],
]; ];
$finder = \PhpCsFixer\Finder::create(); $finder = \PhpCsFixer\Finder::create();

View file

@ -855,7 +855,8 @@ class Database {
left join arsse_enclosures on arsse_enclosures.article = arsse_articles.id left join arsse_enclosures on arsse_enclosures.article = arsse_articles.id
left join arsse_label_members on arsse_label_members.subscription = arsse_subscriptions.id and arsse_label_members.article = arsse_articles.id and arsse_label_members.assigned = 1 left join arsse_label_members on arsse_label_members.subscription = arsse_subscriptions.id and arsse_label_members.article = arsse_articles.id and arsse_label_members.assigned = 1
left join arsse_labels on arsse_labels.owner = arsse_subscriptions.owner and arsse_label_members.label = arsse_labels.id", left join arsse_labels on arsse_labels.owner = arsse_subscriptions.owner and arsse_label_members.label = arsse_labels.id",
["str"], [$user] ["str"],
[$user]
); );
$q->setCTE("latest_editions(article,edition)", "SELECT article,max(id) from arsse_editions group by article", [], [], "join latest_editions on arsse_articles.id = latest_editions.article"); $q->setCTE("latest_editions(article,edition)", "SELECT article,max(id) from arsse_editions group by article", [], [], "join latest_editions on arsse_articles.id = latest_editions.article");
if ($cols) { if ($cols) {

View file

@ -16,7 +16,7 @@ class ResultAggregate extends AbstractResult {
// actual public methods // actual public methods
public function changes(): int { public function changes(): int {
return array_reduce($this->data, function ($sum, $value) { return array_reduce($this->data, function($sum, $value) {
return $sum + $value->changes(); return $sum + $value->changes();
}, 0); }, 0);
} }

View file

@ -104,7 +104,7 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
} }
public function sqlToken(string $token): string { public function sqlToken(string $token): string {
switch(strtolower($token)) { switch (strtolower($token)) {
case "greatest": case "greatest":
return "max"; return "max";
default: default:

View file

@ -140,7 +140,7 @@ class Lang {
protected function listFiles(): array { protected function listFiles(): array {
$out = $this->globFiles($this->path."*.php"); $out = $this->globFiles($this->path."*.php");
// trim the returned file paths to return just the language tag // trim the returned file paths to return just the language tag
$out = array_map(function ($file) { $out = array_map(function($file) {
$file = str_replace(DIRECTORY_SEPARATOR, "/", $file); // we replace the directory separator because we don't use native paths in testing $file = str_replace(DIRECTORY_SEPARATOR, "/", $file); // we replace the directory separator because we don't use native paths in testing
$file = substr($file, strrpos($file, "/")+1); $file = substr($file, strrpos($file, "/")+1);
return strtolower(substr($file, 0, strrpos($file, "."))); return strtolower(substr($file, 0, strrpos($file, ".")));

View file

@ -97,7 +97,7 @@ class REST {
public function apiMatch(string $url): array { public function apiMatch(string $url): array {
$map = $this->apis; $map = $this->apis;
// sort the API list so the longest URL prefixes come first // sort the API list so the longest URL prefixes come first
uasort($map, function ($a, $b) { uasort($map, function($a, $b) {
return (strlen($a['match']) <=> strlen($b['match'])) * -1; return (strlen($a['match']) <=> strlen($b['match'])) * -1;
}); });
// normalize the target URL // normalize the target URL
@ -270,7 +270,7 @@ class REST {
} else { } else {
// if the host is a domain name or IP address, split it along dots and just perform URL decoding // if the host is a domain name or IP address, split it along dots and just perform URL decoding
$host = explode(".", $host); $host = explode(".", $host);
$host = array_map(function ($segment) { $host = array_map(function($segment) {
return str_replace(".", "%2E", rawurlencode(strtolower(rawurldecode($segment)))); return str_replace(".", "%2E", rawurlencode(strtolower(rawurldecode($segment))));
}, $host); }, $host);
$host = implode(".", $host); $host = implode(".", $host);

View file

@ -330,7 +330,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
'id' => "FEED:".self::FEED_ALL, 'id' => "FEED:".self::FEED_ALL,
'bare_id' => self::FEED_ALL, 'bare_id' => self::FEED_ALL,
'icon' => "images/folder.png", 'icon' => "images/folder.png",
'unread' => array_reduce($subs, function ($sum, $value) { 'unread' => array_reduce($subs, function($sum, $value) {
return $sum + $value['unread']; return $sum + $value['unread'];
}, 0), // the sum of all feeds' unread is the total unread }, 0), // the sum of all feeds' unread is the total unread
], $tSpecial), ], $tSpecial),

View file

@ -9,7 +9,6 @@ namespace JKingWeb\Arsse;
use PasswordGenerator\Generator as PassGen; use PasswordGenerator\Generator as PassGen;
class User { class User {
public $id = null; public $id = null;
/** /**

View file

@ -16,7 +16,6 @@ use Phake;
/** @covers \JKingWeb\Arsse\CLI */ /** @covers \JKingWeb\Arsse\CLI */
class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
self::clearData(false); self::clearData(false);
} }

View file

@ -15,7 +15,7 @@ use JKingWeb\Arsse\Db\Result;
use JKingWeb\Arsse\Test\DatabaseInformation; use JKingWeb\Arsse\Test\DatabaseInformation;
use Phake; use Phake;
abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest{ abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest {
use SeriesMiscellany; use SeriesMiscellany;
use SeriesMeta; use SeriesMeta;
use SeriesUser; use SeriesUser;
@ -34,7 +34,7 @@ abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest{
protected static $failureReason = ""; protected static $failureReason = "";
protected $primed = false; protected $primed = false;
protected abstract function nextID(string $table): int; abstract protected function nextID(string $table): int;
protected function findTraitOfTest(string $test): string { protected function findTraitOfTest(string $test): string {
$class = new \ReflectionClass(self::class); $class = new \ReflectionClass(self::class);

View file

@ -411,7 +411,7 @@ trait SeriesArticle {
305 => 105, 305 => 105,
1001 => 20, 1001 => 20,
]; ];
$this->assertEquals($exp, Arsse::$db->editionArticle(...range(1,1001))); $this->assertEquals($exp, Arsse::$db->editionArticle(...range(1, 1001)));
} }
public function testListArticlesCheckingContext() { public function testListArticlesCheckingContext() {

View file

@ -12,7 +12,6 @@ use JKingWeb\Arsse\Feed\Exception as FeedException;
use Phake; use Phake;
trait SeriesSubscription { trait SeriesSubscription {
public function setUpSeriesSubscription() { public function setUpSeriesSubscription() {
$this->data = [ $this->data = [
'arsse_users' => [ 'arsse_users' => [

View file

@ -115,7 +115,7 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
$this->exec($this->create); $this->exec($this->create);
$this->exec($this->lock); $this->exec($this->lock);
$this->assertException("general", "Db", "ExceptionTimeout"); $this->assertException("general", "Db", "ExceptionTimeout");
$lock = is_array($this->lock) ? implode("; ",$this->lock) : $this->lock; $lock = is_array($this->lock) ? implode("; ", $this->lock) : $this->lock;
$this->drv->exec($lock); $this->drv->exec($lock);
} }
@ -144,7 +144,7 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
$this->exec($this->create); $this->exec($this->create);
$this->exec($this->lock); $this->exec($this->lock);
$this->assertException("general", "Db", "ExceptionTimeout"); $this->assertException("general", "Db", "ExceptionTimeout");
$lock = is_array($this->lock) ? implode("; ",$this->lock) : $this->lock; $lock = is_array($this->lock) ? implode("; ", $this->lock) : $this->lock;
$this->drv->exec($lock); $this->drv->exec($lock);
} }

View file

@ -275,7 +275,6 @@ abstract class BaseStatement extends \JKingWeb\Arsse\Test\AbstractTest {
]; ];
foreach ($tests as $index => list($value, $type, $exp)) { foreach ($tests as $index => list($value, $type, $exp)) {
$t = preg_replace("<^strict >", "", $type); $t = preg_replace("<^strict >", "", $type);
if (gettype($exp) != "string") var_export($index);
$exp = ($exp=="null") ? $exp : $this->decorateTypeSyntax($exp, $t); $exp = ($exp=="null") ? $exp : $this->decorateTypeSyntax($exp, $t);
yield $index => [$value, $type, $exp]; yield $index => [$value, $type, $exp];
} }
@ -327,7 +326,6 @@ abstract class BaseStatement extends \JKingWeb\Arsse\Test\AbstractTest {
]; ];
foreach ($tests as $index => list($value, $type, $exp)) { foreach ($tests as $index => list($value, $type, $exp)) {
$t = preg_replace("<^strict >", "", $type); $t = preg_replace("<^strict >", "", $type);
if (gettype($exp) != "string") var_export($index);
$exp = ($exp=="null") ? $exp : $this->decorateTypeSyntax($exp, $t); $exp = ($exp=="null") ? $exp : $this->decorateTypeSyntax($exp, $t);
yield $index => [$value, $type, $exp]; yield $index => [$value, $type, $exp];
} }

View file

@ -21,7 +21,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
if ($act==$postfix) { if ($act==$postfix) {
$this->assertSame($exp, ""); $this->assertSame($exp, "");
} else { } else {
$test = substr($act, 0, strlen($act) - (strlen($postfix) + 1) ); $test = substr($act, 0, strlen($act) - (strlen($postfix) + 1));
$check = substr($act, strlen($test) + 1); $check = substr($act, strlen($test) + 1);
$this->assertSame($postfix, $check); $this->assertSame($postfix, $check);
$this->assertSame($exp, $test); $this->assertSame($exp, $test);

View file

@ -30,7 +30,7 @@ class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
and table_name like 'arsse_%' and table_name like 'arsse_%'
and column_default like 'nextval(%' and column_default like 'nextval(%'
"; ";
foreach(static::$drv->query($seqList) as $r) { foreach (static::$drv->query($seqList) as $r) {
$num = (int) static::$drv->query("SELECT max({$r['col']}) from {$r['table']}")->getValue(); $num = (int) static::$drv->query("SELECT max({$r['col']}) from {$r['table']}")->getValue();
if (!$num) { if (!$num) {
continue; continue;

View file

@ -23,9 +23,8 @@ class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
case "string": case "string":
if (preg_match("<^char\((\d+)\)$>", $value, $match)) { if (preg_match("<^char\((\d+)\)$>", $value, $match)) {
return "U&'\\+".str_pad(dechex((int) $match[1]), 6, "0", \STR_PAD_LEFT)."'"; return "U&'\\+".str_pad(dechex((int) $match[1]), 6, "0", \STR_PAD_LEFT)."'";
} else {
return $value;
} }
return $value;
default: default:
return $value; return $value;
} }

View file

@ -153,7 +153,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
public function testNegotiateCors($origin, bool $exp, string $allowed = null, string $denied = null) { public function testNegotiateCors($origin, bool $exp, string $allowed = null, string $denied = null) {
self::setConf(); self::setConf();
$r = Phake::partialMock(REST::class); $r = Phake::partialMock(REST::class);
Phake::when($r)->corsNormalizeOrigin->thenReturnCallback(function ($origin) { Phake::when($r)->corsNormalizeOrigin->thenReturnCallback(function($origin) {
return $origin; return $origin;
}); });
$headers = isset($origin) ? ['Origin' => $origin] : []; $headers = isset($origin) ? ['Origin' => $origin] : [];
@ -255,10 +255,10 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
public function testNormalizeHttpResponses(ResponseInterface $res, ResponseInterface $exp, RequestInterface $req = null) { public function testNormalizeHttpResponses(ResponseInterface $res, ResponseInterface $exp, RequestInterface $req = null) {
$r = Phake::partialMock(REST::class); $r = Phake::partialMock(REST::class);
Phake::when($r)->corsNegotiate->thenReturn(true); Phake::when($r)->corsNegotiate->thenReturn(true);
Phake::when($r)->challenge->thenReturnCallback(function ($res) { Phake::when($r)->challenge->thenReturnCallback(function($res) {
return $res->withHeader("WWW-Authenticate", "Fake Value"); return $res->withHeader("WWW-Authenticate", "Fake Value");
}); });
Phake::when($r)->corsApply->thenReturnCallback(function ($res) { Phake::when($r)->corsApply->thenReturnCallback(function($res) {
return $res; return $res;
}); });
$act = $r->normalizeResponse($res, $req); $act = $r->normalizeResponse($res, $req);
@ -298,10 +298,10 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideMockRequests */ /** @dataProvider provideMockRequests */
public function testDispatchRequests(ServerRequest $req, string $method, bool $called, string $class = "", string $target ="") { public function testDispatchRequests(ServerRequest $req, string $method, bool $called, string $class = "", string $target ="") {
$r = Phake::partialMock(REST::class); $r = Phake::partialMock(REST::class);
Phake::when($r)->normalizeResponse->thenReturnCallback(function ($res) { Phake::when($r)->normalizeResponse->thenReturnCallback(function($res) {
return $res; return $res;
}); });
Phake::when($r)->authenticateRequest->thenReturnCallback(function ($req) { Phake::when($r)->authenticateRequest->thenReturnCallback(function($req) {
return $req; return $req;
}); });
if ($called) { if ($called) {

View file

@ -1516,13 +1516,13 @@ LONG_STRING;
} }
protected function filterFolders(int $id = null): array { protected function filterFolders(int $id = null): array {
return array_filter($this->folders, function ($value) use ($id) { return array_filter($this->folders, function($value) use ($id) {
return $value['parent']==$id; return $value['parent']==$id;
}); });
} }
protected function filterSubs(int $folder = null): array { protected function filterSubs(int $folder = null): array {
return array_filter($this->subscriptions, function ($value) use ($folder) { return array_filter($this->subscriptions, function($value) use ($folder) {
return $value['folder']==$folder; return $value['folder']==$folder;
}); });
} }
@ -1532,9 +1532,9 @@ LONG_STRING;
foreach ($this->filterFolders($id) as $f) { foreach ($this->filterFolders($id) as $f) {
$out += $this->reduceFolders($f['id']); $out += $this->reduceFolders($f['id']);
} }
$out += array_reduce(array_filter($this->subscriptions, function ($value) use ($id) { $out += array_reduce(array_filter($this->subscriptions, function($value) use ($id) {
return $value['folder']==$id; return $value['folder']==$id;
}), function ($sum, $value) { }), function($sum, $value) {
return $sum + $value['unread']; return $sum + $value['unread'];
}, 0); }, 0);
return $out; return $out;

View file

@ -17,7 +17,6 @@ use Phake;
/** @covers \JKingWeb\Arsse\User\Internal\Driver */ /** @covers \JKingWeb\Arsse\User\Internal\Driver */
class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest { class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
self::clearData(); self::clearData();
self::setConf(); self::setConf();

View file

@ -17,7 +17,6 @@ use Phake;
/** @covers \JKingWeb\Arsse\User */ /** @covers \JKingWeb\Arsse\User */
class TestUser extends \JKingWeb\Arsse\Test\AbstractTest { class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() { public function setUp() {
self::clearData(); self::clearData();
self::setConf(); self::setConf();
@ -236,7 +235,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertException("doesNotExist", "User"); $this->assertException("doesNotExist", "User");
} }
$calls = 0; $calls = 0;
} else{ } else {
$calls = 1; $calls = 1;
} }
try { try {

View file

@ -80,7 +80,7 @@ class DatabaseInformation {
// rollback any pending transaction // rollback any pending transaction
try { try {
$db->exec("ROLLBACK"); $db->exec("ROLLBACK");
} catch(\Throwable $e) { } catch (\Throwable $e) {
} }
foreach ($sqlite3TableList($db) as $table) { foreach ($sqlite3TableList($db) as $table) {
if ($table == "arsse_meta") { if ($table == "arsse_meta") {
@ -97,7 +97,7 @@ class DatabaseInformation {
// rollback any pending transaction // rollback any pending transaction
try { try {
$db->exec("ROLLBACK"); $db->exec("ROLLBACK");
} catch(\Throwable $e) { } catch (\Throwable $e) {
} }
$db->exec("PRAGMA foreign_keys=0"); $db->exec("PRAGMA foreign_keys=0");
foreach ($sqlite3TableList($db) as $table) { foreach ($sqlite3TableList($db) as $table) {
@ -181,7 +181,7 @@ class DatabaseInformation {
// rollback any pending transaction // rollback any pending transaction
try { try {
$db->exec("ROLLBACK"); $db->exec("ROLLBACK");
} catch(\Throwable $e) { } catch (\Throwable $e) {
} }
foreach ($pgObjectList($db) as $obj) { foreach ($pgObjectList($db) as $obj) {
if ($obj['type'] != "TABLE") { if ($obj['type'] != "TABLE") {
@ -200,7 +200,7 @@ class DatabaseInformation {
// rollback any pending transaction // rollback any pending transaction
try { try {
$db->exec("ROLLBACK"); $db->exec("ROLLBACK");
} catch(\Throwable $e) { } catch (\Throwable $e) {
} }
foreach ($pgObjectList($db) as $obj) { foreach ($pgObjectList($db) as $obj) {
$db->exec("DROP {$obj['type']} IF EXISTS {$obj['name']} cascade"); $db->exec("DROP {$obj['type']} IF EXISTS {$obj['name']} cascade");