From 430074ffa822c2456cabbbe77413fd2d615db7d4 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Fri, 3 Mar 2023 20:05:20 +0000 Subject: adjustments due to phpstan report, fixes #2257 Closes #2257 Merge request studip/studip!1490 --- lib/classes/ContentBar.php | 7 ++++--- lib/classes/CoursewarePDFCertificate.php | 7 +++---- lib/classes/JsonApi/Routes/Courseware/UnitsCopy.php | 10 ++++++++-- lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php | 2 +- lib/classes/JsonApi/Routes/Courseware/UnitsUpdate.php | 2 ++ lib/classes/JsonApi/Routes/Files/FileRefsContentShow.php | 2 +- lib/classes/Virusscanner.php | 7 +++++++ lib/cronjobs/remind_oer_upload.class.php | 15 ++++++--------- lib/cronjobs/send_mail_notifications.class.php | 2 +- lib/models/QuestionnaireInfo.php | 4 +--- lib/models/User.class.php | 5 ++++- 11 files changed, 38 insertions(+), 25 deletions(-) diff --git a/lib/classes/ContentBar.php b/lib/classes/ContentBar.php index 53b3dfc..0e6a664 100644 --- a/lib/classes/ContentBar.php +++ b/lib/classes/ContentBar.php @@ -36,18 +36,19 @@ class ContentBar public static function get(): ContentBar { if (static::$instance === null) { - static::$instance = new static; + static::$instance = new static(); } return static::$instance; } /** * Private constructor to ensure that the singleton Get() method is always - * used. + * used. The constructor is finalized so that the call to get() will never + * fail. * * @see ContentBar::get */ - protected function __construct() + protected final function __construct() { } diff --git a/lib/classes/CoursewarePDFCertificate.php b/lib/classes/CoursewarePDFCertificate.php index e3ef02f..ca6e704 100644 --- a/lib/classes/CoursewarePDFCertificate.php +++ b/lib/classes/CoursewarePDFCertificate.php @@ -2,13 +2,12 @@ class CoursewarePDFCertificate extends TCPDF { + protected $background; + public function __construct($background = false, $orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8') { - $this->config = Config::get(); - if ($this->config->getValue('LOAD_EXTERNAL_MEDIA') === 'proxy') { - $this->media_proxy = new MediaProxy(); - } parent::__construct($orientation, $unit, $format, $unicode, $encoding, false); + if ($background) { $fileRef = FileRef::find($background); $this->background = $fileRef->file->getPath(); diff --git a/lib/classes/JsonApi/Routes/Courseware/UnitsCopy.php b/lib/classes/JsonApi/Routes/Courseware/UnitsCopy.php index 5365459..61ffa95 100644 --- a/lib/classes/JsonApi/Routes/Courseware/UnitsCopy.php +++ b/lib/classes/JsonApi/Routes/Courseware/UnitsCopy.php @@ -32,7 +32,13 @@ class UnitsCopy extends NonJsonApiController $rangeType = $data['rangeType']; $modified = $data['modified']; - if (!Authority::canCreateUnit($user)) { + try { + $range = \RangeFactory::createRange($rangeType, $rangeId); + } catch (\Exception $e) { + throw new RecordNotFoundException('Range could not be found'); + } + + if (!Authority::canCreateUnit($user, $range)) { throw new AuthorizationFailedException(); } @@ -43,4 +49,4 @@ class UnitsCopy extends NonJsonApiController return $response; } -} \ No newline at end of file +} diff --git a/lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php b/lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php index c109619..f8fb17b 100644 --- a/lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php +++ b/lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php @@ -3,12 +3,12 @@ namespace JsonApi\Routes\Courseware; use JsonApi\Errors\AuthorizationFailedException; +use JsonApi\Errors\RecordNotFoundException; use JsonApi\JsonApiController; use JsonApi\Routes\ValidationTrait; use JsonApi\Schemas\Courseware\Unit as UnitSchema; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Studip\Activity\Activity; /** * Create a block in a container. diff --git a/lib/classes/JsonApi/Routes/Courseware/UnitsUpdate.php b/lib/classes/JsonApi/Routes/Courseware/UnitsUpdate.php index 53fccd3..762fb04 100644 --- a/lib/classes/JsonApi/Routes/Courseware/UnitsUpdate.php +++ b/lib/classes/JsonApi/Routes/Courseware/UnitsUpdate.php @@ -6,6 +6,7 @@ use Courseware\Unit; use JsonApi\Errors\AuthorizationFailedException; use JsonApi\Errors\RecordNotFoundException; use JsonApi\JsonApiController; +use JsonApi\Routes\TimestampTrait; use JsonApi\Routes\ValidationTrait; use JsonApi\Schemas\Courseware\Unit as UnitSchema; use Psr\Http\Message\ResponseInterface as Response; @@ -17,6 +18,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; class UnitsUpdate extends JsonApiController { use EditBlockAwareTrait; + use TimestampTrait; use ValidationTrait; /** diff --git a/lib/classes/JsonApi/Routes/Files/FileRefsContentShow.php b/lib/classes/JsonApi/Routes/Files/FileRefsContentShow.php index b2b67ce..e2d19c4 100644 --- a/lib/classes/JsonApi/Routes/Files/FileRefsContentShow.php +++ b/lib/classes/JsonApi/Routes/Files/FileRefsContentShow.php @@ -114,7 +114,7 @@ class FileRefsContentShow extends NonJsonApiController $fileRef->incrementDownloadCounter(); - $stream = Psr7\stream_for(fopen($pathFile, 'rb')); + $stream = Psr7\Utils::streamFor(fopen($pathFile, 'rb')); return $response->withBody($stream); } diff --git a/lib/classes/Virusscanner.php b/lib/classes/Virusscanner.php index 628fdba..077e3e2 100644 --- a/lib/classes/Virusscanner.php +++ b/lib/classes/Virusscanner.php @@ -89,6 +89,13 @@ class Virusscanner } /** + * Finalized constructor so that the instantition in scan() will never fail. + */ + protected final function __construct() + { + } + + /** * Establishes a connection to virus scanner via socket or TCP, depending on Stud.IP configuration. * * @return resource|null diff --git a/lib/cronjobs/remind_oer_upload.class.php b/lib/cronjobs/remind_oer_upload.class.php index 9ac20e7..a1a8ee1 100644 --- a/lib/cronjobs/remind_oer_upload.class.php +++ b/lib/cronjobs/remind_oer_upload.class.php @@ -39,10 +39,10 @@ class RemindOerUpload extends CronJob $filetype = $file_ref->getFileType(); $file_to_suggest = $filetype->convertToStandardFile(); - $this->author = $file_ref->owner->username; - $this->link_to_share = URLHelper::getURL('dispatch.php/file/share_oer/' . $result['file_ref_id']); - $this->linktext = _('Klicken Sie hier, um das Material im OER-Campus zu veröffentlichen.'); - $this->formatted_link = '['. $this->linktext .']' . $this->link_to_share; + $author = $file_ref->owner->username; + $link_to_share = URLHelper::getURL('dispatch.php/file/share_oer/' . $result['file_ref_id']); + $linktext = _('Klicken Sie hier, um das Material im OER-Campus zu veröffentlichen.'); + $formatted_link = '['. $linktext .']' . $link_to_share; $oer_reminder_message = sprintf(_("Sie wollten daran erinnert werden, die folgende Datei im OER-Campus zu veröffentlichen:\n\n" . "Dateiname: %s \n" @@ -50,14 +50,14 @@ class RemindOerUpload extends CronJob . "%s \n\n"), $file_to_suggest->getFilename(), $file_to_suggest->getDescription(), - $this->formatted_link + $formatted_link ); $messaging = new messaging(); $messaging->insert_message( $oer_reminder_message, - $this->author, + $author, '____%system%____', '', Request::option('message_id'), @@ -67,10 +67,7 @@ class RemindOerUpload extends CronJob ); OERPostUpload::deleteBySQL("file_ref_id = ?", [$result['file_ref_id']]); - } - } - } } diff --git a/lib/cronjobs/send_mail_notifications.class.php b/lib/cronjobs/send_mail_notifications.class.php index c336308..0888294 100644 --- a/lib/cronjobs/send_mail_notifications.class.php +++ b/lib/cronjobs/send_mail_notifications.class.php @@ -114,7 +114,7 @@ class SendMailNotificationsJob extends CronJob return; } - $GLOBALS['user'] = new Seminar_user($user); + $GLOBALS['user'] = new Seminar_User($user); $ok = false; $mailmessage = $notification->getAllNotifications($user->id); diff --git a/lib/models/QuestionnaireInfo.php b/lib/models/QuestionnaireInfo.php index 7596586..0b1493c 100644 --- a/lib/models/QuestionnaireInfo.php +++ b/lib/models/QuestionnaireInfo.php @@ -1,6 +1,4 @@ info = new UserInfo(); $user->setData($data); $user->setNew($is_new); -- cgit v1.0