forked from GNUsocial/gnu-social
[TOOLS] Fix (most) issues found by PHPStan
This commit is contained in:
@@ -39,6 +39,7 @@ use App\Util\Exception\ClientException;
|
||||
use App\Util\Exception\InvalidFormException;
|
||||
use App\Util\Exception\NoSuchNoteException;
|
||||
use App\Util\Exception\RedirectException;
|
||||
use App\Util\Form\FormFields;
|
||||
use Component\Posting\Posting;
|
||||
use Plugin\Reply\Entity\NoteReply;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
@@ -70,13 +71,10 @@ class Reply extends Controller
|
||||
throw new NoSuchNoteException();
|
||||
}
|
||||
|
||||
// TODO shouldn't this be the posting form?
|
||||
$form = Form::create([
|
||||
['content', TextareaType::class, [
|
||||
'label' => _m('Reply'),
|
||||
'label_attr' => ['class' => 'section-form-label'],
|
||||
'help' => _m('Please input your reply.'),
|
||||
],
|
||||
],
|
||||
['content', TextareaType::class, ['label' => _m('Reply'), 'label_attr' => ['class' => 'section-form-label'], 'help' => _m('Please input your reply.')]],
|
||||
FormFields::language($user->getActor(), context_actor: $note->getActor(), label: 'Note language', help: null),
|
||||
['attachments', FileType::class, ['label' => ' ', 'multiple' => true, 'required' => false]],
|
||||
['replyform', SubmitType::class, ['label' => _m('Submit')]],
|
||||
]);
|
||||
@@ -91,6 +89,7 @@ class Reply extends Controller
|
||||
actor: Actor::getWithPK($actor_id),
|
||||
content: $data['content'],
|
||||
content_type: 'text/plain', // TODO
|
||||
language: $data['language'],
|
||||
attachments: $data['attachments'],
|
||||
);
|
||||
|
||||
@@ -116,13 +115,13 @@ class Reply extends Controller
|
||||
|
||||
// Redirect user to where they came from
|
||||
// Prevent open redirect
|
||||
if (\array_key_exists('from', (array) $get_params = $this->params())) {
|
||||
if (Router::isAbsolute($get_params['from'])) {
|
||||
Log::warning("Actor {$actor_id} attempted to reply to a note and then get redirected to another host, or the URL was invalid ({$get_params['from']})");
|
||||
if (!\is_null($from = $this->string('from'))) {
|
||||
if (Router::isAbsolute($from)) {
|
||||
Log::warning("Actor {$actor_id} attempted to reply to a note and then get redirected to another host, or the URL was invalid ({$from})");
|
||||
throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive)
|
||||
} else {
|
||||
// TODO anchor on element id
|
||||
throw new RedirectException($get_params['from']);
|
||||
throw new RedirectException($from);
|
||||
}
|
||||
} else {
|
||||
// If we don't have a URL to return to, go to the instance root
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare(strict_types = 1);
|
||||
|
||||
// {{{ License
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Plugin\Reply\Entity;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Entity\Note;
|
||||
use function PHPUnit\Framework\isEmpty;
|
||||
|
||||
/**
|
||||
* Entity for notices
|
||||
@@ -87,16 +86,16 @@ class NoteReply extends Entity
|
||||
where reply_to = :note_id
|
||||
order by n.created DESC
|
||||
EOF,
|
||||
['note_id' => $note->getId()]
|
||||
['note_id' => $note->getId()],
|
||||
);
|
||||
}
|
||||
|
||||
public static function getReplyToNote(Note $note): ?int
|
||||
{
|
||||
$result = DB::dql('select nr.reply_to from note_reply nr '
|
||||
. 'where nr.note_id = :note_id', ['note_id' => $note->getId()]);
|
||||
. 'where nr.note_id = :note_id', ['note_id' => $note->getId()], );
|
||||
|
||||
if (!isEmpty($result)) {
|
||||
if (!empty($result)) {
|
||||
return $result['reply_to'];
|
||||
}
|
||||
|
||||
@@ -106,19 +105,19 @@ class NoteReply extends Entity
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'note_reply',
|
||||
'name' => 'note_reply',
|
||||
'fields' => [
|
||||
'note_id' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'The id of the reply itself'],
|
||||
'note_id' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'The id of the reply itself'],
|
||||
'actor_id' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'description' => 'Who made this reply'],
|
||||
'reply_to' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'Note this is a reply of'],
|
||||
],
|
||||
'primary key' => ['note_id'],
|
||||
'foreign keys' => [
|
||||
'note_id_to_id_fkey' => ['note', ['note_id' => 'id']],
|
||||
'note_reply_to_id_fkey' => ['note', ['reply_to' => 'id']],
|
||||
'note_id_to_id_fkey' => ['note', ['note_id' => 'id']],
|
||||
'note_reply_to_id_fkey' => ['note', ['reply_to' => 'id']],
|
||||
'actor_reply_to_id_fkey' => ['actor', ['actor_id' => 'id']],
|
||||
],
|
||||
'indexes' => [
|
||||
'indexes' => [
|
||||
'note_reply_to_idx' => ['reply_to'],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user