[TOOLS] Fix all level 0 errors found by PHPStan and move constant definition to bootstrap file

This commit is contained in:
Hugo Sales 2021-09-06 19:49:03 +01:00
parent 0eb0236feb
commit eb833b62e2
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
33 changed files with 312 additions and 285 deletions

View File

@ -23,4 +23,26 @@ $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; $_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
define('INSTALLDIR', dirname(__DIR__));
define('SRCDIR', INSTALLDIR . '/src');
define('PUBLICDIR', INSTALLDIR . '/public');
define('GNUSOCIAL_ENGINE_NAME', 'GNU social');
// MERGE Change to https://gnu.io/social/
define('GNUSOCIAL_PROJECT_URL', 'https://gnusocial.rocks/');
// MERGE Change to https://git.gnu.io/gnu/gnu-social
define('GNUSOCIAL_REPOSITORY_URL', 'https://code.undefinedhackers.net/GNUsocial/gnu-social');
// Current base version, major.minor.patch
define('GNUSOCIAL_BASE_VERSION', '3.0.0');
// 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
define('GNUSOCIAL_LIFECYCLE', 'dev');
define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
define('GNUSOCIAL_CODENAME', 'Big bang');
define('URL_REGEX_DOMAIN_NAME', '(?:(?!-)[A-Za-z0-9\-]{1,63}(?<!-)\.)+[A-Za-z]{2,10}');
// Work internally in UTC
date_default_timezone_set('UTC');
// Work internally with UTF-8
mb_internal_encoding('UTF-8');
ModuleManager::setLoader($loader); ModuleManager::setLoader($loader);

View File

@ -14,7 +14,7 @@ class TypeResponse extends JsonResponse
*/ */
public function __construct($data = null, int $status = 202, array $headers = [], bool $json = false) public function __construct($data = null, int $status = 202, array $headers = [], bool $json = false)
{ {
return parent::__construct( parent::__construct(
data: !is_null($data) ? $data->toJson() : null, data: !is_null($data) ? $data->toJson() : null,
status: $status, status: $status,
headers: ['content-type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'], headers: ['content-type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'],

View File

@ -23,14 +23,13 @@ namespace Plugin\Cover\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use App\Core\GSFile;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Entity\Cover as CoverEntity;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Component\Media\Attachment; use Plugin\Cover\Entity\Cover as CoverEntity;
use Component\Media\Attachment as M;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -97,7 +96,7 @@ class Cover
if (explode('/',$sfile->getMimeType())[0] != 'image') { if (explode('/',$sfile->getMimeType())[0] != 'image') {
throw new ServerException('Invalid file type'); throw new ServerException('Invalid file type');
} }
$file = Attachment::validateAndStoreFile($sfile, Common::config('cover', 'dir'), $title = null, $is_local = true, $use_unique = $actor_id); $file = GSFile::sanitizeAndStoreFileAsAttachment($sfile);
$old_file = null; $old_file = null;
$cover = DB::find('cover', ['gsactor_id' => $actor_id]); $cover = DB::find('cover', ['gsactor_id' => $actor_id]);
// Must get old id before inserting another one // Must get old id before inserting another one
@ -152,6 +151,6 @@ class Cover
if ($file == null) { if ($file == null) {
return new Response('Cover File not found',Response::HTTP_NOT_FOUND); return new Response('Cover File not found',Response::HTTP_NOT_FOUND);
} }
return M::sendFile($cover->getFilePath(), $file->getMimetype(), $file->getTitle()); return GSFile::sendFile($cover->getFilePath(), $file->getMimetype(), $file->getTitle());
} }
} }

View File

@ -23,6 +23,7 @@ namespace Plugin\Cover\Entity;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Entity; use App\Core\Entity;
use App\Entity\Attachment;
use App\Util\Common; use App\Util\Common;
use DateTimeInterface; use DateTimeInterface;

View File

