mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Apply more PSR-12 style rules
This commit is contained in:
parent
4ed650fd87
commit
9ac615e4a4
17 changed files with 48 additions and 62 deletions
|
@ -16,6 +16,8 @@ $paths = [
|
|||
BASE."tests",
|
||||
];
|
||||
$rules = [
|
||||
// PSR standard to apply
|
||||
'@PSR12' => true,
|
||||
// house rules where PSR series is silent
|
||||
'align_multiline_comment' => ['comment_type' => "phpdocs_only"],
|
||||
'array_syntax' => ['syntax' => "short"],
|
||||
|
@ -51,27 +53,15 @@ $rules = [
|
|||
'trailing_comma_in_multiline' => true,
|
||||
'unary_operator_spaces' => true,
|
||||
'yoda_style' => false,
|
||||
// PSR standard to apply
|
||||
'@PSR2' => true,
|
||||
// PSR-12 rules; php-cs-fixer does not yet support PSR-12 natively
|
||||
'compact_nullable_typehint' => true,
|
||||
'declare_equal_normalize' => ['space' => "none"],
|
||||
'function_typehint_space' => true,
|
||||
'lowercase_cast' => true,
|
||||
'lowercase_static_reference' => true,
|
||||
'no_alternative_syntax' => true,
|
||||
'no_empty_statement' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_leading_namespace_whitespace' => true,
|
||||
'no_whitespace_in_blank_line' => true,
|
||||
'return_type_declaration' => ['space_before' => "none"],
|
||||
'single_trait_insert_per_statement' => true,
|
||||
'short_scalar_cast' => true,
|
||||
'visibility_required' => ['elements' => ["const", "property", "method"]],
|
||||
// house exceptions to PSR rules
|
||||
'braces' => ['position_after_functions_and_oop_constructs' => "same"],
|
||||
'function_declaration' => ['closure_function_spacing' => "none"],
|
||||
'new_with_braces' => false, // no option to specify absence of braces
|
||||
'new_with_braces' => [
|
||||
'anonymous_class' => false,
|
||||
'named_class' => false,
|
||||
],
|
||||
'single_blank_line_before_namespace' => false,
|
||||
'blank_line_after_opening_tag' => false,
|
||||
];
|
||||
|
||||
$finder = \PhpCsFixer\Finder::create();
|
||||
|
|
|
@ -7,7 +7,6 @@ declare(strict_types=1);
|
|||
namespace JKingWeb\Arsse\Db\PostgreSQL;
|
||||
|
||||
class PDOResult extends \JKingWeb\Arsse\Db\PDOResult {
|
||||
|
||||
// This method exists to transparent handle byte-array results
|
||||
|
||||
public function valid() {
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace JKingWeb\Arsse\Misc;
|
|||
* A collection of functions for manipulating URLs
|
||||
*/
|
||||
class URL {
|
||||
|
||||
/** Returns whether a URL is absolute i.e. has a scheme */
|
||||
public static function absolute(string $url): bool {
|
||||
return (bool) strlen((string) parse_url($url, \PHP_URL_SCHEME));
|
||||
|
|
|
@ -107,7 +107,7 @@ class ValueInfo {
|
|||
if ($strict && !$drop) {
|
||||
throw new ExceptionType("strictFailure", $type);
|
||||
}
|
||||
return (!$drop) ? (int) $value->getTimestamp(): null;
|
||||
return (!$drop) ? (int) $value->getTimestamp() : null;
|
||||
} elseif ($value instanceof \DateInterval) {
|
||||
if ($strict && !$drop) {
|
||||
throw new ExceptionType("strictFailure", $type);
|
||||
|
@ -159,7 +159,7 @@ class ValueInfo {
|
|||
if ($strict && !$drop) {
|
||||
throw new ExceptionType("strictFailure", $type);
|
||||
}
|
||||
return (!$drop) ? (float) $value->getTimestamp(): null;
|
||||
return (!$drop) ? (float) $value->getTimestamp() : null;
|
||||
} elseif ($value instanceof \DateInterval) {
|
||||
if ($drop) {
|
||||
return null;
|
||||
|
@ -203,13 +203,13 @@ class ValueInfo {
|
|||
if ($value->days) {
|
||||
$dateSpec = $value->days."D";
|
||||
} else {
|
||||
$dateSpec .= $value->y ? $value->y."Y": "";
|
||||
$dateSpec .= $value->m ? $value->m."M": "";
|
||||
$dateSpec .= $value->d ? $value->d."D": "";
|
||||
$dateSpec .= $value->y ? $value->y."Y" : "";
|
||||
$dateSpec .= $value->m ? $value->m."M" : "";
|
||||
$dateSpec .= $value->d ? $value->d."D" : "";
|
||||
}
|
||||
$timeSpec .= $value->h ? $value->h."H": "";
|
||||
$timeSpec .= $value->i ? $value->i."M": "";
|
||||
$timeSpec .= $value->s ? $value->s."S": "";
|
||||
$timeSpec .= $value->h ? $value->h."H" : "";
|
||||
$timeSpec .= $value->i ? $value->i."M" : "";
|
||||
$timeSpec .= $value->s ? $value->s."S" : "";
|
||||
$timeSpec = $timeSpec ? "T".$timeSpec : "";
|
||||
if (!$dateSpec && !$timeSpec) {
|
||||
return "PT0S";
|
||||
|
|
|
@ -125,14 +125,14 @@ class REST {
|
|||
$target = substr($url, strlen($api['strip']));
|
||||
} else {
|
||||
// if the match fails we are not able to handle the request
|
||||
throw new REST\Exception501();
|
||||
throw new REST\Exception501;
|
||||
}
|
||||
// return the API name, stripped URL, and API class name
|
||||
return [$id, $target, $api['class']];
|
||||
}
|
||||
}
|
||||
// or throw an exception otherwise
|
||||
throw new REST\Exception501();
|
||||
throw new REST\Exception501;
|
||||
}
|
||||
|
||||
public function authenticateRequest(ServerRequestInterface $req): ServerRequestInterface {
|
||||
|
|
|
@ -21,13 +21,13 @@ class Service {
|
|||
|
||||
public function __construct() {
|
||||
$driver = Arsse::$conf->serviceDriver;
|
||||
$this->drv = new $driver();
|
||||
$this->drv = new $driver;
|
||||
}
|
||||
|
||||
public function watch(bool $loop = true): \DateTimeInterface {
|
||||
$this->loop = $loop;
|
||||
$this->signalInit();
|
||||
$t = new \DateTime();
|
||||
$t = new \DateTime;
|
||||
do {
|
||||
$this->checkIn();
|
||||
static::cleanupPre();
|
||||
|
@ -80,7 +80,7 @@ class Service {
|
|||
// get the checking interval
|
||||
$int = Arsse::$conf->serviceFrequency;
|
||||
// subtract twice the checking interval from the current time to yield the earliest acceptable check-in time
|
||||
$limit = new \DateTime();
|
||||
$limit = new \DateTime;
|
||||
$limit->sub($int);
|
||||
$limit->sub($int);
|
||||
// return whether the check-in time is within the acceptable limit
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestException extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
*/
|
||||
public function testBaseClassWithoutMessage(): void {
|
||||
$this->assertException("unknown");
|
||||
throw new Exception();
|
||||
throw new Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,10 +150,10 @@ class TestException extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
public function providePicoFeedException() {
|
||||
return [
|
||||
'Failed feed discovery' => [new \PicoFeed\Reader\SubscriptionNotFoundException(), "subscriptionNotFound"],
|
||||
'Unsupported format' => [new \PicoFeed\Reader\UnsupportedFeedFormatException(), "unsupportedFeedFormat"],
|
||||
'Malformed XML' => [new \PicoFeed\Parser\MalformedXmlException(), "malformedXml"],
|
||||
'XML entity expansion' => [new \PicoFeed\Parser\XmlEntityException(), "xmlEntity"],
|
||||
'Failed feed discovery' => [new \PicoFeed\Reader\SubscriptionNotFoundException, "subscriptionNotFound"],
|
||||
'Unsupported format' => [new \PicoFeed\Reader\UnsupportedFeedFormatException, "unsupportedFeedFormat"],
|
||||
'Malformed XML' => [new \PicoFeed\Parser\MalformedXmlException, "malformedXml"],
|
||||
'XML entity expansion' => [new \PicoFeed\Parser\XmlEntityException, "xmlEntity"],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
public function testCleanIdArrayValues(): void {
|
||||
$methods = ["articles", "editions", "tags", "labels", "subscriptions"];
|
||||
$in = [1, "2", 3.5, 4.0, 4, "ook", 0, -20, true, false, null, new \DateTime(), -1.0];
|
||||
$in = [1, "2", 3.5, 4.0, 4, "ook", 0, -20, true, false, null, new \DateTime, -1.0];
|
||||
$out = [1, 2, 4];
|
||||
$c = new Context;
|
||||
foreach ($methods as $method) {
|
||||
|
@ -113,7 +113,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
public function testCleanFolderIdArrayValues(): void {
|
||||
$methods = ["folders", "foldersShallow"];
|
||||
$in = [1, "2", 3.5, 4.0, 4, "ook", 0, -20, true, false, null, new \DateTime(), -1.0];
|
||||
$in = [1, "2", 3.5, 4.0, 4, "ook", 0, -20, true, false, null, new \DateTime, -1.0];
|
||||
$out = [1, 2, 4, 0];
|
||||
$c = new Context;
|
||||
foreach ($methods as $method) {
|
||||
|
|
|
@ -10,7 +10,6 @@ use JKingWeb\Arsse\Misc\URL;
|
|||
|
||||
/** @covers \JKingWeb\Arsse\Misc\URL */
|
||||
class TestURL extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||
|
||||
/** @dataProvider provideNormalizations */
|
||||
public function testNormalizeAUrl(string $url, string $exp, string $user = null, string $pass = null): void {
|
||||
$this->assertSame($exp, URL::normalize($url, $user, $pass));
|
||||
|
|
|
@ -93,7 +93,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Arsse::$user->method("propertiesGet")->willReturn(['num' => 42, 'admin' => false, 'root_folder_name' => null, 'tz' => "Asia/Gaza"]);
|
||||
Arsse::$user->method("begin")->willReturn($this->transaction->get());
|
||||
//initialize a handler
|
||||
$this->h = new V1();
|
||||
$this->h = new V1;
|
||||
}
|
||||
|
||||
protected function v($value) {
|
||||
|
|
|
@ -328,7 +328,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$this->dbMock = $this->mock(Database::class);
|
||||
$this->dbMock->begin->returns($this->mock(Transaction::class));
|
||||
//initialize a handler
|
||||
$this->h = new V1_2();
|
||||
$this->h = new V1_2;
|
||||
}
|
||||
|
||||
protected function v($value) {
|
||||
|
|
|
@ -22,7 +22,6 @@ use Laminas\Diactoros\Response\EmptyResponse;
|
|||
|
||||
/** @covers \JKingWeb\Arsse\REST */
|
||||
class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||
|
||||
/** @dataProvider provideApiMatchData */
|
||||
public function testMatchAUrlToAnApi($apiList, string $input, array $exp): void {
|
||||
$r = new REST($apiList);
|
||||
|
@ -61,7 +60,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
/** @dataProvider provideAuthenticableRequests */
|
||||
public function testAuthenticateRequests(array $serverParams, array $expAttr): void {
|
||||
$r = new REST();
|
||||
$r = new REST;
|
||||
// create a mock user manager
|
||||
$this->userMock = $this->mock(User::class);
|
||||
$this->userMock->auth->returns(false);
|
||||
|
@ -95,7 +94,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
public function testSendAuthenticationChallenges(): void {
|
||||
self::setConf();
|
||||
$r = new REST();
|
||||
$r = new REST;
|
||||
$in = new EmptyResponse(401);
|
||||
$exp = $in->withHeader("WWW-Authenticate", 'Basic realm="OOK", charset="UTF-8"');
|
||||
$act = $r->challenge($in, "OOK");
|
||||
|
@ -107,7 +106,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
/** @dataProvider provideUnnormalizedOrigins */
|
||||
public function testNormalizeOrigins(string $origin, string $exp, array $ports = null): void {
|
||||
$r = new REST();
|
||||
$r = new REST;
|
||||
$act = $r->corsNormalizeOrigin($origin, $ports);
|
||||
$this->assertSame($exp, $act);
|
||||
}
|
||||
|
@ -188,7 +187,7 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
|
||||
/** @dataProvider provideCorsHeaders */
|
||||
public function testAddCorsHeaders(string $reqMethod, array $reqHeaders, array $resHeaders, array $expHeaders): void {
|
||||
$r = new REST();
|
||||
$r = new REST;
|
||||
$req = new Request("", $reqMethod, "php://memory", $reqHeaders);
|
||||
$res = new EmptyResponse(204, $resHeaders);
|
||||
$exp = new EmptyResponse(204, $expHeaders);
|
||||
|
|
|
@ -147,7 +147,7 @@ LONG_STRING;
|
|||
'expires' => "2112-12-21 21:12:00",
|
||||
'user' => $this->userId,
|
||||
]);
|
||||
$this->h = new API();
|
||||
$this->h = new API;
|
||||
}
|
||||
|
||||
protected function req($data, string $method = "POST", string $target = "", string $strData = null, string $user = null): ResponseInterface {
|
||||
|
|
|
@ -25,7 +25,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
Arsse::$user = $this->mock(User::class)->get();
|
||||
// create a mock database interface
|
||||
$this->dbMock = $this->mock(Database::class);
|
||||
$this->h = new Icon();
|
||||
$this->h = new Icon;
|
||||
}
|
||||
|
||||
protected function req(string $target, string $method = "GET", string $user = null): ResponseInterface {
|
||||
|
|
|
@ -20,7 +20,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
self::setConf();
|
||||
$this->dbMock = $this->mock(Database::class);
|
||||
Arsse::$db = $this->dbMock->get();
|
||||
$this->srv = new Service();
|
||||
$this->srv = new Service;
|
||||
}
|
||||
|
||||
public function testCheckIn(): void {
|
||||
|
|
|
@ -54,7 +54,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|||
Arsse::$$prop = null;
|
||||
}
|
||||
if ($loadLang) {
|
||||
Arsse::$lang = new \JKingWeb\Arsse\Lang();
|
||||
Arsse::$lang = new \JKingWeb\Arsse\Lang;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,17 +62,17 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|||
$defaults = [
|
||||
'dbSQLite3File' => ":memory:",
|
||||
'dbSQLite3Timeout' => 0,
|
||||
'dbPostgreSQLHost' => $_ENV['ARSSE_TEST_PGSQL_HOST'] ?: "",
|
||||
'dbPostgreSQLPort' => $_ENV['ARSSE_TEST_PGSQL_PORT'] ?: 5432,
|
||||
'dbPostgreSQLUser' => $_ENV['ARSSE_TEST_PGSQL_USER'] ?: "arsse_test",
|
||||
'dbPostgreSQLPass' => $_ENV['ARSSE_TEST_PGSQL_PASS'] ?: "arsse_test",
|
||||
'dbPostgreSQLDb' => $_ENV['ARSSE_TEST_PGSQL_DB'] ?: "arsse_test",
|
||||
'dbPostgreSQLHost' => $_ENV['ARSSE_TEST_PGSQL_HOST'] ?: "",
|
||||
'dbPostgreSQLPort' => $_ENV['ARSSE_TEST_PGSQL_PORT'] ?: 5432,
|
||||
'dbPostgreSQLUser' => $_ENV['ARSSE_TEST_PGSQL_USER'] ?: "arsse_test",
|
||||
'dbPostgreSQLPass' => $_ENV['ARSSE_TEST_PGSQL_PASS'] ?: "arsse_test",
|
||||
'dbPostgreSQLDb' => $_ENV['ARSSE_TEST_PGSQL_DB'] ?: "arsse_test",
|
||||
'dbPostgreSQLSchema' => $_ENV['ARSSE_TEST_PGSQL_SCHEMA'] ?: "arsse_test",
|
||||
'dbMySQLHost' => $_ENV['ARSSE_TEST_MYSQL_HOST'] ?: "localhost",
|
||||
'dbMySQLPort' => $_ENV['ARSSE_TEST_MYSQL_PORT'] ?: 3306,
|
||||
'dbMySQLUser' => $_ENV['ARSSE_TEST_MYSQL_USER'] ?: "arsse_test",
|
||||
'dbMySQLPass' => $_ENV['ARSSE_TEST_MYSQL_PASS'] ?: "arsse_test",
|
||||
'dbMySQLDb' => $_ENV['ARSSE_TEST_MYSQL_DB'] ?: "arsse_test",
|
||||
'dbMySQLHost' => $_ENV['ARSSE_TEST_MYSQL_HOST'] ?: "localhost",
|
||||
'dbMySQLPort' => $_ENV['ARSSE_TEST_MYSQL_PORT'] ?: 3306,
|
||||
'dbMySQLUser' => $_ENV['ARSSE_TEST_MYSQL_USER'] ?: "arsse_test",
|
||||
'dbMySQLPass' => $_ENV['ARSSE_TEST_MYSQL_PASS'] ?: "arsse_test",
|
||||
'dbMySQLDb' => $_ENV['ARSSE_TEST_MYSQL_DB'] ?: "arsse_test",
|
||||
];
|
||||
Arsse::$conf = (($force ? null : Arsse::$conf) ?? (new Conf))->import($defaults)->import($conf);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue