Add psalm static analysis

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/1377/head
Carl Schwan 2022-04-15 15:01:27 +02:00
rodzic 9e20993c4d
commit 46df90a0fb
46 zmienionych plików z 1373 dodań i 879 usunięć

Wyświetl plik

@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.4", "8.0"]
php-versions: ["7.4", "8.0", "8.1"]
name: php-lint

Wyświetl plik

@ -0,0 +1,26 @@
name: Static analysis
on: [pull_request]
jobs:
static-psalm-analysis:
runs-on: ubuntu-latest
strategy:
matrix:
ocp-version: [ 'dev-master' ]
name: Nextcloud ${{ matrix.ocp-version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up php
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v1
coverage: none
- name: Install dependencies
run: composer i
- name: Install dependencies
run: composer require --dev christophwurst/nextcloud:${{ matrix.ocp-version }}
- name: Run coding standards check
run: composer run psalm

Wyświetl plik

@ -28,8 +28,6 @@
"friendica/json-ld": "^1.0"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "^1.0",
"rector/rector": "^0.12.20",
"phpunit/phpunit": "^9.5",
"nextcloud/coding-standard": "^1.0.0",
"christophwurst/nextcloud": "dev-master",
@ -39,7 +37,7 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm --threads=1",
"psalm": "psalm --threads=1 --update-baseline",
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
"psalm:clear": "psalm --clear-cache && psalm --clear-global-cache",
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"

174
composer.lock wygenerowano
Wyświetl plik

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "303af33a7156caaf44b7a28ce25c7755",
"content-hash": "c9f825ade4c2baa82438409e058171bc",
"packages": [
{
"name": "daita/my-small-php-tools",
@ -1097,59 +1097,6 @@
],
"time": "2022-03-18T17:20:59+00:00"
},
{
"name": "jakub-onderka/php-parallel-lint",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/JakubOnderka/PHP-Parallel-Lint.git",
"reference": "04fbd3f5fb1c83f08724aa58a23db90bd9086ee8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/JakubOnderka/PHP-Parallel-Lint/zipball/04fbd3f5fb1c83f08724aa58a23db90bd9086ee8",
"reference": "04fbd3f5fb1c83f08724aa58a23db90bd9086ee8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"jakub-onderka/php-console-highlighter": "~0.3",
"nette/tester": "~1.3",
"squizlabs/php_codesniffer": "~2.7"
},
"suggest": {
"jakub-onderka/php-console-highlighter": "Highlight syntax in code snippet"
},
"bin": [
"parallel-lint"
],
"type": "library",
"autoload": {
"classmap": [
"./"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Jakub Onderka",
"email": "ahoj@jakubonderka.cz"
}
],
"description": "This tool check syntax of PHP files about 20x faster than serial check.",
"homepage": "https://github.com/JakubOnderka/PHP-Parallel-Lint",
"support": {
"issues": "https://github.com/JakubOnderka/PHP-Parallel-Lint/issues",
"source": "https://github.com/JakubOnderka/PHP-Parallel-Lint/tree/master"
},
"abandoned": "php-parallel-lint/php-parallel-lint",
"time": "2018-02-24T15:31:20+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.11.0",
@ -1800,65 +1747,6 @@
},
"time": "2021-12-08T12:19:24+00:00"
},
{
"name": "phpstan/phpstan",
"version": "1.5.5",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "d77a607667f29ae099c0686f99664bd451fd23df"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/d77a607667f29ae099c0686f99664bd451fd23df",
"reference": "d77a607667f29ae099c0686f99664bd451fd23df",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.5.5"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://www.patreon.com/phpstan",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2022-04-14T12:20:26+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.15",
@ -2477,66 +2365,6 @@
},
"time": "2021-05-03T11:20:27+00:00"
},
{
"name": "rector/rector",
"version": "0.12.20",
"source": {
"type": "git",
"url": "https://github.com/rectorphp/rector.git",
"reference": "cfa8d3e236a6e1a41d69712a84d434dfdf70e560"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/cfa8d3e236a6e1a41d69712a84d434dfdf70e560",
"reference": "cfa8d3e236a6e1a41d69712a84d434dfdf70e560",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0",
"phpstan/phpstan": "^1.5"
},
"conflict": {
"phpstan/phpdoc-parser": "<1.2",
"rector/rector-cakephp": "*",
"rector/rector-doctrine": "*",
"rector/rector-laravel": "*",
"rector/rector-nette": "*",
"rector/rector-phpoffice": "*",
"rector/rector-phpunit": "*",
"rector/rector-prefixed": "*",
"rector/rector-symfony": "*"
},
"bin": [
"bin/rector"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "0.12-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Instant Upgrade and Automated Refactoring of any PHP code",
"support": {
"issues": "https://github.com/rectorphp/rector/issues",
"source": "https://github.com/rectorphp/rector/tree/0.12.20"
},
"funding": [
{
"url": "https://github.com/tomasvotruba",
"type": "github"
}
],
"time": "2022-04-06T12:55:14+00:00"
},
{
"name": "sebastian/cli-parser",
"version": "1.0.1",

Wyświetl plik

@ -32,7 +32,6 @@ declare(strict_types=1);
namespace OCA\Social\AppInfo;
use Closure;
use OC\DB\SchemaWrapper;
use OCA\Social\Notification\Notifier;
use OCA\Social\Search\UnifiedSearchProvider;
use OCA\Social\Service\ConfigService;
@ -45,6 +44,8 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException;
use OCP\IDBConnection;
use OCP\IServerContainer;
use OC\DB\SchemaWrapper;
use OCP\DB\ISchemaWrapper;
use Throwable;
require_once __DIR__ . '/../../vendor/autoload.php';
@ -106,6 +107,7 @@ class Application extends App implements IBootstrap {
return;
}
/** @var ISchemaWrapper $schema */
$schema = new SchemaWrapper($container->get(IDBConnection::class));
if ($schema->hasTable('social_a2_stream')) {
$updateService->checkUpdateStatus();

Wyświetl plik

@ -175,7 +175,7 @@ class CheckInstall extends Base {
return true;
}
private function regenerateIndex(OutputInterface $output) {
private function regenerateIndex(OutputInterface $output): void {
$streams = $this->streamRequest->getAll();
$progressBar = new ProgressBar($output, count($streams));
$progressBar->start();

Wyświetl plik

@ -49,22 +49,10 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class NoteBoost extends Base {
private StreamService $streamService;
private AccountService $accountService;
private BoostService $boostService;
private MiscService $miscService;
/**
* NoteBoost constructor.
*
* @param AccountService $accountService
* @param StreamService $streamService
* @param BoostService $boostService
* @param MiscService $miscService
*/
public function __construct(
AccountService $accountService, StreamService $streamService, BoostService $boostService,
MiscService $miscService
@ -104,6 +92,7 @@ class NoteBoost extends Base {
$actor = $this->accountService->getActorFromUserId($userId);
$this->streamService->setViewer($actor);
$token = '';
if (!$input->getOption('unboost')) {
$activity = $this->boostService->create($actor, $noteId, $token);
} else {

Wyświetl plik

@ -137,6 +137,7 @@ class NoteCreate extends Base {
$post->addTo(($to === null) ? '' : $to);
$post->setHashtags(($hashtag === null) ? [] : [$hashtag]);
$token = '';
$activity = $this->postService->createPost($post, $token);
echo 'object: ' . json_encode($activity, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";

Wyświetl plik

@ -104,6 +104,7 @@ class NoteLike extends Base {
$actor = $this->accountService->getActorFromUserId($userId);
$this->streamService->setViewer($actor);
$token = '';
if (!$input->getOption('unlike')) {
$activity = $this->likeService->create($actor, $noteId, $token);
} else {

Wyświetl plik

@ -125,6 +125,7 @@ class LocalController extends Controller {
$post->setHashtags($this->getArray('hashtags', $data, []));
$post->setAttachments($this->getArray('attachments', $data, []));
$token = '';
$activity = $this->postService->createPost($post, $token);
return $this->success(
@ -209,6 +210,7 @@ class LocalController extends Controller {
public function postBoost(string $postId): DataResponse {
try {
$this->initViewer(true);
$token = '';
$announce = $this->boostService->create($this->viewer, $postId, $token);
return $this->success(
@ -231,6 +233,7 @@ class LocalController extends Controller {
public function postUnboost(string $postId): DataResponse {
try {
$this->initViewer(true);
$token = '';
$announce = $this->boostService->delete($this->viewer, $postId, $token);
return $this->success(
@ -253,6 +256,7 @@ class LocalController extends Controller {
public function postLike(string $postId): DataResponse {
try {
$this->initViewer(true);
$token = '';
$announce = $this->likeService->create($this->viewer, $postId, $token);
return $this->success(
@ -275,6 +279,7 @@ class LocalController extends Controller {
public function postUnlike(string $postId): DataResponse {
try {
$this->initViewer(true);
$token = '';
$like = $this->likeService->delete($this->viewer, $postId, $token);
return $this->success(

Wyświetl plik

@ -74,6 +74,7 @@ class NavigationController extends Controller {
private MiscService $miscService;
private IL10N $l10n;
private CheckService $checkService;
private IInitialStateService $initialStateService;
public function __construct(
IL10N $l10n,

Wyświetl plik

@ -140,10 +140,11 @@ class OAuthController extends Controller {
/**
* @NoCSRFRequired
* @PublicPage
* @param array|string $redirect_uris
* @throws ClientException
*/
public function apps(
string $client_name = '', string $redirect_uris = '', string $website = '', string $scopes = 'read'
string $client_name = '', $redirect_uris = '', string $website = '', string $scopes = 'read'
): DataResponse {
// TODO: manage array from request
if (!is_array($redirect_uris)) {

Wyświetl plik

@ -67,6 +67,7 @@ class SocialPubController extends Controller {
private CacheActorService $cacheActorService;
private StreamService $streamService;
private ConfigService $configService;
private IInitialStateService $initialStateService;
public function __construct(
?string $userId, IInitialStateService $initialStateService, IRequest $request, IL10N $l10n, NavigationController $navigationController,

Wyświetl plik

@ -32,7 +32,7 @@ declare(strict_types=1);
namespace OCA\Social\Cron;
use Exception;
use OC\AppFramework\Utility\TimeFactory;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\Social\AppInfo\Application;
use OCA\Social\Service\AccountService;
@ -52,7 +52,7 @@ class Cache extends TimedJob {
private ?DocumentService $documentService = null;
private ?HashtagService $hashtagService = null;
public function __construct(TimeFactory $time) {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->setInterval(12 * 60); // 12 minutes
}

Wyświetl plik

@ -31,11 +31,10 @@ declare(strict_types=1);
namespace OCA\Social\Cron;
use OC\AppFramework\Utility\TimeFactory;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\Social\AppInfo\Application;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\AppFramework\QueryException;
/**
@ -46,7 +45,7 @@ use OCP\AppFramework\QueryException;
class Chunk extends TimedJob {
private ?ConfigService $configService = null;
public function __construct(TimeFactory $time) {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->setInterval(12 * 3600); // 12 hours
}
@ -62,7 +61,6 @@ class Chunk extends TimedJob {
$c = $app->getContainer();
$this->configService = $c->query(ConfigService::class);
$this->miscService = $c->query(MiscService::class);
$size = (int)$this->configService->getAppValue(ConfigService::DATABASE_CHUNK_SIZE);
$this->morphChunks($size);

Wyświetl plik

@ -31,12 +31,11 @@ declare(strict_types=1);
namespace OCA\Social\Cron;
use OC\AppFramework\Utility\TimeFactory;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\RequestQueueService;
use OCA\Social\Service\StreamQueueService;
use OCP\AppFramework\QueryException;
@ -51,11 +50,10 @@ class Queue extends TimedJob {
private ?RequestQueueService $requestQueueService = null;
private ?StreamQueueService $streamQueueService = null;
/**
* Cache constructor.
*/
public function __construct(TimeFactory $time) {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->setInterval(12 * 60); // 12 minutes
}
@ -74,7 +72,6 @@ class Queue extends TimedJob {
$this->requestQueueService = $c->get(RequestQueueService::class);
$this->streamQueueService = $c->get(StreamQueueService::class);
$this->activityService = $c->get(ActivityService::class);
$this->miscService = $c->get(MiscService::class);
$this->manageRequestQueue();
$this->manageStreamQueue();

Wyświetl plik

@ -69,7 +69,7 @@ class ActionsRequest extends ActionsRequestBuilder {
$this->generatePrimaryKey($qb, $like->getId());
$qb->execute();
$qb->executeStatement();
}

Wyświetl plik

@ -118,8 +118,8 @@ class ActionsRequestBuilder extends CoreRequestBuilder {
* @throws ActionDoesNotExistException
*/
protected function getActionFromRequest(SocialQueryBuilder $qb): ACore {
/** @var ACore $result */
try {
/** @var ACore $result */
$result = $qb->getRow([$this, 'parseActionsSelectSql']);
} catch (RowNotFoundException $e) {
throw new ActionDoesNotExistException($e->getMessage());

Wyświetl plik

@ -31,22 +31,20 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use DateTime;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Exception as DBException;
class CacheActorsRequest extends CacheActorsRequestBuilder {
public const CACHE_TTL = 60 * 24; // 1d
/**
* insert cache about an Actor in database.
*
* @param Person $actor
* Insert cache about an Actor in database.
*/
public function save(Person $actor) {
public function save(Person $actor): void {
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('id_prim', $qb->createNamedParameter($this->prim($actor->getId())))
@ -95,18 +93,14 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
$qb->generatePrimaryKey($actor->getId());
try {
$qb->execute();
} catch (UniqueConstraintViolationException $e) {
$qb->executeStatement();
} catch (DBException $e) {
}
}
/**
* insert cache about an Actor in database.
*
* @param Person $actor
*
* @return int
* Insert cache about an Actor in database.
*/
public function update(Person $actor): int {
$qb = $this->getCacheActorsUpdateSql();
@ -151,7 +145,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
$this->limitToIdString($qb, $actor->getId());
return $qb->execute();
return $qb->executeStatement();
}
@ -202,6 +196,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
$qb = $this->getCacheActorsSelectSql();
$this->limitToPreferredUsername($qb, $account);
$this->limitToLocal($qb, true);
/** @var SocialQueryBuilder $qb */
$qb->leftJoinCacheDocuments('icon_id');
$this->leftJoinDetails($qb);
@ -217,6 +212,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
public function searchAccounts(string $search): array {
$qb = $this->getCacheActorsSelectSql();
$this->searchInAccount($qb, $search);
/** @var SocialQueryBuilder $qb */
$qb->leftJoinCacheDocuments('icon_id');
$this->leftJoinDetails($qb);
$this->limitResults($qb, 25);

Wyświetl plik

@ -38,6 +38,7 @@ use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OC;
use OC\DB\SchemaWrapper;
use OCP\DB\ISchemaWrapper;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Follow;
@ -109,7 +110,6 @@ class CoreRequestBuilder {
) {
$this->dbConnection = $connection;
$this->logger = $logger;
$this->loggerInterface = $logger;
$this->urlGenerator = $urlGenerator;
$this->configService = $configService;
$this->miscService = $miscService;
@ -122,7 +122,7 @@ class CoreRequestBuilder {
public function getQueryBuilder(): SocialQueryBuilder {
$qb = new SocialQueryBuilder(
$this->dbConnection,
OC::$server->getSystemConfig(),
OC::$server->get(\OC\SystemConfig::class),
$this->logger,
$this->urlGenerator
);
@ -729,20 +729,11 @@ class CoreRequestBuilder {
}
/**
* @param IQueryBuilder $qb
* @param string $field
* @param array $values
*/
protected function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) {
protected function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values): void {
$expr = $qb->expr();
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
$field = $pf . $field;
if (!is_array($values)) {
$values = [$values];
}
$orX = $expr->orX();
foreach ($values as $value) {
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
@ -1185,6 +1176,7 @@ class CoreRequestBuilder {
* this just empty all tables from the app.
*/
public function uninstallSocialTables() {
/** @var ISchemaWrapper|SchemaWrapper $schema */
$schema = new SchemaWrapper($this->dbConnection);
foreach ($this->tables as $table) {
if ($schema->hasTable($table)) {

Wyświetl plik

@ -43,11 +43,9 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
/**
* create a new Queue in the database.
*
* @param StreamAction $action
* Create a new Queue in the database.
*/
public function create(StreamAction $action) {
public function create(StreamAction $action): void {
$qb = $this->getStreamActionInsertSql();
$values = $action->getValues();
@ -68,16 +66,12 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
->setValue('boosted', $qb->createNamedParameter(($boosted) ? 1 : 0))
->setValue('replied', $qb->createNamedParameter(($replied) ? 1 : 0));
$qb->execute();
$qb->executeStatement();
}
/**
* create a new Queue in the database.
*
* @param StreamAction $action
*
* @return int
* Create a new Queue in the database.
*/
public function update(StreamAction $action): int {
$qb = $this->getStreamActionUpdateSql();
@ -95,15 +89,11 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
$this->limitToActorId($qb, $action->getActorId());
$this->limitToStreamId($qb, $action->getStreamId());
return $qb->execute();
return $qb->executeStatement();
}
/**
* @param string $actorId
* @param string $streamId
*
* @return StreamAction
* @throws StreamActionDoesNotExistException
*/
public function getAction(string $actorId, string $streamId): StreamAction {
@ -111,7 +101,7 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
$this->limitToActorId($qb, $actorId);
$this->limitToStreamId($qb, $streamId);
$cursor = $qb->execute();
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
if ($data === false) {
throw new StreamActionDoesNotExistException();
@ -121,15 +111,11 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
return $this->parseStreamActionsSelectSql($data);
}
/**
* @param StreamAction $action
*/
public function delete(StreamAction $action) {
public function delete(StreamAction $action): void {
$qb = $this->getStreamActionDeleteSql();
$this->limitToActorId($qb, $action->getActorId());
$this->limitToStreamId($qb, $action->getStreamId());
$qb->execute();
$qb->executeStatement();
}
}

Wyświetl plik

@ -32,8 +32,8 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TStringTools;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use OCP\DB\Exception as DBException;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\CacheActorService;
@ -71,16 +71,12 @@ class StreamDestRequest extends StreamDestRequestBuilder {
$qb->setValue('subtype', $qb->createNamedParameter($subType));
try {
$qb->execute();
} catch (UniqueConstraintViolationException $e) {
$qb->executeStatement();
} catch (DBException $e) {
}
}
/**
* @param Stream $stream
*/
public function generateStreamDest(Stream $stream) {
public function generateStreamDest(Stream $stream): void {
if ($this->generateStreamNotification($stream)) {
return;
}
@ -92,12 +88,6 @@ class StreamDestRequest extends StreamDestRequestBuilder {
$this->generateStreamHome($stream);
}
/**
* @param Stream $stream
*
* @return bool
*/
private function generateStreamHome(Stream $stream): bool {
$recipients =
[
@ -118,12 +108,6 @@ class StreamDestRequest extends StreamDestRequestBuilder {
return true;
}
/**
* @param Stream $stream
*
* @return bool
*/
private function generateStreamDirect(Stream $stream): bool {
try {
$author = $this->cacheActorService->getFromId($stream->getAttributedTo());
@ -152,12 +136,6 @@ class StreamDestRequest extends StreamDestRequestBuilder {
return true;
}
/**
* @param Stream $stream
*
* @return bool
*/
private function generateStreamNotification(Stream $stream): bool {
if ($stream->getType() !== SocialAppNotification::TYPE) {
return false;
@ -174,14 +152,10 @@ class StreamDestRequest extends StreamDestRequestBuilder {
return true;
}
/**
*
*/
public function emptyStreamDest() {
public function emptyStreamDest(): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_STREAM_DEST);
$qb->execute();
$qb->executeStatement();
}
}

Wyświetl plik

@ -44,8 +44,6 @@ class StreamDestRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Insert request
*
* @return IQueryBuilder
*/
protected function getStreamDestInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();

Wyświetl plik

@ -33,8 +33,8 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Exceptions\DateTimeException;
use daita\MySmallPhpTools\Model\Cache;
use DateTime;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use OCP\DB\Exception as DBException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
@ -70,11 +70,7 @@ class StreamRequest extends StreamRequestBuilder {
$this->streamTagsRequest = $streamTagsRequest;
}
/**
* @param Stream $stream
*/
public function save(Stream $stream) {
public function save(Stream $stream): void {
$qb = $this->saveStream($stream);
if ($stream->getType() === Note::TYPE) {
/** @var Note $stream */
@ -87,19 +83,15 @@ class StreamRequest extends StreamRequestBuilder {
}
try {
$qb->execute();
$qb->executeStatement();
$this->streamDestRequest->generateStreamDest($stream);
$this->streamTagsRequest->generateStreamTags($stream);
} catch (UniqueConstraintViolationException $e) {
} catch (DBException $e) {
}
}
/**
* @param Stream $stream \
*/
public function update(Stream $stream) {
public function update(Stream $stream): void {
$qb = $this->getStreamUpdateSql();
$qb->set('details', $qb->createNamedParameter(json_encode($stream->getDetailsAll())));
@ -109,34 +101,25 @@ class StreamRequest extends StreamRequestBuilder {
)
);
$qb->limitToIdPrim($qb->prim($stream->getId()));
$qb->execute();
$qb->executeStatement();
$this->streamDestRequest->generateStreamDest($stream);
}
/**
* @param Stream $stream
* @param Cache $cache
*/
public function updateCache(Stream $stream, Cache $cache) {
public function updateCache(Stream $stream, Cache $cache): void {
$qb = $this->getStreamUpdateSql();
$qb->set('cache', $qb->createNamedParameter(json_encode($cache, JSON_UNESCAPED_SLASHES)));
$qb->limitToIdPrim($qb->prim($stream->getId()));
$qb->execute();
$qb->executeStatement();
}
/**
* @param Document $document
*/
public function updateAttachments(Document $document) {
public function updateAttachments(Document $document): void {
$qb = $this->getStreamSelectSql();
$qb->limitToIdPrim($qb->prim($document->getParentId()));
$cursor = $qb->execute();
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
$cursor->closeCursor();
@ -149,13 +132,10 @@ class StreamRequest extends StreamRequestBuilder {
$qb->set('attachments', $qb->createNamedParameter(json_encode($new, JSON_UNESCAPED_SLASHES)));
$qb->limitToIdPrim($qb->prim($document->getParentId()));
$qb->execute();
$qb->executeStatement();
}
/**
* @param Document $document
* @param array $attachments
*
* @return Document[]
*/
private function updateAttachmentInList(Document $document, array $attachments): array {
@ -174,18 +154,14 @@ class StreamRequest extends StreamRequestBuilder {
}
/**
* @param string $itemId
* @param string $to
*/
public function updateAttributedTo(string $itemId, string $to) {
public function updateAttributedTo(string $itemId, string $to): void {
$qb = $this->getStreamUpdateSql();
$qb->set('attributed_to', $qb->createNamedParameter($to));
$qb->set('attributed_to_prim', $qb->createNamedParameter($qb->prim($to)));
$qb->limitToIdPrim($qb->prim($itemId));
$qb->execute();
$qb->executeStatement();
}

Wyświetl plik

@ -32,9 +32,9 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TStringTools;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCP\DB\Exception as DBException;
/**
* Class StreamTagsRequest
@ -44,11 +44,7 @@ use OCA\Social\Model\ActivityPub\Stream;
class StreamTagsRequest extends StreamTagsRequestBuilder {
use TStringTools;
/**
* @param Stream $stream
*/
public function generateStreamTags(Stream $stream) {
public function generateStreamTags(Stream $stream): void {
if ($stream->getType() !== Note::TYPE) {
return;
}
@ -60,22 +56,18 @@ class StreamTagsRequest extends StreamTagsRequestBuilder {
$qb->setValue('stream_id', $qb->createNamedParameter($streamId));
$qb->setValue('hashtag', $qb->createNamedParameter($hashtag));
try {
$qb->execute();
} catch (UniqueConstraintViolationException $e) {
$qb->executeStatement();
} catch (DBException $e) {
\OC::$server->getLogger()
->log(1, 'Social - Duplicate hashtag on Stream ' . json_encode($stream));
}
}
}
/**
*
*/
public function emptyStreamTags() {
public function emptyStreamTags(): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_STREAM_TAGS);
$qb->execute();
$qb->executeStatement();
}
}

Wyświetl plik

@ -54,30 +54,13 @@ use OCA\Social\Service\MiscService;
class PersonInterface implements IActivityPubInterface {
use TArrayTools;
private CacheActorsRequest $cacheActorsRequest;
private StreamRequest $streamRequest;
private FollowsRequest $followsRequest;
private ActorService $actorService;
private ConfigService $configService;
private MiscService $miscService;
/**
* UndoService constructor.
*
* @param CacheActorsRequest $cacheActorsRequest
* @param StreamRequest $streamRequest
* @param FollowsRequest $followsRequest
* @param ActorService $actorService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest,
FollowsRequest $followsRequest, ActorService $actorService, ConfigService $configService,
@ -91,25 +74,15 @@ class PersonInterface implements IActivityPubInterface {
$this->miscService = $miscService;
}
/**
* @param ACore $person
*/
public function processIncomingRequest(ACore $person) {
public function processIncomingRequest(ACore $item) {
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
}
/**
* @param ACore $item
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItem(ACore $item): ACore {
@ -149,12 +122,9 @@ class PersonInterface implements IActivityPubInterface {
}
}
/**
* @param ACore $person
*/
public function save(ACore $person) {
public function save(ACore $item) {
/** @var Person $person */
$person = $item;
try {
$this->getItemById($person->getId());
$this->actorService->update($person);
@ -163,17 +133,9 @@ class PersonInterface implements IActivityPubInterface {
}
}
/**
* @param ACore $item
*/
public function update(ACore $item) {
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
/** @var Person $item */
$this->cacheActorsRequest->deleteCacheById($item->getId());
@ -181,19 +143,9 @@ class PersonInterface implements IActivityPubInterface {
$this->followsRequest->deleteRelatedId($item->getId());
}
/**
* @param ACore $item
* @param string $source
*/
public function event(ACore $item, string $source) {
}
/**
* @param Person $actor
* @param ACore $activity
*/
private function updateActor(Person $actor, ACore $activity) {
$actor->setCreation($activity->getOriginCreationTime());

Wyświetl plik

@ -73,7 +73,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
/**
* @param ACore $note
*/
public function processIncomingRequest(ACore $note) {
public function processIncomingRequest(ACore $item) {
}
@ -113,12 +113,9 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
public function activity(Acore $activity, ACore $item) {
}
/**
* @param ACore $notification
*/
public function save(ACore $notification) {
public function save(ACore $item) {
/** @var SocialAppNotification $notification */
$notification = $item;
if ($notification->getId() === '') {
return;
}
@ -132,12 +129,9 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
$this->streamRequest->save($notification);
}
/**
* @param ACore $notification
*/
public function update(ACore $notification) {
public function update(ACore $item) {
/** @var SocialAppNotification $notification */
$notification = $item;
$this->miscService->log(
'Updating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1
);

Wyświetl plik

@ -149,8 +149,9 @@ class AnnounceInterface implements IActivityPubInterface {
* @throws RequestServerException
* @throws UnauthorizedFediverseException
*/
public function activity(Acore $activity, ACore $announce) {
public function activity(Acore $activity, ACore $item) {
/** @var Announce $announce */
$announce = $item;
if ($activity->getType() === Undo::TYPE) {
$activity->checkOrigin($announce->getId());
$activity->checkOrigin($announce->getActorId());

Wyświetl plik

@ -69,28 +69,12 @@ use OCA\Social\Service\MiscService;
*/
class FollowInterface implements IActivityPubInterface {
private FollowsRequest $followsRequest;
private CacheActorService $cacheActorService;
private AccountService $accountService;
private ActivityService $activityService;
private ConfigService $configService;
private MiscService $miscService;
/**
* NoteInterface constructor.
*
* @param FollowsRequest $followsRequest
* @param CacheActorService $cacheActorService
* @param AccountService $accountService
* @param ActivityService $activityService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
FollowsRequest $followsRequest, CacheActorService $cacheActorService,
AccountService $accountService, ActivityService $activityService,
@ -104,17 +88,9 @@ class FollowInterface implements IActivityPubInterface {
$this->miscService = $miscService;
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
}
/**
* @param Follow $follow
*/
public function confirmFollowRequest(Follow $follow) {
try {
$remoteActor = $this->cacheActorService->getFromId($follow->getActorId());
@ -165,8 +141,9 @@ class FollowInterface implements IActivityPubInterface {
* @throws RequestResultNotJsonException
* @throws Exception
*/
public function processIncomingRequest(ACore $follow) {
public function processIncomingRequest(ACore $item) {
/** @var Follow $follow */
$follow = $item;
$follow->checkOrigin($follow->getActorId());
try {

Wyświetl plik

@ -88,12 +88,13 @@ class LikeInterface implements IActivityPubInterface {
/**
* @param ACore $like
* @param ACore $item
*
* @throws InvalidOriginException
*/
public function processIncomingRequest(ACore $like) {
public function processIncomingRequest(ACore $item) {
/** @var Like $like */
$like = $item;
$like->checkOrigin($like->getId());
$like->checkOrigin($like->getActorId());
@ -110,8 +111,9 @@ class LikeInterface implements IActivityPubInterface {
*
* @throws InvalidOriginException
*/
public function activity(ACore $activity, ACore $like) {
public function activity(ACore $activity, ACore $item) {
/** @var Like $like */
$like = $item;
if ($activity->getType() === Undo::TYPE) {
$activity->checkOrigin($like->getId());
$activity->checkOrigin($like->getActorId());
@ -212,7 +214,9 @@ class LikeInterface implements IActivityPubInterface {
/**
* @param ACore $like
*/
private function undoLikeAction(ACore $like) {
private function undoLikeAction(ACore $item) {
/** @var Like $like */
$like = $item;
try {
if ($like->hasActor()) {
$actor = $like->getActor();

Wyświetl plik

@ -47,25 +47,11 @@ use OCA\Social\Service\PushService;
class NoteInterface implements IActivityPubInterface {
private StreamRequest $streamRequest;
private CurlService $curlService;
private PushService $pushService;
private ConfigService $configService;
private MiscService $miscService;
/**
* NoteInterface constructor.
*
* @param StreamRequest $streamRequest
* @param CurlService $curlService
* @param PushService $pushService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
StreamRequest $streamRequest, CurlService $curlService, PushService $pushService,
ConfigService $configService, MiscService $miscService
@ -77,36 +63,20 @@ class NoteInterface implements IActivityPubInterface {
$this->miscService = $miscService;
}
/**
* @param ACore $note
*/
public function processIncomingRequest(ACore $note) {
public function processIncomingRequest(ACore $item) {
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
}
/**
* @param ACore $item
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItem(ACore $item): ACore {
throw new ItemNotFoundException();
}
/**
* @param string $id
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
@ -140,13 +110,9 @@ class NoteInterface implements IActivityPubInterface {
}
}
/**
* @param ACore $note
*/
public function save(ACore $note) {
public function save(ACore $item) {
/** @var Note $note */
$note = $item;
try {
$this->streamRequest->getStreamById($note->getId());
} catch (StreamNotFoundException $e) {

Wyświetl plik

@ -37,163 +37,85 @@ use OCA\Social\Model\InstancePath;
class Item {
use TArrayTools;
private string $urlSocial = '';
private string $urlCloud = '';
private string $address = '';
private string $id = '';
private int $nid = 0;
private string $type = '';
private string $subType = '';
private string $url = '';
private string $attributedTo = '';
private string $summary = '';
/** @var InstancePath[] */
private array $instancePaths = [];
private string $to = '';
private array $toArray = [];
private array $cc = [];
private array $bcc = [];
private string $published = '';
private array $tags = [];
private ?Person $actor = null;
private string $actorId = '';
private string $iconId = '';
private string $objectId = '';
private bool $completeDetails = false;
private string $source = '';
private bool $local = false;
private string $origin = '';
private int $originSource = 0;
private int $originCreationTime = 0;
/**
* @return string
*/
public function getId(): string {
return $this->id;
}
/**
* @param string $id
*
* @return Item
*/
public function setId(string $id): Item {
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getNid(): int {
return $this->nid;
}
/**
* @param int $nid
*
* @return Item
*/
public function setNid(int $nid): self {
$this->nid = $nid;
return $this;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param string $type
*
* @return Item
*/
public function setType(string $type): Item {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getSubType(): string {
return $this->subType;
}
/**
* @param string $type
*
* @return Item
*/
public function setSubType(string $type): Item {
$this->subType = $type;
return $this;
}
/**
* @return string
*/
public function getUrl(): string {
return $this->url;
}
/**
* @param string $url
*
* @return Item
*/
public function setUrl(string $url): Item {
$this->url = $url;
return $this;
}
/**
* @param InstancePath $instancePath
*
* @return Item
*/
public function addInstancePath(InstancePath $instancePath): Item {
if ($instancePath->getUri() !== '') {
$this->instancePaths[] = $instancePath;
@ -202,11 +124,8 @@ class Item {
return $this;
}
/**
* @param InstancePath[] $path
*
* @return Item
*/
public function addInstancePaths(array $path): Item {
$this->instancePaths = array_merge($this->instancePaths, $path);
@ -232,10 +151,6 @@ class Item {
return $this;
}
/**
* @return string
*/
public function getSummary(): string {
return $this->summary;
}
@ -255,15 +170,10 @@ class Item {
/**
* @return Person
*/
public function getActor(): Person {
public function getActor(): ?Person {
return $this->actor;
}
/**
* @param Person $actor
*
* @return Item
*/
public function setActor(Person $actor): Item {
$this->actor = $actor;

Wyświetl plik

@ -51,7 +51,7 @@ class Announce extends Stream implements JsonSerializable {
*
* @param ACore $parent
*/
public function __construct($parent = null) {
public function __construct(?ACore $parent = null) {
parent::__construct($parent);
$this->setType(self::TYPE);

Wyświetl plik

@ -58,40 +58,26 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
public const TYPE_DIRECT = 'direct';
public const TYPE_ANNOUNCE = 'announce';
private string $activityId = '';
private string $content = '';
private string $spoilerText = '';
private string $language = 'en';
private string $attributedTo = '';
private string $inReplyTo = '';
private bool $sensitive = false;
private string $conversation = '';
private ?Cache $cache = null;
private int $publishedTime = 0;
private ?StreamAction $action = null;
private string $timeline = '';
private bool $filterDuplicate = false;
/**
* Stream constructor.
*
* @param null $parent
* @param ?ACore $parent
*/
public function __construct($parent = null) {
public function __construct(?ACore $parent = null) {
parent::__construct($parent);
}
@ -286,7 +272,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
/**
* @return Cache
*/
public function getCache(): Cache {
public function getCache(): ?Cache {
return $this->cache;
}
@ -315,19 +301,10 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
return $this;
}
/**
* @return StreamAction
*/
public function getAction(): StreamAction {
public function getAction(): ?StreamAction {
return $this->action;
}
/**
* @param StreamAction $action
*
* @return Stream
*/
public function setAction(StreamAction $action): Stream {
$this->action = $action;

Wyświetl plik

@ -107,18 +107,27 @@ class LinkedDataSignature implements JsonSerializable {
return $this->privateKey;
}
public function setPrivateKey(string $privateKey): LinkedDataSignature {
public function setPrivateKey(string $privateKey): self {
$this->privateKey = $privateKey;
return $this;
}
public function setPublicKey(string $publicKey): LinkedDataSignature {
public function setPublicKey(string $publicKey): self {
$this->publicKey = $publicKey;
return $this;
}
public function getObject(): array {
return $this->object;
}
public function setObject(array $object): self {
$this->object = $object;
return $this;
}
/**
* @throws LinkedDataSignatureMissingException
*/

Wyświetl plik

@ -49,169 +49,88 @@ class StreamAction implements JsonSerializable {
public const BOOSTED = 'boosted';
public const REPLIED = 'replied';
private int $id = 0;
private string $actorId = '';
private string $streamId = '';
private array $values = [];
/**
* StreamAction constructor.
*
* @param string $actorId
* @param string $streamId
*/
public function __construct(string $actorId = '', string $streamId = '') {
$this->actorId = $actorId;
$this->streamId = $streamId;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @param int $id
*
* @return StreamAction
*/
public function setId(int $id): StreamAction {
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getActorId(): string {
return $this->actorId;
}
/**
* @param string $actorId
*
* @return StreamAction
*/
public function setActorId(string $actorId): StreamAction {
$this->actorId = $actorId;
return $this;
}
/**
* @return string
*/
public function getStreamId(): string {
return $this->streamId;
}
/**
* @param string $streamId
*
* @return StreamAction
*/
public function setStreamId(string $streamId): StreamAction {
$this->streamId = $streamId;
return $this;
}
/**
* @param string $key
* @param string $value
*/
public function updateValue(string $key, string $value) {
public function updateValue(string $key, string $value): void {
$this->values[$key] = $value;
}
/**
* @param string $key
* @param int $value
*/
public function updateValueInt(string $key, int $value) {
public function updateValueInt(string $key, int $value): void {
$this->values[$key] = $value;
}
/**
* @param string $key
* @param bool $value
*/
public function updateValueBool(string $key, bool $value) {
public function updateValueBool(string $key, bool $value): void {
$this->values[$key] = $value;
}
/**
* @param string $key
*
* @return bool
*/
public function hasValue(string $key): bool {
return (array_key_exists($key, $this->values));
}
/**
* @param string $key
*
* @return string
*/
public function getValue(string $key): string {
return $this->values[$key];
}
/**
* @param string $key
*
* @return int
*/
public function getValueInt(string $key): int {
return $this->values[$key];
}
/**
* @param string $key
*
* @return bool
*/
public function getValueBool(string $key): bool {
return $this->values[$key];
}
/**
* @return array
*/
public function getValues(): array {
return $this->values;
}
/**
* @param array $values
*
* @return StreamAction
*/
public function setValues(array $values): StreamAction {
$this->values = $values;
return $this;
}
/**
* @param array $default
*
* @return StreamAction
*/
public function setDefaultValues(array $default): StreamAction {
$keys = array_keys($default);
foreach ($keys as $k) {
@ -223,21 +142,13 @@ class StreamAction implements JsonSerializable {
return $this;
}
/**
* @param array $data
*/
public function importFromDatabase(array $data) {
public function importFromDatabase(array $data): void {
$this->setId($this->getInt('id', $data, 0));
$this->setActorId($this->get('actor_id', $data, ''));
$this->setStreamId($this->get('stream_id', $data, ''));
$this->setValues($this->getArray('values', $data, []));
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),

Wyświetl plik

@ -44,7 +44,6 @@ use OCA\Social\Model\ActivityPub\Stream;
class StreamDetails implements JsonSerializable {
use TArrayTools;
private Stream $stream;
/** @var Person[] */
@ -52,82 +51,51 @@ class StreamDetails implements JsonSerializable {
/** @var Person[] */
private array $directViewers = [];
private bool $public = false;
private bool $federated = false;
/**
* StreamDetails constructor.
*
* @param Stream|null $stream
*/
public function __construct(Stream $stream = null) {
public function __construct(?Stream $stream = null) {
$this->stream = $stream;
}
/**
* @return Stream
*/
public function getStream(): Stream {
return $this->stream;
}
/**
* @param Stream $stream
*
* @return StreamDetails
*/
public function setStream(Stream $stream): self {
$this->stream = $stream;
return $this;
}
/**
* @return Person[]
*/
/** @return Person[] */
public function getHomeViewers(): array {
return $this->homeViewers;
}
/**
* @param Person[] $viewers
*
* @return StreamDetails
*/
/** @param Person[] $viewers */
public function setHomeViewers(array $viewers): self {
$this->homeViewers = $viewers;
return $this;
}
/**
* @param Person $viewer
*
* @return StreamDetails
*/
public function addHomeViewer(Person $viewer): self {
$this->homeViewers[] = $viewer;
return $this;
}
/**
* @return Person[]
*/
public function getDirectViewers(): array {
return $this->directViewers;
}
/**
* @param Person[] $viewers
*
* @return StreamDetails
*/
public function setDirectViewers(array $viewers): self {
$this->directViewers = $viewers;
@ -135,59 +103,32 @@ class StreamDetails implements JsonSerializable {
return $this;
}
/**
* @param Person $viewer
*
* @return StreamDetails
*/
public function addDirectViewer(Person $viewer): self {
$this->directViewers[] = $viewer;
return $this;
}
/**
* @return bool
*/
public function isPublic(): bool {
return $this->public;
}
/**
* @param bool $public
*
* @return StreamDetails
*/
public function setPublic(bool $public): self {
$this->public = $public;
return $this;
}
/**
* @return bool
*/
public function isFederated(): bool {
return $this->federated;
}
/**
* @param bool $federated
*
* @return StreamDetails
*/
public function setFederated(bool $federated): self {
$this->federated = $federated;
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'stream' => $this->getStream(),

Wyświetl plik

@ -44,7 +44,6 @@ use JsonSerializable;
class StreamQueue implements JsonSerializable {
use TArrayTools;
public const TYPE_CACHE = 'Cache';
public const TYPE_VERIFY = 'Signature';
@ -52,58 +51,30 @@ class StreamQueue implements JsonSerializable {
public const STATUS_RUNNING = 1;
public const STATUS_SUCCESS = 9;
private int $id = 0;
private string $token = '';
private string $streamId = '';
private string $type = '';
private int $status = 0;
private int $tries = 0;
private int $last = 0;
/**
* StreamQueue constructor.
*
* @param string $token
* @param string $type
* @param string $streamId
*/
public function __construct(string $token = '', string $type = '', string $streamId = '') {
$this->token = $token;
$this->type = $type;
$this->streamId = $streamId;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @param int $id
*
* @return StreamQueue
*/
public function setId(int $id): StreamQueue {
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getToken(): string {
return $this->token;
}

Wyświetl plik

@ -61,51 +61,22 @@ class CheckService {
public const CACHE_PREFIX = 'social_check_';
private IUserManager $userManager;
private ICache $cache;
private IConfig $config;
private IClientService $clientService;
private IRequest $request;
private IURLGenerator $urlGenerator;
private FollowsRequest $followRequest;
private CacheActorsRequest $cacheActorsRequest;
private StreamDestRequest $streamDestRequest;
private StreamRequest $streamRequest;
private AccountService $accountService;
private ConfigService $configService;
private MiscService $miscService;
private ?string $userId = null;
/**
* CheckService constructor.
*
* @param IUserManager $userManager
* @param ICache $cache
* @param IConfig $config
* @param IClientService $clientService
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param FollowsRequest $followRequest
* @param CacheActorsRequest $cacheActorsRequest
* @param StreamDestRequest $streamDestRequest
* @param StreamRequest $streamRequest
* @param AccountService $accountService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IUserManager $userManager, ICache $cache, IConfig $config, IClientService $clientService,
IUserManager $userManager, ?string $userId, ICache $cache, IConfig $config, IClientService $clientService,
IRequest $request, IURLGenerator $urlGenerator, FollowsRequest $followRequest,
CacheActorsRequest $cacheActorsRequest, StreamDestRequest $streamDestRequest,
StreamRequest $streamRequest, AccountService $accountService, ConfigService $configService,
@ -124,6 +95,7 @@ class CheckService {
$this->accountService = $accountService;
$this->configService = $configService;
$this->miscService = $miscService;
$this->userId = $userId;
}
@ -291,16 +263,12 @@ class CheckService {
return $count;
}
/**
* @param string $base
*
* @return bool
*/
private function requestWellKnown(string $base) {
private function requestWellKnown(string $base): bool {
try {
$url = $base . '/.well-known/webfinger';
$url = $base . '/.well-known/webfinger?resource=acct:' . $this->userId . '@' . parse_url($base, PHP_URL_HOST);
$options['nextcloud']['allow_local_address'] = true;
$options['verify'] = $this->config->getSystemValue('social.checkssl', true);
$response = $this->clientService->newClient()
->get($url, $options);
if ($response->getStatusCode() === Http::STATUS_OK) {

Wyświetl plik

@ -87,29 +87,14 @@ class ConfigService {
'WHITELIST' => 'none_but'
];
private string $userId;
private ?string $userId = null;
private IConfig $config;
private IRequest $request;
private IURLGenerator $urlGenerator;
private MiscService $miscService;
/**
* ConfigService constructor.
*
* @param string $userId
* @param IConfig $config
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param MiscService $miscService
*/
public function __construct(
$userId, IConfig $config, IRequest $request, IURLGenerator $urlGenerator,
?string $userId, IConfig $config, IRequest $request, IURLGenerator $urlGenerator,
MiscService $miscService
) {
$this->userId = $userId;

Wyświetl plik

@ -65,11 +65,8 @@ class CurlService {
public const ASYNC_REQUEST_TOKEN = '/async/request/{token}';
public const USER_AGENT = 'Nextcloud Social';
private ConfigService $configService;
private FediverseService $fediverseService;
private MiscService $miscService;
@ -115,10 +112,12 @@ class CurlService {
throw new InvalidResourceException('account format is not valid');
}
list($username, $host) = explode('@', $account);
if ($username === null || $host === null) {
$exploded = explode('@', $account);
if (count($exploded) < 2) {
throw new InvalidResourceException();
}
[$username, $host] = $exploded;
$protocols = ['https', 'http'];
try {

Wyświetl plik

@ -69,38 +69,21 @@ use stdClass;
class SignatureService {
use TArrayTools;
public const ORIGIN_HEADER = 1;
public const ORIGIN_SIGNATURE = 2;
public const ORIGIN_REQUEST = 3;
public const DATE_HEADER = 'D, d M Y H:i:s T';
public const DATE_OBJECT = 'Y-m-d\TH:i:s\Z';
public const DATE_DELAY = 300;
private CacheActorService $cacheActorService;
private ActorsRequest $actorsRequest;
private CurlService $curlService;
private ConfigService $configService;
private MiscService $miscService;
/**
* ActivityService constructor.
*
* @param ActorsRequest $actorsRequest
* @param CacheActorService $cacheActorService
* @param CurlService $curlService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
ActorsRequest $actorsRequest, CacheActorService $cacheActorService,
CurlService $curlService,

39
psalm.xml 100644
Wyświetl plik

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="tests/psalm-baseline.xml"
>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
</stubs>
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor" />
<ignoreFiles>
<directory name="vendor/phpunit/php-code-coverage" />
</ignoreFiles>
</extraFiles>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC" />
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
<referencedClass name="Doctrine\DBAL\Schema\Table" />
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
</psalm>

Wyświetl plik

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/lib',
__DIR__ . '/tests/',
]);
$parameters->set(Option::BOOTSTRAP_FILES, [
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../lib/composer/autoload.php',
__DIR__ . '/../../3rdparty/autoload.php',
]);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class)
->configure([
TypedPropertyRector::INLINE_PUBLIC => true,
]);
};

Wyświetl plik

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703">
<file src="lib/AP.php">
<InvalidScalarArgument occurrences="1">
<code>$level</code>
</InvalidScalarArgument>
<UndefinedPropertyAssignment occurrences="3">
<code>$ap-&gt;groupInterface</code>
<code>$ap-&gt;groupInterface</code>
<code>$ap-&gt;groupInterface</code>
</UndefinedPropertyAssignment>
</file>
<file src="lib/Migration/Version0003Date20200823023900.php">
<UndefinedDocblockClass occurrences="1">
<code>DBALException</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Migration/Version0003Date20200823023911.php">
<UndefinedClass occurrences="3">
<code>SchemaException</code>
<code>SchemaException</code>
<code>Type</code>
</UndefinedClass>
</file>
<file src="lib/Model/ActivityPub/ACore.php">
<InvalidArgument occurrences="1">
<code>['a', 'p', 'span', 'br']</code>
</InvalidArgument>
<InvalidClass occurrences="1">
<code>Acore</code>
</InvalidClass>
<InvalidNullableReturnType occurrences="4">
<code>ACore</code>
<code>ACore</code>
<code>Document</code>
<code>LinkedDataSignature</code>
</InvalidNullableReturnType>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$parent</code>
</InvalidPropertyAssignmentValue>
<NullableReturnStatement occurrences="4">
<code>$this-&gt;icon</code>
<code>$this-&gt;object</code>
<code>$this-&gt;parent</code>
<code>$this-&gt;signature</code>
</NullableReturnStatement>
<TypeDoesNotContainNull occurrences="1">
<code>$v === null</code>
</TypeDoesNotContainNull>
<TypeDoesNotContainType occurrences="2">
<code>$v === 0</code>
<code>$v === 0</code>
</TypeDoesNotContainType>
</file>
<file src="lib/Model/ActivityPub/Object/Announce.php">
<RedundantCondition occurrences="1">
<code>$object = $cache-&gt;getItem($this-&gt;getObjectId())</code>
</RedundantCondition>
</file>
<file src="lib/Model/Instance.php">
<InvalidNullableReturnType occurrences="2">
<code>Person</code>
<code>string</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="2">
<code>$this-&gt;accountPrim</code>
<code>$this-&gt;contactAccount</code>
</NullableReturnStatement>
</file>
<file src="lib/Model/LinkedDataSignature.php">
<UndefinedMethod occurrences="1">
<code>getPublicKey</code>
</UndefinedMethod>
</file>
<file src="lib/Model/RequestQueue.php">
<InvalidNullableReturnType occurrences="1">
<code>InstancePath</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="1">
<code>$this-&gt;instance</code>
</NullableReturnStatement>
</file>
<file src="lib/Service/CheckService.php">
<RedundantCast occurrences="1">
<code>(bool)($this-&gt;cache-&gt;get(self::CACHE_PREFIX . 'wellknown') === 'true')</code>
</RedundantCast>
<UndefinedClass occurrences="1">
<code>ClientException</code>
</UndefinedClass>
</file>
<file src="lib/Service/CurlService.php">
<InvalidOperand occurrences="1">
<code>$this-&gt;configService-&gt;getAppValue(ConfigService::SOCIAL_MAX_SIZE)</code>
</InvalidOperand>
<RedundantCondition occurrences="1">
<code>is_array($result)</code>
</RedundantCondition>
</file>
<file src="lib/Service/FollowService.php">
<InvalidReturnStatement occurrences="2">
<code>$this-&gt;followsRequest-&gt;getFollowersByActorId($actor-&gt;getId())</code>
<code>$this-&gt;followsRequest-&gt;getFollowingByActorId($actor-&gt;getId())</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="2">
<code>Person[]</code>
<code>Person[]</code>
</InvalidReturnType>
</file>
<file src="lib/Service/HashtagService.php">
<InvalidReturnStatement occurrences="1">
<code>$result</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>Stream[]</code>
</InvalidReturnType>
</file>
<file src="lib/Service/PostService.php">
<InvalidNullableReturnType occurrences="1">
<code>ACore</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="1">
<code>$activity</code>
</NullableReturnStatement>
<UndefinedMethod occurrences="2">
<code>setAttributedTo</code>
<code>setContent</code>
</UndefinedMethod>
</file>
<file src="lib/Service/SearchService.php">
<InvalidOperand occurrences="3">
<code>!$type</code>
<code>!$type</code>
<code>!$type</code>
</InvalidOperand>
</file>
<file src="lib/Service/SignatureService.php">
<RedundantCondition occurrences="1">
<code>$varr[0] !== null</code>
</RedundantCondition>
<UndefinedInterfaceMethod occurrences="1">
<code>getAppDataDir</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Service/StreamService.php">
<InvalidReturnType occurrences="1">
<code>Note[]</code>
</InvalidReturnType>
</file>
<file src="lib/Service/TestService.php">
<TypeDoesNotContainNull occurrences="3">
<code>$host === null</code>
<code>$username === null</code>
<code>$username === null</code>
</TypeDoesNotContainNull>
</file>
</files>

1019
tests/stub.phpstub 100644

Plik diff jest za duży Load Diff