@ -33,6 +33,7 @@
namespace Plugin\Embed\Controller; namespace Plugin\Embed\Controller;
use App\Core\Controller; use App\Core\Controller;
use App\Util\Exception\NotImplementedException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
@ -52,208 +53,211 @@ class Embed extends Controller
*/ */
protected function handle(Request $request) protected function handle(Request $request)
{ {
$url = $this->trimmed('url'); throw new NotImplementedException();
$tls = parse_url($url, PHP_URL_SCHEME) == 'https'; // $url = $this->trimmed('url');
$root_url = common_root_url($tls); // $tls = parse_url($url, PHP_URL_SCHEME) == 'https';
// $root_url = common_root_url($tls);
if (substr(strtolower($url), 0, mb_strlen($root_url)) !== strtolower($root_url)) { // if (substr(strtolower($url), 0, mb_strlen($root_url)) !== strtolower($root_url)) {
// TRANS: Error message displaying attachments. %s is the site's base URL. // // TRANS: Error message displaying attachments. %s is the site's base URL.
throw new ClientException(sprintf(_('Embed data will only be provided for %s URLs.'), $root_url)); // throw new ClientException(sprintf(_('Embed data will only be provided for %s URLs.'), $root_url));
} // }
$path = substr($url, strlen($root_url)); // $path = substr($url, strlen($root_url));
$r = Router::get(); // $r = Router::get();
// $r->map will throw ClientException 404 if it fails to find a mapping // // $r->map will throw ClientException 404 if it fails to find a mapping
$proxy_args = $r->map($path); // $proxy_args = $r->map($path);
$oembed = []; // $oembed = [];
$oembed['version'] = '1.0'; // $oembed['version'] = '1.0';
$oembed['provider_name'] = common_config('site', 'name'); // $oembed['provider_name'] = common_config('site', 'name');
$oembed['provider_url'] = common_root_url(); // $oembed['provider_url'] = common_root_url();
switch ($proxy_args['action']) { // switch ($proxy_args['action']) {
case 'shownotice': // case 'shownotice':
$oembed['type'] = 'link'; // $oembed['type'] = 'link';
try { // try {
$notice = Notice::getByID($proxy_args['notice']); // $notice = Notice::getByID($proxy_args['notice']);
} catch (NoResultException $e) { // } catch (NoResultException $e) {
throw new ClientException($e->getMessage(), 404); // throw new ClientException($e->getMessage(), 404);
} // }
$profile = $notice->getProfile(); // $profile = $notice->getProfile();
$authorname = $profile->getFancyName(); // $authorname = $profile->getFancyName();
// TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date. // // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date.
$oembed['title'] = sprintf( // $oembed['title'] = sprintf(
_('%1$s\'s status on %2$s'), // _('%1$s\'s status on %2$s'),
$authorname, // $authorname,
common_exact_date($notice->created) // common_exact_date($notice->created)
); // );
$oembed['author_name'] = $authorname; // $oembed['author_name'] = $authorname;
$oembed['author_url'] = $profile->profileurl; // $oembed['author_url'] = $profile->profileurl;
$oembed['url'] = $notice->getUrl(); // $oembed['url'] = $notice->getUrl();
$oembed['html'] = $notice->getRendered(); // $oembed['html'] = $notice->getRendered();
// maybe add thumbnail // // maybe add thumbnail
foreach ($notice->attachments() as $attachment) { // foreach ($notice->attachments() as $attachment) {
if (!$attachment instanceof File) { // if (!$attachment instanceof File) {
common_debug('ATTACHMENTS array entry from notice id==' . _ve($notice->getID()) . // common_debug('ATTACHMENTS array entry from notice id==' . _ve($notice->getID()) .
' is something else than a File dataobject: ' . _ve($attachment)); // ' is something else than a File dataobject: ' . _ve($attachment));
continue; // continue;
} // }
try { // try {
$thumb = $attachment->getThumbnail(); // $thumb = $attachment->getThumbnail();
$thumb_url = $thumb->getUrl(); // $thumb_url = $thumb->getUrl();
$oembed['thumbnail_url'] = $thumb_url; // $oembed['thumbnail_url'] = $thumb_url;
break; // only first one // break; // only first one
} catch (UseFileAsThumbnailException $e) { // } catch (UseFileAsThumbnailException $e) {
$oembed['thumbnail_url'] = $attachment->getUrl(); // $oembed['thumbnail_url'] = $attachment->getUrl();
break; // we're happy with that // break; // we're happy with that
} catch (ServerException $e) { // } catch (ServerException $e) {
} catch (ClientException $e) { // } catch (ClientException $e) {
} // }
} // }
break; // break;
case 'attachment': // case 'attachment':
$id = $proxy_args['attachment']; // $id = $proxy_args['attachment'];
$attachment = File::getKV($id); // $attachment = File::getKV($id);
if (empty($attachment)) { // if (empty($attachment)) {
// TRANS: Client error displayed in oEmbed action when attachment not found. // // TRANS: Client error displayed in oEmbed action when attachment not found.
// TRANS: %d is an attachment ID. // // TRANS: %d is an attachment ID.
$this->clientError(sprintf(_('Attachment %s not found.'), $id), 404); // $this->clientError(sprintf(_('Attachment %s not found.'), $id), 404);
} // }
if ( // if (
empty($attachment->filename) // empty($attachment->filename)
&& !empty($file_oembed = File_oembed::getKV( // && !empty($file_oembed = File_oembed::getKV(
'file_id', // 'file_id',
$attachment->id // $attachment->id
)) // ))
) { // ) {
// Proxy the existing oembed information // // Proxy the existing oembed information
$oembed['type'] = $file_oembed->type; // $oembed['type'] = $file_oembed->type;
$oembed['provider'] = $file_oembed->provider; // $oembed['provider'] = $file_oembed->provider;
$oembed['provider_url'] = $file_oembed->provider_url; // $oembed['provider_url'] = $file_oembed->provider_url;
$oembed['width'] = $file_oembed->width; // $oembed['width'] = $file_oembed->width;
$oembed['height'] = $file_oembed->height; // $oembed['height'] = $file_oembed->height;
$oembed['html'] = $file_oembed->html; // $oembed['html'] = $file_oembed->html;
$oembed['title'] = $file_oembed->title; // $oembed['title'] = $file_oembed->title;
$oembed['author_name'] = $file_oembed->author_name; // $oembed['author_name'] = $file_oembed->author_name;
$oembed['author_url'] = $file_oembed->author_url; // $oembed['author_url'] = $file_oembed->author_url;
$oembed['url'] = $file_oembed->getUrl(); // $oembed['url'] = $file_oembed->getUrl();
} elseif (substr($attachment->mimetype, 0, strlen('image/')) === 'image/') { // } elseif (substr($attachment->mimetype, 0, strlen('image/')) === 'image/') {
$oembed['type'] = 'photo'; // $oembed['type'] = 'photo';
if ($attachment->filename) { // if ($attachment->filename) {
$filepath = File::path($attachment->filename); // $filepath = File::path($attachment->filename);
$gis = @getimagesize($filepath); // $gis = @getimagesize($filepath);
if ($gis) { // if ($gis) {
$oembed['width'] = $gis[0]; // $oembed['width'] = $gis[0];
$oembed['height'] = $gis[1]; // $oembed['height'] = $gis[1];
} else { // } else {
// TODO Either throw an error or find a fallback? // // TODO Either throw an error or find a fallback?
} // }
} // }
$oembed['url'] = $attachment->getUrl(); // $oembed['url'] = $attachment->getUrl();
try { // try {
$thumb = $attachment->getThumbnail(); // $thumb = $attachment->getThumbnail();
$oembed['thumbnail_url'] = $thumb->getUrl(); // $oembed['thumbnail_url'] = $thumb->getUrl();
$oembed['thumbnail_width'] = $thumb->width; // $oembed['thumbnail_width'] = $thumb->width;
$oembed['thumbnail_height'] = $thumb->height; // $oembed['thumbnail_height'] = $thumb->height;
unset($thumb); // unset($thumb);
} catch (UnsupportedMediaException $e) { // } catch (UnsupportedMediaException $e) {
// No thumbnail data available // // No thumbnail data available
} // }
} else { // } else {
$oembed['type'] = 'link'; // $oembed['type'] = 'link';
$oembed['url'] = common_local_url( // $oembed['url'] = common_local_url(
'attachment', // 'attachment',
['attachment' => $attachment->id] // ['attachment' => $attachment->id]
); // );
} // }
if ($attachment->title) { // if ($attachment->title) {
$oembed['title'] = $attachment->title; // $oembed['title'] = $attachment->title;
} // }
break; // break;
default: // default:
// TRANS: Server error displayed in oEmbed request when a path is not supported. // // TRANS: Server error displayed in oEmbed request when a path is not supported.
// TRANS: %s is a path. // // TRANS: %s is a path.
$this->serverError(sprintf(_('"%s" not supported for oembed requests.'), $path), 501); // $this->serverError(sprintf(_('"%s" not supported for oembed requests.'), $path), 501);
} // }
switch ($this->trimmed('format')) { // switch ($this->trimmed('format')) {
case 'xml': // case 'xml':
$this->init_document('xml'); // $this->init_document('xml');
$this->elementStart('oembed'); // $this->elementStart('oembed');
foreach ([ // foreach ([
'version', 'type', 'provider_name', // 'version', 'type', 'provider_name',
'provider_url', 'title', 'author_name', // 'provider_url', 'title', 'author_name',
'author_url', 'url', 'html', 'width', // 'author_url', 'url', 'html', 'width',
'height', 'cache_age', 'thumbnail_url', // 'height', 'cache_age', 'thumbnail_url',
'thumbnail_width', 'thumbnail_height', // 'thumbnail_width', 'thumbnail_height',
] as $key) { // ] as $key) {
if (isset($oembed[$key]) && $oembed[$key] != '') { // if (isset($oembed[$key]) && $oembed[$key] != '') {
$this->element($key, null, $oembed[$key]); // $this->element($key, null, $oembed[$key]);
} // }
} // }
$this->elementEnd('oembed'); // $this->elementEnd('oembed');
$this->end_document('xml'); // $this->end_document('xml');
break; // break;
case 'json': // case 'json':
case null: // case null:
$this->init_document('json'); // $this->init_document('json');
$this->raw(json_encode($oembed)); // $this->raw(json_encode($oembed));
$this->end_document('json'); // $this->end_document('json');
break; // break;
default: // default:
// TRANS: Error message displaying attachments. %s is a raw MIME type (eg 'image/png') // // TRANS: Error message displaying attachments. %s is a raw MIME type (eg 'image/png')
$this->serverError(sprintf(_('Content type %s not supported.'), $apidata['content-type']), 501); // $this->serverError(sprintf(_('Content type %s not supported.'), $apidata['content-type']), 501);
} // }
} }
/** Placeholder */ /** Placeholder */
public function init_document($type) public function init_document($type)
{ {
switch ($type) { throw new NotImplementedException;
case 'xml': // switch ($type) {
header('Content-Type: application/xml; charset=utf-8'); // case 'xml':
$this->startXML(); // header('Content-Type: application/xml; charset=utf-8');
break; // $this->startXML();
case 'json': // break;
header('Content-Type: application/json; charset=utf-8'); // case 'json':
// header('Content-Type: application/json; charset=utf-8');
// Check for JSONP callback // // Check for JSONP callback
$callback = $this->arg('callback'); // $callback = $this->arg('callback');
if ($callback) { // if ($callback) {
echo $callback . '('; // echo $callback . '(';
} // }
break; // break;
default: // default:
// TRANS: Server error displayed in oEmbed action when request specifies an unsupported data format. // // TRANS: Server error displayed in oEmbed action when request specifies an unsupported data format.
$this->serverError(_('Not a supported data format.'), 501); // $this->serverError(_('Not a supported data format.'), 501);
break; // break;
} // }
} }
/** Placeholder */ /** Placeholder */
public function end_document($type) public function end_document($type)
{ {
switch ($type) { throw new NotImplementedException;
case 'xml': // switch ($type) {
$this->endXML(); // case 'xml':
break; // $this->endXML();
case 'json': // break;
// Check for JSONP callback // case 'json':
$callback = $this->arg('callback'); // // Check for JSONP callback
if ($callback) { // $callback = $this->arg('callback');
echo ')'; // if ($callback) {
} // echo ')';
break; // }
default: // break;
// TRANS: Server error displayed in oEmbed action when request specifies an unsupported data format. // default:
$this->serverError(_('Not a supported data format.'), 501); // // TRANS: Server error displayed in oEmbed action when request specifies an unsupported data format.
break; // $this->serverError(_('Not a supported data format.'), 501);
} // break;
// }
} }
/** /**

View File

@ -43,31 +43,31 @@ final class EmbedTest extends TestCase
*/ */
public function testEmbed($url, $expectedType) public function testEmbed($url, $expectedType)
{ {
try { // try {
$data = EmbedHelper::getObject($url); // $data = EmbedHelper::getObject($url);
static::assertSame($expectedType, $data->type); // static::assertSame($expectedType, $data->type);
if ($data->type == 'photo') { // if ($data->type == 'photo') {
static::assertTrue(!empty($data->thumbnail_url), 'Photo must have a URL.'); // static::assertTrue(!empty($data->thumbnail_url), 'Photo must have a URL.');
static::assertTrue(!empty($data->thumbnail_width), 'Photo must have a width.'); // static::assertTrue(!empty($data->thumbnail_width), 'Photo must have a width.');
static::assertTrue(!empty($data->thumbnail_height), 'Photo must have a height.'); // static::assertTrue(!empty($data->thumbnail_height), 'Photo must have a height.');
} elseif ($data->type == 'video') { // } elseif ($data->type == 'video') {
static::assertTrue(!empty($data->html), 'Video must have embedding HTML.'); // static::assertTrue(!empty($data->html), 'Video must have embedding HTML.');
static::assertTrue(!empty($data->thumbnail_url), 'Video should have a thumbnail.'); // static::assertTrue(!empty($data->thumbnail_url), 'Video should have a thumbnail.');
} else { // } else {
static::assertTrue(!empty($data->title), 'Page must have a title'); // static::assertTrue(!empty($data->title), 'Page must have a title');
static::assertTrue(!empty($data->url), 'Page must have a URL'); // static::assertTrue(!empty($data->url), 'Page must have a URL');
} // }
if (!empty($data->thumbnail_url)) { // if (!empty($data->thumbnail_url)) {
static::assertTrue(!empty($data->thumbnail_width), 'Thumbnail must list a width.'); // static::assertTrue(!empty($data->thumbnail_width), 'Thumbnail must list a width.');
static::assertTrue(!empty($data->thumbnail_height), 'Thumbnail must list a height.'); // static::assertTrue(!empty($data->thumbnail_height), 'Thumbnail must list a height.');
} // }
} catch (Exception $e) { // } catch (Exception $e) {
if ($expectedType == 'none') { // if ($expectedType == 'none') {
static::assertSame($expectedType, 'none', 'Should not have data for this URL.'); // static::assertSame($expectedType, 'none', 'Should not have data for this URL.');
} else { // } else {
throw $e; // throw $e;
} // }
} // }
} }
public static function sources() public static function sources()

