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

Style fixes

This commit is contained in:
J. King 2020-11-16 10:26:14 -05:00
parent 180b4ecc9b
commit e16df90bae
13 changed files with 50 additions and 57 deletions

View file

@ -37,7 +37,7 @@ use JKingWeb\Arsse\Misc\URL;
* associations with articles. There has been an effort to keep public method * associations with articles. There has been an effort to keep public method
* names consistent throughout, but protected methods, having different * names consistent throughout, but protected methods, having different
* concerns, will typically follow different conventions. * concerns, will typically follow different conventions.
* *
* Note that operations on users should be performed with the User class rather * Note that operations on users should be performed with the User class rather
* than the Database class directly. This is to allow for alternate user sources. * than the Database class directly. This is to allow for alternate user sources.
*/ */
@ -298,7 +298,7 @@ class Database {
$this->db->prepare("UPDATE arsse_users set password = ? where id = ?", "str", "str")->run($hash, $user); $this->db->prepare("UPDATE arsse_users set password = ? where id = ?", "str", "str")->run($hash, $user);
return true; return true;
} }
public function userPropertiesGet(string $user): array { public function userPropertiesGet(string $user): array {
$out = $this->db->prepare("SELECT num, admin, lang, tz, sort_asc from arsse_users where id = ?", "str")->run($user)->getRow(); $out = $this->db->prepare("SELECT num, admin, lang, tz, sort_asc from arsse_users where id = ?", "str")->run($user)->getRow();
if (!$out) { if (!$out) {
@ -309,7 +309,7 @@ class Database {
settype($out['sort_asc'], "bool"); settype($out['sort_asc'], "bool");
return $out; return $out;
} }
public function userPropertiesSet(string $user, array $data): bool { public function userPropertiesSet(string $user, array $data): bool {
if (!$this->userExists($user)) { if (!$this->userExists($user)) {
throw new User\ExceptionConflict("doesNotExist", ["action" => __FUNCTION__, "user" => $user]); throw new User\ExceptionConflict("doesNotExist", ["action" => __FUNCTION__, "user" => $user]);
@ -325,7 +325,6 @@ class Database {
return false; return false;
} }
return (bool) $this->db->prepare("UPDATE arsse_users set $setClause where id = ?", $setTypes, "str")->run($setValues, $user)->changes(); return (bool) $this->db->prepare("UPDATE arsse_users set $setClause where id = ?", $setTypes, "str")->run($setValues, $user)->changes();
} }
/** Creates a new session for the given user and returns the session identifier */ /** Creates a new session for the given user and returns the session identifier */
@ -874,16 +873,16 @@ class Database {
$out = $this->db->prepare("SELECT $field from arsse_tags where id in (select tag from arsse_tag_members where subscription = ? and assigned = 1) order by $field", "int")->run($id)->getAll(); $out = $this->db->prepare("SELECT $field from arsse_tags where id in (select tag from arsse_tag_members where subscription = ? and assigned = 1) order by $field", "int")->run($id)->getAll();
return $out ? array_column($out, $field) : []; return $out ? array_column($out, $field) : [];
} }
/** Retrieves detailed information about the icon for a subscription. /** Retrieves detailed information about the icon for a subscription.
* *
* The returned information is: * The returned information is:
* *
* - "id": The umeric identifier of the icon (not the subscription) * - "id": The umeric identifier of the icon (not the subscription)
* - "url": The URL of the icon * - "url": The URL of the icon
* - "type": The Content-Type of the icon e.g. "image/png" * - "type": The Content-Type of the icon e.g. "image/png"
* - "data": The icon itself, as a binary sring; if $withData is false this will be null * - "data": The icon itself, as a binary sring; if $withData is false this will be null
* *
* @param string|null $user The user who owns the subscription being queried; using null here is supported for TT-RSS and SHOULD NOT be used elsewhere as it leaks information * @param string|null $user The user who owns the subscription being queried; using null here is supported for TT-RSS and SHOULD NOT be used elsewhere as it leaks information
* @param int $subscription The numeric identifier of the subscription * @param int $subscription The numeric identifier of the subscription
* @param bool $includeData Whether to include the binary data of the icon itself in the result * @param bool $includeData Whether to include the binary data of the icon itself in the result
@ -1219,14 +1218,14 @@ class Database {
} }
/** Lists icons for feeds to which a user is subscribed /** Lists icons for feeds to which a user is subscribed
* *
* The returned information for each icon is: * The returned information for each icon is:
* *
* - "id": The umeric identifier of the icon * - "id": The umeric identifier of the icon
* - "url": The URL of the icon * - "url": The URL of the icon
* - "type": The Content-Type of the icon e.g. "image/png" * - "type": The Content-Type of the icon e.g. "image/png"
* - "data": The icon itself, as a binary sring * - "data": The icon itself, as a binary sring
* *
* @param string $user The user whose subscription icons are to be retrieved * @param string $user The user whose subscription icons are to be retrieved
*/ */
public function iconList(string $user): Db\Result { public function iconList(string $user): Db\Result {

View file

@ -13,7 +13,7 @@ class PDOResult extends \JKingWeb\Arsse\Db\PDOResult {
public function valid() { public function valid() {
$this->cur = $this->set->fetch(\PDO::FETCH_ASSOC); $this->cur = $this->set->fetch(\PDO::FETCH_ASSOC);
if ($this->cur !== false) { if ($this->cur !== false) {
foreach($this->cur as $k => $v) { foreach ($this->cur as $k => $v) {
if (is_resource($v)) { if (is_resource($v)) {
$this->cur[$k] = stream_get_contents($v); $this->cur[$k] = stream_get_contents($v);
fclose($v); fclose($v);

View file

@ -48,7 +48,7 @@ class Result extends \JKingWeb\Arsse\Db\AbstractResult {
public function valid() { public function valid() {
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC); $this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
if ($this->cur !== false) { if ($this->cur !== false) {
foreach($this->blobs as $f) { foreach ($this->blobs as $f) {
if ($this->cur[$f]) { if ($this->cur[$f]) {
$this->cur[$f] = hex2bin(substr($this->cur[$f], 2)); $this->cur[$f] = hex2bin(substr($this->cur[$f], 2));
} }

View file

@ -7,19 +7,14 @@ declare(strict_types=1);
namespace JKingWeb\Arsse\REST\Miniflux; namespace JKingWeb\Arsse\REST\Miniflux;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Context\Context;
use JKingWeb\Arsse\Misc\ValueInfo; use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\AbstractException; use JKingWeb\Arsse\AbstractException;
use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Feed\Exception as FeedException;
use JKingWeb\Arsse\Misc\HTTP; use JKingWeb\Arsse\Misc\HTTP;
use JKingWeb\Arsse\REST\Exception; use JKingWeb\Arsse\REST\Exception;
use JKingWeb\Arsse\REST\Exception404; use JKingWeb\Arsse\REST\Exception404;
use JKingWeb\Arsse\REST\Exception405; use JKingWeb\Arsse\REST\Exception405;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Laminas\Diactoros\Response\JsonResponse as Response;
use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\Response\EmptyResponse;
class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {

View file

@ -69,7 +69,6 @@ class User {
} }
return $out; return $out;
} }
public function remove(string $user): bool { public function remove(string $user): bool {
try { try {

View file

@ -16,12 +16,12 @@ interface Driver {
public function auth(string $user, string $password): bool; public function auth(string $user, string $password): bool;
/** Adds a new user and returns their password /** Adds a new user and returns their password
* *
* When given no password the implementation may return null; the user * When given no password the implementation may return null; the user
* manager will then generate a random password and try again with that * manager will then generate a random password and try again with that
* password. Alternatively the implementation may generate its own * password. Alternatively the implementation may generate its own
* password if desired * password if desired
* *
* @param string $user The username to create * @param string $user The username to create
* @param string|null $password The cleartext password to assign to the user, or null to generate a random password * @param string|null $password The cleartext password to assign to the user, or null to generate a random password
*/ */
@ -34,45 +34,45 @@ interface Driver {
public function userList(): array; public function userList(): array;
/** Sets a user's password /** Sets a user's password
* *
* When given no password the implementation may return null; the user * When given no password the implementation may return null; the user
* manager will then generate a random password and try again with that * manager will then generate a random password and try again with that
* password. Alternatively the implementation may generate its own * password. Alternatively the implementation may generate its own
* password if desired * password if desired
* *
* @param string $user The user for whom to change the password * @param string $user The user for whom to change the password
* @param string|null $password The cleartext password to assign to the user, or null to generate a random password * @param string|null $password The cleartext password to assign to the user, or null to generate a random password
* @param string|null $oldPassword The user's previous password, if known * @param string|null $oldPassword The user's previous password, if known
*/ */
public function userPasswordSet(string $user, ?string $newPassword, string $oldPassword = null); public function userPasswordSet(string $user, ?string $newPassword, string $oldPassword = null);
/** Removes a user's password; this makes authentication fail unconditionally /** Removes a user's password; this makes authentication fail unconditionally
* *
* @param string $user The user for whom to change the password * @param string $user The user for whom to change the password
* @param string|null $oldPassword The user's previous password, if known * @param string|null $oldPassword The user's previous password, if known
*/ */
public function userPasswordUnset(string $user, string $oldPassword = null): bool; public function userPasswordUnset(string $user, string $oldPassword = null): bool;
/** Retrieves metadata about a user /** Retrieves metadata about a user
* *
* Any expected keys not returned by the driver are taken from the internal * Any expected keys not returned by the driver are taken from the internal
* database instead; the expected keys at this time are: * database instead; the expected keys at this time are:
* *
* - admin: A boolean denoting whether the user has administrator privileges * - admin: A boolean denoting whether the user has administrator privileges
* - lang: A BCP 47 language tag e.g. "en", "hy-Latn-IT-arevela" * - lang: A BCP 47 language tag e.g. "en", "hy-Latn-IT-arevela"
* - tz: A zoneinfo timezone e.g. "Asia/Jakarta", "America/Argentina/La_Rioja" * - tz: A zoneinfo timezone e.g. "Asia/Jakarta", "America/Argentina/La_Rioja"
* - sort_asc: A boolean denoting whether the user prefers articles to be sorted oldest-first * - sort_asc: A boolean denoting whether the user prefers articles to be sorted oldest-first
* *
* Any other keys will be ignored. * Any other keys will be ignored.
*/ */
public function userPropertiesGet(string $user): array; public function userPropertiesGet(string $user): array;
/** Sets metadata about a user /** Sets metadata about a user
* *
* Output should be the same as the input, unless input is changed prior to storage * Output should be the same as the input, unless input is changed prior to storage
* (if it is, for instance, normalized in some way), which which case the changes * (if it is, for instance, normalized in some way), which which case the changes
* should be reflected in the output. * should be reflected in the output.
* *
* @param string $user The user for which to set metadata * @param string $user The user for which to set metadata
* @param array $data The input data; see userPropertiesGet for keys * @param array $data The input data; see userPropertiesGet for keys
*/ */

View file

@ -68,8 +68,8 @@ trait SeriesCleanup {
], ],
'arsse_icons' => [ 'arsse_icons' => [
'columns' => [ 'columns' => [
'id' => "int", 'id' => "int",
'url' => "str", 'url' => "str",
'orphaned' => "datetime", 'orphaned' => "datetime",
], ],
'rows' => [ 'rows' => [

View file

@ -104,12 +104,12 @@ trait SeriesUser {
$this->assertException("doesNotExist", "User", "ExceptionConflict"); $this->assertException("doesNotExist", "User", "ExceptionConflict");
Arsse::$db->userPasswordSet("john.doe@example.org", "secret"); Arsse::$db->userPasswordSet("john.doe@example.org", "secret");
} }
/** @dataProvider provideMetaData */ /** @dataProvider provideMetaData */
public function testGetMetadata(string $user, array $exp): void { public function testGetMetadata(string $user, array $exp): void {
$this->assertSame($exp, Arsse::$db->userPropertiesGet($user)); $this->assertSame($exp, Arsse::$db->userPropertiesGet($user));
} }
public function provideMetadata(): iterable { public function provideMetadata(): iterable {
return [ return [
["admin@example.net", ['num' => 1, 'admin' => true, 'lang' => "en", 'tz' => "America/Toronto", 'sort_asc' => false]], ["admin@example.net", ['num' => 1, 'admin' => true, 'lang' => "en", 'tz' => "America/Toronto", 'sort_asc' => false]],
@ -122,12 +122,12 @@ trait SeriesUser {
$this->assertException("doesNotExist", "User", "ExceptionConflict"); $this->assertException("doesNotExist", "User", "ExceptionConflict");
Arsse::$db->userPropertiesGet("john.doe@example.org"); Arsse::$db->userPropertiesGet("john.doe@example.org");
} }
public function testSetMetadata(): void { public function testSetMetadata(): void {
$in = [ $in = [
'admin' => true, 'admin' => true,
'lang' => "en-ca", 'lang' => "en-ca",
'tz' => "Atlantic/Reykjavik", 'tz' => "Atlantic/Reykjavik",
'sort_asc' => true, 'sort_asc' => true,
]; ];
$this->assertTrue(Arsse::$db->userPropertiesSet("john.doe@example.com", $in)); $this->assertTrue(Arsse::$db->userPropertiesSet("john.doe@example.com", $in));
@ -135,11 +135,11 @@ trait SeriesUser {
$state['arsse_users']['rows'][2] = ["john.doe@example.com", 3, 1, "en-ca", "Atlantic/Reykjavik", 1]; $state['arsse_users']['rows'][2] = ["john.doe@example.com", 3, 1, "en-ca", "Atlantic/Reykjavik", 1];
$this->compareExpectations(static::$drv, $state); $this->compareExpectations(static::$drv, $state);
} }
public function testSetNoMetadata(): void { public function testSetNoMetadata(): void {
$in = [ $in = [
'num' => 2112, 'num' => 2112,
'blah' => "bloo" 'blah' => "bloo",
]; ];
$this->assertFalse(Arsse::$db->userPropertiesSet("john.doe@example.com", $in)); $this->assertFalse(Arsse::$db->userPropertiesSet("john.doe@example.com", $in));
$state = $this->primeExpectations($this->data, ['arsse_users' => ['id', 'num', 'admin', 'lang', 'tz', 'sort_asc']]); $state = $this->primeExpectations($this->data, ['arsse_users' => ['id', 'num', 'admin', 'lang', 'tz', 'sort_asc']]);

View file

@ -134,10 +134,11 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
$this->drv->schemaUpdate(Database::SCHEMA_VERSION); $this->drv->schemaUpdate(Database::SCHEMA_VERSION);
$this->assertTrue($this->drv->maintenance()); $this->assertTrue($this->drv->maintenance());
} }
public function testUpdateTo7(): void { public function testUpdateTo7(): void {
$this->drv->schemaUpdate(6); $this->drv->schemaUpdate(6);
$this->drv->exec(<<<QUERY_TEXT $this->drv->exec(
<<<QUERY_TEXT
INSERT INTO arsse_users values('a', 'xyz'); INSERT INTO arsse_users values('a', 'xyz');
INSERT INTO arsse_users values('b', 'abc'); INSERT INTO arsse_users values('b', 'abc');
INSERT INTO arsse_folders(owner,name) values('a', '1'); INSERT INTO arsse_folders(owner,name) values('a', '1');

View file

@ -121,14 +121,14 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertException("doesNotExist", "User", "ExceptionConflict"); $this->assertException("doesNotExist", "User", "ExceptionConflict");
(new Driver)->userPasswordUnset("john.doe@example.com"); (new Driver)->userPasswordUnset("john.doe@example.com");
} }
public function testGetUserProperties(): void { public function testGetUserProperties(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(true); \Phake::when(Arsse::$db)->userExists->thenReturn(true);
$this->assertSame([], (new Driver)->userPropertiesGet("john.doe@example.com")); $this->assertSame([], (new Driver)->userPropertiesGet("john.doe@example.com"));
\Phake::verify(Arsse::$db)->userExists("john.doe@example.com"); \Phake::verify(Arsse::$db)->userExists("john.doe@example.com");
\Phake::verifyNoFurtherInteraction(Arsse::$db); \Phake::verifyNoFurtherInteraction(Arsse::$db);
} }
public function testGetPropertiesForAMissingUser(): void { public function testGetPropertiesForAMissingUser(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(false); \Phake::when(Arsse::$db)->userExists->thenReturn(false);
$this->assertException("doesNotExist", "User", "ExceptionConflict"); $this->assertException("doesNotExist", "User", "ExceptionConflict");
@ -139,7 +139,7 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verifyNoFurtherInteraction(Arsse::$db); \Phake::verifyNoFurtherInteraction(Arsse::$db);
} }
} }
public function testSetUserProperties(): void { public function testSetUserProperties(): void {
$in = ['admin' => true]; $in = ['admin' => true];
\Phake::when(Arsse::$db)->userExists->thenReturn(true); \Phake::when(Arsse::$db)->userExists->thenReturn(true);
@ -147,7 +147,7 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userExists("john.doe@example.com"); \Phake::verify(Arsse::$db)->userExists("john.doe@example.com");
\Phake::verifyNoFurtherInteraction(Arsse::$db); \Phake::verifyNoFurtherInteraction(Arsse::$db);
} }
public function testSetPropertiesForAMissingUser(): void { public function testSetPropertiesForAMissingUser(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(false); \Phake::when(Arsse::$db)->userExists->thenReturn(false);
$this->assertException("doesNotExist", "User", "ExceptionConflict"); $this->assertException("doesNotExist", "User", "ExceptionConflict");

View file

@ -9,7 +9,6 @@ namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Database; use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\User; use JKingWeb\Arsse\User;
use JKingWeb\Arsse\AbstractException as Exception;
use JKingWeb\Arsse\User\ExceptionConflict; use JKingWeb\Arsse\User\ExceptionConflict;
use JKingWeb\Arsse\User\ExceptionInput; use JKingWeb\Arsse\User\ExceptionInput;
use JKingWeb\Arsse\User\Driver; use JKingWeb\Arsse\User\Driver;
@ -25,7 +24,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
// create a mock user driver // create a mock user driver
$this->drv = \Phake::mock(Driver::class); $this->drv = \Phake::mock(Driver::class);
} }
public function tearDown(): void { public function tearDown(): void {
\Phake::verifyNoOtherInteractions($this->drv); \Phake::verifyNoOtherInteractions($this->drv);
\Phake::verifyNoOtherInteractions(Arsse::$db); \Phake::verifyNoOtherInteractions(Arsse::$db);
@ -159,7 +158,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify($this->drv)->userAdd($user, $pass); \Phake::verify($this->drv)->userAdd($user, $pass);
\Phake::verify(Arsse::$db)->userExists($user); \Phake::verify(Arsse::$db)->userExists($user);
} }
public function testRemoveAUser(): void { public function testRemoveAUser(): void {
$user = "john.doe@example.com"; $user = "john.doe@example.com";
$pass = "secret"; $pass = "secret";
@ -171,7 +170,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userRemove($user); \Phake::verify(Arsse::$db)->userRemove($user);
\Phake::verify($this->drv)->userRemove($user); \Phake::verify($this->drv)->userRemove($user);
} }
public function testRemoveAUserWeDoNotKnow(): void { public function testRemoveAUserWeDoNotKnow(): void {
$user = "john.doe@example.com"; $user = "john.doe@example.com";
$pass = "secret"; $pass = "secret";
@ -182,7 +181,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userExists($user); \Phake::verify(Arsse::$db)->userExists($user);
\Phake::verify($this->drv)->userRemove($user); \Phake::verify($this->drv)->userRemove($user);
} }
public function testRemoveAMissingUser(): void { public function testRemoveAMissingUser(): void {
$user = "john.doe@example.com"; $user = "john.doe@example.com";
$pass = "secret"; $pass = "secret";
@ -198,7 +197,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify($this->drv)->userRemove($user); \Phake::verify($this->drv)->userRemove($user);
} }
} }
public function testRemoveAMissingUserWeDoNotKnow(): void { public function testRemoveAMissingUserWeDoNotKnow(): void {
$user = "john.doe@example.com"; $user = "john.doe@example.com";
$pass = "secret"; $pass = "secret";

View file

@ -1,4 +1,4 @@
<?php return [ <?php return [
'mime' => "image/svg+xml", 'mime' => "image/svg+xml",
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect fill="#fff" height="600" width="900"/><circle fill="#bc002d" cx="450" cy="300" r="180"/></svg>' 'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect fill="#fff" height="600" width="900"/><circle fill="#bc002d" cx="450" cy="300" r="180"/></svg>',
]; ];

View file

@ -1,4 +1,4 @@
<?php return [ <?php return [
'mime' => "image/svg+xml", 'mime' => "image/svg+xml",
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#ED2939"/><rect width="600" height="600" fill="#fff"/><rect width="300" height="600" fill="#002395"/></svg>' 'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#ED2939"/><rect width="600" height="600" fill="#fff"/><rect width="300" height="600" fill="#002395"/></svg>',
]; ];