refactor: use psalm to fix documentation

pull/129/head
sualko 2021-02-24 15:23:26 +01:00
parent dedfd37cae
commit 3d9b579d55
16 changed files with 87 additions and 40 deletions

View File

@ -97,7 +97,7 @@ class Provider implements IProvider {
return $event; return $event;
} }
private function parseRoomCreated(IEvent $event) { private function parseRoomCreated(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
$event->setParsedSubject($this->l->t('You created the room %s.', [$params['name']])); $event->setParsedSubject($this->l->t('You created the room %s.', [$params['name']]));
@ -105,7 +105,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'room-created'); $this->setIcon($event, 'room-created');
} }
private function parseRoomDeleted(IEvent $event) { private function parseRoomDeleted(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) { if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) {
@ -121,7 +121,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'room-deleted'); $this->setIcon($event, 'room-deleted');
} }
private function parseShareCreated(IEvent $event) { private function parseShareCreated(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) { if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) {
@ -138,7 +138,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'share-created'); $this->setIcon($event, 'share-created');
} }
private function parseShareDeleted(IEvent $event) { private function parseShareDeleted(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) { if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) {
@ -155,7 +155,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'share-deleted'); $this->setIcon($event, 'share-deleted');
} }
private function parseMeetingStarted(IEvent $event) { private function parseMeetingStarted(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) { if ($this->activityManager->getCurrentUserId() === $event->getAuthor()) {
@ -171,7 +171,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'meeting-started'); $this->setIcon($event, 'meeting-started');
} }
private function parseMeetingEnded(IEvent $event) { private function parseMeetingEnded(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
$event->setParsedSubject($this->l->t('The meeting in room "%s" has ended.', [$params['name']])); $event->setParsedSubject($this->l->t('The meeting in room "%s" has ended.', [$params['name']]));
@ -179,7 +179,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'meeting-ended'); $this->setIcon($event, 'meeting-ended');
} }
private function parseRecordingReady(IEvent $event) { private function parseRecordingReady(IEvent $event): void {
$params = $event->getSubjectParameters(); $params = $event->getSubjectParameters();
$event->setParsedSubject($this->l->t('Recording for room "%s" is ready.', [$params['name']])); $event->setParsedSubject($this->l->t('Recording for room "%s" is ready.', [$params['name']]));
@ -187,7 +187,7 @@ class Provider implements IProvider {
$this->setIcon($event, 'recording-ready'); $this->setIcon($event, 'recording-ready');
} }
private function setIcon(IEvent $event, string $baseName) { private function setIcon(IEvent $event, string $baseName): void {
if ($this->activityManager->getRequirePNG()) { if ($this->activityManager->getRequirePNG()) {
$imagePath = $this->url->imagePath(Application::ID, 'actions/'.$baseName.'.png'); $imagePath = $this->url->imagePath(Application::ID, 'actions/'.$baseName.'.png');
} else { } else {
@ -197,7 +197,7 @@ class Provider implements IProvider {
$event->setIcon($this->url->getAbsoluteURL($imagePath)); $event->setIcon($this->url->getAbsoluteURL($imagePath));
} }
private function setSubjects(IEvent $event, string $subject, array $parameters) { private function setSubjects(IEvent $event, string $subject, array $parameters): void {
$placeholders = $replacements = []; $placeholders = $replacements = [];
foreach ($parameters as $placeholder => $parameter) { foreach ($parameters as $placeholder => $parameter) {
@ -213,7 +213,12 @@ class Provider implements IProvider {
->setRichSubject($subject, $parameters); ->setRichSubject($subject, $parameters);
} }
protected function getUser(string $uid) { /**
* @return string[]
*
* @psalm-return array{type: string, id: string, name: string}
*/
protected function getUser(string $uid): array {
$user = $this->userManager->get($uid); $user = $this->userManager->get($uid);
if ($user instanceof IUser) { if ($user instanceof IUser) {
@ -231,7 +236,12 @@ class Provider implements IProvider {
]; ];
} }
protected function getGroup($uid) { /**
* @return (mixed|string)[]
*
* @psalm-return array{type: string, id: mixed|string, name: mixed|string}
*/
protected function getGroup($uid): array {
$group = $this->groupManager->get($uid); $group = $this->groupManager->get($uid);
if ($group !== null) { if ($group !== null) {

View File

@ -53,11 +53,14 @@ class RoomShareListener implements IEventListener {
} }
} }
private function shareWithUser(string $subject, Room $room, RoomShare $share) { private function shareWithUser(string $subject, Room $room, RoomShare $share): void {
$this->createActivityEvent($subject, $room->getUserId(), $room, $share); $this->createActivityEvent($subject, $room->getUserId(), $room, $share);
$this->createActivityEvent($subject, $share->getShareWith(), $room, $share); $this->createActivityEvent($subject, $share->getShareWith(), $room, $share);
} }
/**
* @return void
*/
private function shareWithGroup(string $subject, Room $room, RoomShare $share) { private function shareWithGroup(string $subject, Room $room, RoomShare $share) {
$this->createActivityEvent($subject, $room->getUserId(), $room, $share); $this->createActivityEvent($subject, $room->getUserId(), $room, $share);
@ -72,7 +75,7 @@ class RoomShareListener implements IEventListener {
} }
} }
private function createActivityEvent(string $subject, string $affectedUser, Room $room, RoomShare $roomShare) { private function createActivityEvent(string $subject, string $affectedUser, Room $room, RoomShare $roomShare): void {
$activityEvent = $this->activityManager->generateEvent(); $activityEvent = $this->activityManager->generateEvent();
$activityEvent->setApp(Application::ID); $activityEvent->setApp(Application::ID);

View File

@ -51,14 +51,14 @@ class Application extends App {
} }
} }
private function registerAsPersonalSetting() { private function registerAsPersonalSetting(): void {
/** @var ISettingsManager */ /** @var ISettingsManager */
$settingsManager = $this->getContainer()->query(ISettingsManager::class); $settingsManager = $this->getContainer()->query(ISettingsManager::class);
$settingsManager->registerSetting(ISettingsManager::KEY_PERSONAL_SETTINGS, \OCA\BigBlueButton\Settings\Personal::class); $settingsManager->registerSetting(ISettingsManager::KEY_PERSONAL_SETTINGS, \OCA\BigBlueButton\Settings\Personal::class);
} }
private function registerAsNavigationEntry(string $name) { private function registerAsNavigationEntry(string $name): void {
$server = $this->getContainer()->getServer(); $server = $this->getContainer()->getServer();
$server->getNavigationManager()->add(function () use ($server, $name) { $server->getNavigationManager()->add(function () use ($server, $name) {
@ -72,7 +72,7 @@ class Application extends App {
}); });
} }
private function registerServiceListener(IEventDispatcher $dispatcher) { private function registerServiceListener(IEventDispatcher $dispatcher): void {
$dispatcher->addServiceListener(RoomCreatedEvent::class, RoomListener::class); $dispatcher->addServiceListener(RoomCreatedEvent::class, RoomListener::class);
$dispatcher->addServiceListener(RoomDeletedEvent::class, RoomListener::class); $dispatcher->addServiceListener(RoomDeletedEvent::class, RoomListener::class);

View File

@ -56,7 +56,7 @@ class API {
$this->urlHelper = $urlHelper; $this->urlHelper = $urlHelper;
} }
private function getServer() { private function getServer(): BigBlueButton {
if (!$this->server) { if (!$this->server) {
$apiUrl = $this->config->getAppValue('bbb', 'api.url'); $apiUrl = $this->config->getAppValue('bbb', 'api.url');
$secret = $this->config->getAppValue('bbb', 'api.secret'); $secret = $this->config->getAppValue('bbb', 'api.secret');
@ -175,7 +175,7 @@ class API {
return $this->recordToArray($records[0]); return $this->recordToArray($records[0]);
} }
public function getRecordings(Room $room) { public function getRecordings(Room $room): array {
$recordingParams = new GetRecordingsParameters(); $recordingParams = new GetRecordingsParameters();
$recordingParams->setMeetingId($room->uid); $recordingParams->setMeetingId($room->uid);
$recordingParams->setState('processing,processed,published,unpublished'); $recordingParams->setState('processing,processed,published,unpublished');
@ -201,7 +201,12 @@ class API {
return $response->isDeleted(); return $response->isDeleted();
} }
private function recordToArray(Record $record) { /**
* @return (array|bool|int|string)[]
*
* @psalm-return array{id: string, meetingId: string, name: string, published: bool, state: string, startTime: string, participants: int, type: string, length: string, url: string, metas: array}
*/
private function recordToArray(Record $record): array {
return [ return [
'id' => $record->getRecordId(), 'id' => $record->getRecordId(),
'meetingId' => $record->getMeetingId(), 'meetingId' => $record->getMeetingId(),
@ -217,7 +222,7 @@ class API {
]; ];
} }
public function check(string $url, string $secret) { public function check(string $url, string $secret): string {
$server = new BigBlueButton($url, $secret); $server = new BigBlueButton($url, $secret);
$meetingParams = new IsMeetingRunningParameters('foobar'); $meetingParams = new IsMeetingRunningParameters('foobar');

View File

@ -12,15 +12,15 @@ class Presentation {
$this->filename = $filename; $this->filename = $filename;
} }
public function getUrl() { public function getUrl(): string {
return $this->url; return $this->url;
} }
public function getFilename() { public function getFilename(): string {
return $this->filename; return $this->filename;
} }
public function isValid() { public function isValid(): bool {
return !empty($this->url) && !empty($this->filename); return !empty($this->url) && !empty($this->filename);
} }
} }

View File

@ -35,7 +35,7 @@ class HookController extends Controller {
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
} }
public function setToken(string $token) { public function setToken(string $token): void {
$this->token = $token; $this->token = $token;
$this->room = null; $this->room = null;
} }
@ -48,9 +48,12 @@ class HookController extends Controller {
/** /**
* @PublicPage * @PublicPage
*
* @NoCSRFRequired * @NoCSRFRequired
*
* @return void
*/ */
public function meetingEnded($recordingmarks = false) { public function meetingEnded($recordingmarks = false): void {
$recordingmarks = \boolval($recordingmarks); $recordingmarks = \boolval($recordingmarks);
$this->eventDispatcher->dispatch(MeetingEndedEvent::class, new MeetingEndedEvent($this->getRoom(), $recordingmarks)); $this->eventDispatcher->dispatch(MeetingEndedEvent::class, new MeetingEndedEvent($this->getRoom(), $recordingmarks));
@ -58,9 +61,12 @@ class HookController extends Controller {
/** /**
* @PublicPage * @PublicPage
*
* @NoCSRFRequired * @NoCSRFRequired
*
* @return void
*/ */
public function recordingReady() { public function recordingReady(): void {
$this->eventDispatcher->dispatch(RecordingReadyEvent::class, new RecordingReadyEvent($this->getRoom())); $this->eventDispatcher->dispatch(RecordingReadyEvent::class, new RecordingReadyEvent($this->getRoom()));
} }

View File

@ -56,7 +56,7 @@ class JoinController extends Controller {
$this->permission = $permission; $this->permission = $permission;
} }
public function setToken(string $token) { public function setToken(string $token): void {
$this->token = $token; $this->token = $token;
$this->room = null; $this->room = null;
} }
@ -69,7 +69,10 @@ class JoinController extends Controller {
/** /**
* @PublicPage * @PublicPage
*
* @NoCSRFRequired * @NoCSRFRequired
*
* @return RedirectResponse|TemplateResponse
*/ */
public function index($displayname, $u = '', $filename = '', $password = '') { public function index($displayname, $u = '', $filename = '', $password = '') {
$room = $this->getRoom(); $room = $this->getRoom();

View File

@ -4,6 +4,7 @@ namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\TemplateProvider; use OCA\BigBlueButton\TemplateProvider;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest; use OCP\IRequest;
class PageController extends Controller { class PageController extends Controller {
@ -18,9 +19,12 @@ class PageController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
*
* @NoCSRFRequired * @NoCSRFRequired
*
* @return TemplateResponse
*/ */
public function index() { public function index(): TemplateResponse {
return $this->templateProvider->getManager(); return $this->templateProvider->getManager();
} }
} }

View File

@ -80,7 +80,7 @@ class ServerController extends Controller {
return new DataResponse($success); return new DataResponse($success);
} }
public function check(?string $url, ?string $secret) { public function check(?string $url, ?string $secret): DataResponse {
if ($url === null || empty($url) || $secret === null || empty($secret)) { if ($url === null || empty($url) || $secret === null || empty($secret)) {
return new DataResponse(false); return new DataResponse(false);
} }
@ -88,7 +88,7 @@ class ServerController extends Controller {
return new DataResponse($this->server->check($url, $secret)); return new DataResponse($this->server->check($url, $secret));
} }
public function version(?string $url) { public function version(?string $url): DataResponse {
if ($url === null || empty($url)) { if ($url === null || empty($url)) {
return new DataResponse(false, Http::STATUS_NOT_FOUND); return new DataResponse(false, Http::STATUS_NOT_FOUND);
} }

View File

@ -22,7 +22,7 @@ class Crypto {
return $this->encodeBase64UrlSafe(\sha1($this->crypto->calculateHMAC($message), true)); return $this->encodeBase64UrlSafe(\sha1($this->crypto->calculateHMAC($message), true));
} }
public function verifyHMAC(string $message, string $mac) { public function verifyHMAC(string $message, string $mac): bool {
if ($message === null || $mac === null) { if ($message === null || $mac === null) {
return false; return false;
} }
@ -32,6 +32,9 @@ class Crypto {
return $validMac === $mac; return $validMac === $mac;
} }
/**
* @return false|string
*/
private function encodeBase64UrlSafe(string $data) { private function encodeBase64UrlSafe(string $data) {
$b64 = \base64_encode($data); $b64 = \base64_encode($data);

View File

@ -46,7 +46,7 @@ class UserDeletedListener implements IEventListener {
} }
} }
private function deleteSharesByRoomId(string $roomId) { private function deleteSharesByRoomId(string $roomId): void {
$shares = $this->shareService->findAll($roomId); $shares = $this->shareService->findAll($roomId);
foreach ($shares as $share) { foreach ($shares as $share) {
@ -54,7 +54,7 @@ class UserDeletedListener implements IEventListener {
} }
} }
private function deleteSharesByUserId(string $userId) { private function deleteSharesByUserId(string $userId): void {
$shares = $this->shareService->findByUserId($userId); $shares = $this->shareService->findByUserId($userId);
foreach ($shares as $share) { foreach ($shares as $share) {

View File

@ -23,6 +23,9 @@ class HookMiddleware extends Middleware {
$this->crypto = $crypto; $this->crypto = $crypto;
} }
/**
* @return void
*/
public function beforeController($controller, $methodName) { public function beforeController($controller, $methodName) {
if (!($controller instanceof HookController)) { if (!($controller instanceof HookController)) {
return; return;

View File

@ -18,6 +18,9 @@ class JoinMiddleware extends Middleware {
$this->request = $request; $this->request = $request;
} }
/**
* @return void
*/
public function beforeController($controller, $methodName) { public function beforeController($controller, $methodName) {
if (!($controller instanceof JoinController)) { if (!($controller instanceof JoinController)) {
return; return;

View File

@ -55,20 +55,20 @@ class Permission {
return $this->restrictionService->findByGroupIds($groupIds); return $this->restrictionService->findByGroupIds($groupIds);
} }
public function isAllowedToCreateRoom(string $uid) { public function isAllowedToCreateRoom(string $uid): bool {
$numberOfCreatedRooms = count($this->roomService->findAll($uid, [], [])); $numberOfCreatedRooms = count($this->roomService->findAll($uid, [], []));
$restriction = $this->getRestriction($uid); $restriction = $this->getRestriction($uid);
return $restriction->getMaxRooms() < 0 || $restriction->getMaxRooms() > $numberOfCreatedRooms; return $restriction->getMaxRooms() < 0 || $restriction->getMaxRooms() > $numberOfCreatedRooms;
} }
public function isUser(Room $room, ?string $uid) { public function isUser(Room $room, ?string $uid): bool {
return $this->hasPermission($room, $uid, function (RoomShare $share) { return $this->hasPermission($room, $uid, function (RoomShare $share) {
return $share->hasUserPermission(); return $share->hasUserPermission();
}); });
} }
public function isModerator(Room $room, ?string $uid) { public function isModerator(Room $room, ?string $uid): bool {
if ($room->everyoneIsModerator) { if ($room->everyoneIsModerator) {
return true; return true;
} }
@ -78,7 +78,7 @@ class Permission {
}); });
} }
public function isAdmin(Room $room, ?string $uid) { public function isAdmin(Room $room, ?string $uid): bool {
return $this->hasPermission($room, $uid, function (RoomShare $share) { return $this->hasPermission($room, $uid, function (RoomShare $share) {
return $share->hasAdminPermission(); return $share->hasAdminPermission();
}); });

View File

@ -57,7 +57,7 @@ class RoomService {
} }
} }
public function findByUid(string $uid) { public function findByUid(string $uid): ?Room {
try { try {
return $this->mapper->findByUid($uid); return $this->mapper->findByUid($uid);
} catch (Exception $e) { } catch (Exception $e) {
@ -66,7 +66,7 @@ class RoomService {
} }
} }
public function create(string $name, string $welcome, int $maxParticipants, bool $record, string $access, string $userId) { public function create(string $name, string $welcome, int $maxParticipants, bool $record, string $access, string $userId): \OCP\AppFramework\Db\Entity {
$room = new Room(); $room = new Room();
$room->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE)); $room->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE));
@ -92,6 +92,8 @@ class RoomService {
/** /**
* @param null|string $moderatorToken * @param null|string $moderatorToken
*
* @return \OCP\AppFramework\Db\Entity|null
*/ */
public function update(int $id, string $name, string $welcome, int $maxParticipants, bool $record, string $access, bool $everyoneIsModerator, bool $requireModerator, ?string $moderatorToken) { public function update(int $id, string $name, string $welcome, int $maxParticipants, bool $record, string $access, bool $everyoneIsModerator, bool $requireModerator, ?string $moderatorToken) {
try { try {
@ -119,6 +121,9 @@ class RoomService {
} }
} }
/**
* @return Room|null
*/
public function delete(int $id) { public function delete(int $id) {
try { try {
$room = $this->mapper->find($id); $room = $this->mapper->find($id);

View File

@ -21,7 +21,7 @@ class Section implements IIconSection {
* returns the ID of the section. It is supposed to be a lower case string, * returns the ID of the section. It is supposed to be a lower case string,
* e.g. 'ldap' * e.g. 'ldap'
* *
* @returns string * @return string
*/ */
public function getID() { public function getID() {
return 'bbb'; return 'bbb';
@ -50,6 +50,8 @@ class Section implements IIconSection {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @return string
*/ */
public function getIcon() { public function getIcon() {
return $this->url->imagePath('bbb', 'app-dark.svg'); return $this->url->imagePath('bbb', 'app-dark.svg');