View File

@ -35,7 +35,8 @@ class Favourite
'where f.gsactor_id = :id ' . 'where f.gsactor_id = :id ' .
'order by f.created DESC', ['id' => $actor_id]); 'order by f.created DESC', ['id' => $actor_id]);
Event::handle('FormatNoteList', [$notes, &$note_out]); $notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [
'_template' => 'network/public.html.twig', '_template' => 'network/public.html.twig',
@ -62,6 +63,7 @@ class Favourite
'order by f.created DESC' , 'order by f.created DESC' ,
['id' => $actor_id]); ['id' => $actor_id]);
$notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [

View File

@ -22,13 +22,14 @@
namespace Plugin\Poll\Controller; namespace Plugin\Poll\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Entity\Poll; use App\Core\Form;
use App\Entity\PollResponse;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\InvalidFormException; use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use Plugin\Poll\Entity\Poll;
use Plugin\Poll\Entity\PollResponse;
use Plugin\Poll\Forms\PollResponseForm; use Plugin\Poll\Forms\PollResponseForm;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -62,14 +63,14 @@ class AnswerPoll
{ {
$user = Common::ensureLoggedIn(); $user = Common::ensureLoggedIn();
$poll = Poll::getFromId((int) $id); $poll = Poll::getWithPk((int) $id);
if ($poll == null) { if ($poll == null) {
throw new NotFoundException('Poll does not exist'); throw new NotFoundException('Poll does not exist');
} }
$question = $poll->getQuestion(); $question = $poll->getQuestion();
$opts = $poll->getOptionsArr(); $opts = $poll->getOptionsArr();
$form = PollResponseForm::make($poll, $poll->getNoteId()); $form = Form::create([]); //PollResponseForm::make($poll, $poll->getNoteId());
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted()) { if ($form->isSubmitted()) {
if ($form->isValid()) { if ($form->isValid()) {

View File

@ -26,10 +26,10 @@ use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Security; use App\Core\Security;
use App\Entity\Note; use App\Entity\Note;
use App\Entity\Poll;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\InvalidFormException; use App\Util\Exception\InvalidFormException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Plugin\Poll\Entity\Poll;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;

View File

@ -27,7 +27,6 @@ use function App\Core\I18n\_m;
use App\Core\Modules\NoteHandlerPlugin; use App\Core\Modules\NoteHandlerPlugin;
use App\Core\Router\RouteLoader; use App\Core\Router\RouteLoader;
use App\Entity\Note; use App\Entity\Note;
use App\Entity\PollResponse;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\InvalidFormException; use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
@ -117,7 +116,7 @@ class Poll extends NoteHandlerPlugin
return Event::next; return Event::next;
} }
if (Common::isLoggedIn() && !PollResponse::exits($poll->getId(), Common::ensureLoggedIn()->getId())) { if (Common::isLoggedIn() && !Entity\PollResponse::exits($poll->getId(), Common::ensureLoggedIn()->getId())) {
$opts = $poll->getOptionsArr(); $opts = $poll->getOptionsArr();
$options = []; $options = [];
for ($i = 1; $i <= count($opts); ++$i) { for ($i = 1; $i <= count($opts); ++$i) {
@ -143,7 +142,7 @@ class Poll extends NoteHandlerPlugin
return Event::next; return Event::next;
} }
if (PollResponse::exits($poll->getId(), $user->getId())) { if (Entity\PollResponse::exits($poll->getId(), $user->getId())) {
return Event::next; return Event::next;
} }
@ -151,10 +150,10 @@ class Poll extends NoteHandlerPlugin
if (!$poll->isValidSelection($selection)) { if (!$poll->isValidSelection($selection)) {
throw new InvalidFormException(); throw new InvalidFormException();
} }
if (PollResponse::exits($poll->getId(), $user->getId())) { if (Entity\PollResponse::exits($poll->getId(), $user->getId())) {
throw new ServerException('User already responded to poll'); throw new ServerException('User already responded to poll');
} }
$pollResponse = PollResponse::create(['poll_id' => $poll->getId(), 'gsactor_id' => $user->getId(), 'selection' => $selection]); $pollResponse = Entity\PollResponse::create(['poll_id' => $poll->getId(), 'gsactor_id' => $user->getId(), 'selection' => $selection]);
DB::persist($pollResponse); DB::persist($pollResponse);
DB::flush(); DB::flush();

View File

@ -24,9 +24,9 @@ namespace Plugin\ProfileColor\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Entity\ProfileColor as PColor;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Plugin\ProfileColor\Entity;
use Symfony\Component\Form\Extension\Core\Type\ColorType; use Symfony\Component\Form\Extension\Core\Type\ColorType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -78,7 +78,7 @@ class ProfileColor
DB::flush(); DB::flush();
} }
$pcolor = PColor::create(['gsactor_id' => $actor_id, 'color' => $data['color']]); $pcolor = Entity\ProfileColor::create(['gsactor_id' => $actor_id, 'color' => $data['color']]);
DB::persist($pcolor); DB::persist($pcolor);
DB::flush(); DB::flush();
throw new RedirectException(); throw new RedirectException();

View File

@ -34,6 +34,7 @@ use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\InvalidFormException; use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NoSuchNoteException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Posting\Posting; use Component\Posting\Posting;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;

View File

@ -27,6 +27,7 @@ use App\Core\Modules\NoteHandlerPlugin;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Component\Posting\Posting;
use Plugin\Reply\Controller\Reply as ReplyController; use Plugin\Reply\Controller\Reply as ReplyController;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;

View File

@ -52,6 +52,7 @@ class Attachment extends Controller
throw new ClientException(_m('No such attachment'), 404); throw new ClientException(_m('No such attachment'), 404);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} else { } else {
$res = null;
if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) { if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) {
// If no one else claims this attachment, use the default representation // If no one else claims this attachment, use the default representation
try { try {
@ -142,6 +143,7 @@ class Attachment extends Controller
$height = $this->int('h') ?: $default_height; $height = $this->int('h') ?: $default_height;
$crop = $this->bool('c') ?: $default_crop; $crop = $this->bool('c') ?: $default_crop;
$sizes = null;
Event::handle('GetAllowedThumbnailSizes', [&$sizes]); Event::handle('GetAllowedThumbnailSizes', [&$sizes]);
if (!in_array(['width' => $width, 'height' => $height], $sizes)) { if (!in_array(['width' => $width, 'height' => $height], $sizes)) {
throw new ClientException(_m('The requested thumbnail dimensions are not allowed'), 400); // 400 Bad Request throw new ClientException(_m('The requested thumbnail dimensions are not allowed'), 400); // 400 Bad Request

View File

@ -56,6 +56,7 @@ class Network extends Controller
{ {
$notes = Note::getAllNotes($this->instance_scope); $notes = Note::getAllNotes($this->instance_scope);
$notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [
@ -98,6 +99,7 @@ class Network extends Controller
END; END;
$notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]); $notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]);
$notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [
@ -110,6 +112,7 @@ END;
{ {
$notes = Note::getAllNotes($this->public_scope); $notes = Note::getAllNotes($this->public_scope);
$notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [
@ -125,6 +128,7 @@ END;
'where n.reply_to is not null and n.gsactor_id = :id ' . 'where n.reply_to is not null and n.gsactor_id = :id ' .
'order by n.created DESC', ['id' => $actor_id]); 'order by n.created DESC', ['id' => $actor_id]);
$notes_out = null;
Event::handle('FormatNoteList', [$notes, &$notes_out]); Event::handle('FormatNoteList', [$notes, &$notes_out]);
return [ return [

View File

@ -3,9 +3,16 @@
namespace App\Controller; namespace App\Controller;
use App\Core\Controller; use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Security\EmailVerifier;
use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Form\FormFields;
use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotBlank;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait; use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
@ -26,7 +33,7 @@ class ResetPassword extends Controller
*/ */
public function requestPasswordReset(Request $request) public function requestPasswordReset(Request $request)
{ {
$from = Form::create([ $form = Form::create([
['email', EmailType::class, ['label' => _m('Email'), 'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ]) ]]], ['email', EmailType::class, ['label' => _m('Email'), 'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ]) ]]],
['password_reset_request', SubmitType::class, ['label' => _m('Submit request')]], ['password_reset_request', SubmitType::class, ['label' => _m('Submit request')]],
]); ]);
@ -38,7 +45,7 @@ class ResetPassword extends Controller
return [ return [
'_template' => 'reset_password/request.html.twig', '_template' => 'reset_password/request.html.twig',
'password_reset_form' => $from->createView(), 'password_reset_form' => $form->createView(),
]; ];
} }
@ -83,7 +90,7 @@ class ResetPassword extends Controller
} }
// The token is valid; allow the user to change their password. // The token is valid; allow the user to change their password.
$form = From::create([ $form = Form::create([
FormFields::repeated_password(), FormFields::repeated_password(),
['password_reset', SubmitType::class, ['label' => _m('Change password')]], ['password_reset', SubmitType::class, ['label' => _m('Change password')]],
]); ]);

View File

@ -13,7 +13,8 @@ use App\Entity\GSActor;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use App\Entity\Note; use App\Entity\Note;
use App\Security\Authenticator; use App\Security\Authenticator;
use app\Util\Common; use App\Security\EmailVerifier;
use App\Util\Common;
use App\Util\Exception\EmailTakenException; use App\Util\Exception\EmailTakenException;
use App\Util\Exception\NicknameTakenException; use App\Util\Exception\NicknameTakenException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
@ -142,7 +143,7 @@ class Security extends Controller
// generate a signed url and email it to the user // generate a signed url and email it to the user
if ($_ENV['APP_ENV'] !== 'dev' && Common::config('site', 'use_email')) { if ($_ENV['APP_ENV'] !== 'dev' && Common::config('site', 'use_email')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
Common::sendVerificationEmail(); EmailVerifier::sendEmailConfirmation($user);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} else { } else {
$user->setIsEmailVerified(true); $user->setIsEmailVerified(true);

View File

@ -43,6 +43,7 @@ use App\Entity\UserNotificationPrefs;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\AuthenticationException; use App\Util\Exception\AuthenticationException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use App\Util\Form\ActorArrayTransformer;
use App\Util\Form\ArrayTransformer; use App\Util\Form\ArrayTransformer;
use App\Util\Form\FormFields; use App\Util\Form\FormFields;
use App\Util\Formatting; use App\Util\Formatting;

View File

@ -73,7 +73,7 @@ abstract class Cache
} }
$class = RedisCluster::class; // true for persistent connection $class = RedisCluster::class; // true for persistent connection
$seeds = F\Map($dsns, fn ($str) => explode('://', $str)[1]); $seeds = F\Map($dsns, fn ($str) => explode('://', $str)[1]);
$r = new RedisCluster(name: null, seeds: $seeds, timeout: null, read_timeout: null, persistent: true); $r = new RedisCluster(name: null, seeds: $seeds, timeout: null, readTimeout: null, persistent: true);
// Distribute reads randomly // Distribute reads randomly
$r->setOption($class::OPT_SLAVE_FAILOVER, $class::FAILOVER_DISTRIBUTE); $r->setOption($class::OPT_SLAVE_FAILOVER, $class::FAILOVER_DISTRIBUTE);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
@ -102,7 +102,7 @@ abstract class Cache
$adapters[$pool][] = new Adapter\ApcuAdapter(); $adapters[$pool][] = new Adapter\ApcuAdapter();
break; break;
case 'opcache': case 'opcache':
$adapters[$pool][] = new Adapter\PhpArrayAdapter($rest, new FilesystemAdapter($rest . '.fallback')); $adapters[$pool][] = new Adapter\PhpArrayAdapter($rest, new Adapter\FilesystemAdapter($rest . '.fallback'));
break; break;
case 'doctrine': case 'doctrine':
$adapters[$pool][] = new Adapter\PdoAdapter($dsn); $adapters[$pool][] = new Adapter\PdoAdapter($dsn);

View File

@ -23,7 +23,6 @@ namespace App\Core;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use App\Util\Exception\ServerException;
use App\Util\Formatting; use App\Util\Formatting;
use DateTime; use DateTime;
@ -53,7 +52,7 @@ abstract class Entity
*/ */
public static function create(array $args, $obj = null) public static function create(array $args, $obj = null)
{ {
$class = get_called_class(); $class = static::class;
$obj = $obj ?: new $class(); $obj = $obj ?: new $class();
$date = new DateTime(); $date = new DateTime();
foreach (['created', 'modified'] as $prop) { foreach (['created', 'modified'] as $prop) {

View File

@ -20,13 +20,14 @@
namespace App\Core\Modules; namespace App\Core\Modules;
use App\Util\Common; use App\Util\Common;
use App\Util\Formatting;
/** /**
* Base class for all GNU social modules (plugins and components) * Base class for all GNU social modules (plugins and components)
*/ */
abstract class Module abstract class Module
{ {
const MODULE_TYPE = 'module';
/** /**
* Load values from the config and set them as properties on each module object * Load values from the config and set them as properties on each module object
*/ */
@ -54,8 +55,7 @@ abstract class Module
*/ */
public static function __set_state($state) public static function __set_state($state)
{ {
$class = get_called_class(); $obj = new (static::class);
$obj = new $class();
foreach ($state as $k => $v) { foreach ($state as $k => $v) {
$obj->{$k} = $v; $obj->{$k} = $v;
} }

View File

@ -125,7 +125,7 @@ class Invitation extends Entity
'user_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'many to one', 'name' => 'invitation_user_id_fkey', 'not null' => true, 'description' => 'who sent the invitation'], 'user_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'many to one', 'name' => 'invitation_user_id_fkey', 'not null' => true, 'description' => 'who sent the invitation'],
'address' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'invitation sent to'], 'address' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'invitation sent to'],
'address_type' => ['type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'], 'address_type' => ['type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'],
'registered_user_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'one to one', 'name' => 'invitation_registered_user_id_fkey', 'type' => 'int', 'not null' => false, 'description' => 'if the invitation is converted, who the new user is'], 'registered_user_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'one to one', 'name' => 'invitation_registered_user_id_fkey', 'not null' => false, 'description' => 'if the invitation is converted, who the new user is'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
], ],
'primary key' => ['code'], 'primary key' => ['code'],

View File

@ -87,7 +87,7 @@ class RelatedGroup extends Entity
// @fixme description for related_group? // @fixme description for related_group?
'fields' => [ 'fields' => [
'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to group'], 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to group'],
'related_group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'type' => 'int', 'not null' => true, 'description' => 'foreign key to group'], 'related_group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to group'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
], ],
'primary key' => ['group_id', 'related_group_id'], 'primary key' => ['group_id', 'related_group_id'],

View File

@ -47,35 +47,6 @@ class Kernel extends BaseKernel
public const CONFIG_EXTS = '.{php,xml,yaml,yml}'; public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);
if (!defined('INSTALLDIR')) {
define('INSTALLDIR', dirname(__DIR__));
define('SRCDIR', INSTALLDIR . '/src');
define('PUBLICDIR', INSTALLDIR . '/public');
define('GNUSOCIAL_ENGINE_NAME', 'GNU social');
// MERGE Change to https://gnu.io/social/
define('GNUSOCIAL_PROJECT_URL', 'https://gnusocial.rocks/');
// MERGE Change to https://git.gnu.io/gnu/gnu-social
define('GNUSOCIAL_REPOSITORY_URL', 'https://code.undefinedhackers.net/GNUsocial/gnu-social');
// Current base version, major.minor.patch
define('GNUSOCIAL_BASE_VERSION', '3.0.0');
// 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
define('GNUSOCIAL_LIFECYCLE', 'dev');
define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
define('GNUSOCIAL_CODENAME', 'Big bang');
define('URL_REGEX_DOMAIN_NAME', '(?:(?!-)[A-Za-z0-9\-]{1,63}(?<!-)\.)+[A-Za-z]{2,10}');
// Work internally in UTC
date_default_timezone_set('UTC');
// Work internally with UTF-8
mb_internal_encoding('UTF-8');
}
}
/** /**
* Symfony framework function override responsible for registering * Symfony framework function override responsible for registering
* bundles (similar to our modules) * bundles (similar to our modules)

View File

@ -4,6 +4,8 @@ namespace App\Security;
use App\Core\Controller; use App\Core\Controller;
use App\Core\DB\DB; use App\Core\DB\DB;
use function App\Core\I18n\_m;
use App\Util\Common;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bridge\Twig\Mime\TemplatedEmail;
@ -11,6 +13,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface; use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
use SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface; use SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface;
@ -61,7 +64,7 @@ abstract class EmailVerifier
self::send($email); self::send($email);
} }
public function send($email) public static function send($email)
{ {
return self::$mailer_helper->send($email); return self::$mailer_helper->send($email);
} }
@ -77,7 +80,7 @@ abstract class EmailVerifier
DB::flush(); DB::flush();
} }
public function processSendingPasswordResetEmail(string $emailFormData, Controller $controller) public static function processSendingPasswordResetEmail(string $emailFormData, Controller $controller)
{ {
try { try {
$user = DB::findOneBy('local_user', ['outgoing_email' => $emailFormData]); $user = DB::findOneBy('local_user', ['outgoing_email' => $emailFormData]);

View File

@ -32,7 +32,7 @@ abstract class Bitmap
private static function _to(int $r, bool $instance) private static function _to(int $r, bool $instance)
{ {
$init = $r; $init = $r;
$class = get_called_class(); $class = static::class;
if ($instance) { if ($instance) {
$obj = new $class; $obj = new $class;
} else { } else {

View File

@ -19,6 +19,8 @@
namespace App\Util\Exception; namespace App\Util\Exception;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router; use App\Core\Router\Router;
use Exception; use Exception;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;

View File

@ -45,7 +45,8 @@ abstract class FormFields
*/ */
public static function password(array $options = []): array public static function password(array $options = []): array
{ {
['password', PasswordType::class, [ return [
'password', PasswordType::class, [
'label' => _m('Password'), 'label' => _m('Password'),
'label_attr' => ['class' => 'section-form-label'], 'label_attr' => ['class' => 'section-form-label'],
'attr' => ['placeholder' => '********'], 'attr' => ['placeholder' => '********'],

View File

@ -31,6 +31,7 @@ use App\Util\Exception\NicknameReservedException;
use App\Util\Exception\NicknameTakenException; use App\Util\Exception\NicknameTakenException;
use App\Util\Exception\NicknameTooLongException; use App\Util\Exception\NicknameTooLongException;
use App\Util\Exception\NicknameTooShortException; use App\Util\Exception\NicknameTooShortException;
use App\Util\Exception\NotImplementedException;
use Functional as F; use Functional as F;
use Normalizer; use Normalizer;
@ -154,7 +155,7 @@ class Nickname
break; break;
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
case self::CHECK_LOCAL_GROUP: case self::CHECK_LOCAL_GROUP:
throw new \NotImplementedException(); throw new NotImplementedException();
break; break;
default: default:
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();

View File

@ -30,7 +30,7 @@
namespace App\Util\Notification; namespace App\Util\Notification;
use App\Entity\Gsactor; use App\Entity\GSActor;
class Notification class Notification
{ {

View File

@ -19,6 +19,7 @@
namespace App\Util; namespace App\Util;
use function App\Core\I18n\_m;
use App\Util\Exception\TemporaryFileException; use App\Util\Exception\TemporaryFileException;
use Symfony\Component\Mime\MimeTypes; use Symfony\Component\Mime\MimeTypes;

View File

@ -76,6 +76,7 @@ class AttachmentTest extends GNUsocialTestCase
$test = function (string $method) { $test = function (string $method) {
$temp_file = new TemporaryFile(); $temp_file = new TemporaryFile();
$temp_file->write(file_get_contents(INSTALLDIR . '/tests/sample-uploads/gnu-logo.png')); $temp_file->write(file_get_contents(INSTALLDIR . '/tests/sample-uploads/gnu-logo.png'));
$hash = null;
Event::handle('HashFile', [$temp_file->getPathname(), &$hash]); Event::handle('HashFile', [$temp_file->getPathname(), &$hash]);
$attachment = DB::findOneBy('attachment', ['filehash' => $hash]); $attachment = DB::findOneBy('attachment', ['filehash' => $hash]);
$attachment->{$method}(); $attachment->{$method}();
@ -118,6 +119,7 @@ class AttachmentTest extends GNUsocialTestCase
public function testMimetype() public function testMimetype()
{ {
$file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/image.jpg'); $file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/image.jpg');
$hash = null;
Event::handle('HashFile', [$file->getPathname(), &$hash]); Event::handle('HashFile', [$file->getPathname(), &$hash]);
$attachment = DB::findOneBy('attachment', ['filehash' => $hash]); $attachment = DB::findOneBy('attachment', ['filehash' => $hash]);

View File

@ -38,6 +38,7 @@ class AttachmentThumbnailTest extends GNUsocialTestCase
// Data fixture already loaded this file, but we need to get its hash to find it // Data fixture already loaded this file, but we need to get its hash to find it
$file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/attachment-lifecycle-target.jpg'); $file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/attachment-lifecycle-target.jpg');
$hash = null;
Event::handle('HashFile', [$file->getPathname(), &$hash]); Event::handle('HashFile', [$file->getPathname(), &$hash]);
$attachment = DB::findOneBy('attachment', ['filehash' => $hash]); $attachment = DB::findOneBy('attachment', ['filehash' => $hash]);
@ -73,6 +74,7 @@ class AttachmentThumbnailTest extends GNUsocialTestCase
parent::bootKernel(); parent::bootKernel();
$file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/spreadsheet.ods'); $file = new \SplFileInfo(INSTALLDIR . '/tests/sample-uploads/spreadsheet.ods');
$hash = null;
Event::handle('HashFile', [$file->getPathname(), &$hash]); Event::handle('HashFile', [$file->getPathname(), &$hash]);
$attachment = DB::findOneBy('attachment', ['filehash' => $hash]); $attachment = DB::findOneBy('attachment', ['filehash' => $hash]);