Skip to content

Commit

Permalink
Merge pull request #141 from humhub-contrib/enh/php-cs-fixer
Browse files Browse the repository at this point in the history
Use PHP CS Fixer
  • Loading branch information
luke- authored Oct 3, 2024
2 parents b3d555e + 4444074 commit e9626cb
Show file tree
Hide file tree
Showing 44 changed files with 232 additions and 241 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: PHP CS Fixer

on: push

jobs:
fixers:
uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main
3 changes: 1 addition & 2 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class Events
{

public static function onSpaceMenuInit($event)
{
try {
Expand Down Expand Up @@ -63,7 +62,7 @@ public static function onProfileMenuInit($event)
'label' => Yii::t('GalleryModule.base', 'Gallery'),
'url' => Url::toGalleryOverview($event->sender->user),
'icon' => '<i class="fa fa-picture-o"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'gallery')
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'gallery'),
]);
}
} catch (\Throwable $e) {
Expand Down
9 changes: 4 additions & 5 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class Module extends ContentContainerModule
{

public $galleryMaxImages = 50;
public $snippetMaxImages = 20;
public $debug = false;
Expand All @@ -29,7 +28,7 @@ public function getContentContainerTypes()
{
return [
Space::class,
User::class
User::class,
];
}

Expand All @@ -43,8 +42,8 @@ public function getContentClasses(): array

public function getContainerPermissions($contentContainer = null)
{
return [
new WriteAccess()
return [
new WriteAccess(),
];
}

Expand Down Expand Up @@ -82,7 +81,7 @@ public function enableContentContainer(ContentContainerActiveRecord $container)
{
$streamGallery = new StreamGallery($container, Content::VISIBILITY_PUBLIC, [
'title' => Yii::t('GalleryModule.base', 'Posted pictures'),
'description' => Yii::t('GalleryModule.base', 'This gallery contains all posted pictures.')
'description' => Yii::t('GalleryModule.base', 'This gallery contains all posted pictures.'),
]);

$streamGallery->save();
Expand Down
11 changes: 5 additions & 6 deletions assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class Assets extends AssetBundle
{

/**
* v1.5 compatibility defer script loading
*
Expand All @@ -33,7 +32,7 @@ class Assets extends AssetBundle
public $defer = true;

public $publishOptions = [
'forceCopy' => false
'forceCopy' => false,
];

public $css = [
Expand All @@ -43,9 +42,9 @@ class Assets extends AssetBundle
public $js = [
'js/gallery.js',
];

public $jsOptions = [
'position' => \yii\web\View::POS_END
'position' => \yii\web\View::POS_END,
];

/**
Expand All @@ -62,8 +61,8 @@ public static function register($view)
$view->registerJsConfig('gallery', [
'fallbackImageUrl' => Media::getFallbackPreviewImageUrl(),
'text' => [
'error.loadImageError' => Yii::t('GalleryModule.base', 'Image could not be loaded')
]
'error.loadImageError' => Yii::t('GalleryModule.base', 'Image could not be loaded'),
],
]);

return parent::register($view);
Expand Down
1 change: 0 additions & 1 deletion assets/WallEntryAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class WallEntryAssets extends AssetBundle
{

/**
* @inheritdoc
*/
Expand Down
9 changes: 4 additions & 5 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use humhub\modules\gallery\Events;
use \humhub\modules\space\widgets\Menu;
use humhub\modules\space\widgets\Menu;
use humhub\modules\space\widgets\Sidebar as SpaceSidebar;
use \humhub\modules\user\widgets\ProfileMenu;
use \humhub\modules\user\widgets\ProfileSidebar;
use humhub\modules\user\widgets\ProfileMenu;
use humhub\modules\user\widgets\ProfileSidebar;

return [
'id' => 'gallery',
Expand All @@ -15,6 +15,5 @@
['class' => ProfileMenu::class,'event' => ProfileMenu::EVENT_INIT, 'callback' => [Events::class,'onProfileMenuInit']],
['class' => SpaceSidebar::class, 'event' => SpaceSidebar::EVENT_INIT, 'callback' => [Events::class, 'onSpaceSidebarInit']],
['class' => ProfileSidebar::class, 'event' => ProfileSidebar::EVENT_INIT, 'callback' => [Events::class, 'onProfileSidebarInit']],
]
],
];

28 changes: 14 additions & 14 deletions controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

use humhub\modules\content\components\ActiveQueryContent;
use humhub\modules\content\components\ContentActiveRecord;
use \humhub\modules\content\components\ContentContainerController;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\gallery\models\BaseGallery;
use humhub\modules\gallery\models\forms\ContainerSettings;
use humhub\modules\gallery\models\Media;
use \humhub\modules\gallery\Module;
use humhub\modules\gallery\Module;
use humhub\modules\gallery\widgets\GalleryList;
use humhub\modules\space\models\Space;
use \humhub\modules\user\models\User;
use \Yii;
use humhub\modules\user\models\User;
use Yii;
use yii\base\Exception;
use \yii\base\Model;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\data\BaseDataProvider;
use \yii\web\HttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;

/**
Expand Down Expand Up @@ -71,16 +71,16 @@ protected function prepareInitialItems($items)
protected function loadPage($page = 0)
{
$query = $this->getPaginationQuery();
if(!$query) {
if (!$query) {
throw new NotFoundHttpException();
}

return new ActiveDataProvider([
'query' => $query,
'pagination' => [
'page' => $page,
'pageSize' => $this->getPageSize()
]
'pageSize' => $this->getPageSize(),
],
]);
}

Expand All @@ -95,11 +95,11 @@ abstract protected function getGallery();

final protected function isAdmin()
{
if(Yii::$app->user->isGuest) {
if (Yii::$app->user->isGuest) {
return false;
}

if($this->contentContainer instanceof Space) {
if ($this->contentContainer instanceof Space) {
return $this->contentContainer->isAdmin();
}

Expand All @@ -114,13 +114,13 @@ public function actionLoadPage($page)

return $this->asJson([
'html' => GalleryList::widget(['entryList' => $models, 'entriesOnly' => true, 'parentGallery' => $this->getGallery()]),
'isLast' => $this->isLastPage($page)
'isLast' => $this->isLastPage($page),
]);
}

protected function isLastPage($page = 0)
{
if(!$this->dataProvider || !$this->dataProvider->getPagination()) {
if (!$this->dataProvider || !$this->dataProvider->getPagination()) {
return true;
}

Expand All @@ -135,7 +135,7 @@ protected function getPageSize()
protected function getSettings()
{
return new ContainerSettings([
'contentContainer' => $this->contentContainer
'contentContainer' => $this->contentContainer,
]);
}
}
47 changes: 23 additions & 24 deletions controllers/CustomGalleryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
use humhub\modules\file\libs\FileHelper;
use humhub\modules\gallery\helpers\Url;
use humhub\modules\gallery\models\BaseGallery;
use \humhub\modules\gallery\models\CustomGallery;
use humhub\modules\gallery\models\CustomGallery;
use humhub\modules\gallery\models\forms\GalleryEditForm;
use \humhub\modules\gallery\models\Media;
use humhub\modules\gallery\models\Media;
use humhub\modules\gallery\permissions\WriteAccess;
use \Yii;
use Yii;
use yii\base\Exception;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use \yii\web\HttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;
use \yii\web\UploadedFile;
use yii\web\UploadedFile;

/**
* Description of a Custom Gallery Controller for the gallery module.
Expand All @@ -34,7 +34,6 @@
*/
class CustomGalleryController extends BaseController
{

/**
* @var CustomGallery
*/
Expand All @@ -55,15 +54,15 @@ protected function renderGallery($items)
{
$gallery = $this->getGallery();

if(!$gallery->content->canView()) {
if (!$gallery->content->canView()) {
throw new ForbiddenHttpException();
}

return $this->render("gallery_view", [
'gallery'=> $gallery,
'gallery' => $gallery,
'media' => $items,
'container' => $this->contentContainer,
'showMore' => !$this->isLastPage() ? Url::toShowMoreMedia($this->contentContainer, $gallery->id) : false
'showMore' => !$this->isLastPage() ? Url::toShowMoreMedia($this->contentContainer, $gallery->id) : false,
]);
}

Expand All @@ -76,19 +75,19 @@ protected function renderGallery($items)
*/
protected function getGallery()
{
if($this->gallery) {
if ($this->gallery) {
return $this->gallery;
}

$gid = Yii::$app->request->get('gid');

if(!$gid) {
if (!$gid) {
throw new BadRequestHttpException();
}

$this->gallery = CustomGallery::find()->contentContainer($this->contentContainer)->where(['gallery_gallery.id' => $gid])->one();

if(!$this->gallery) {
if (!$this->gallery) {
throw new NotFoundHttpException();
}

Expand All @@ -104,13 +103,13 @@ protected function getGallery()
*/
public function actionEdit($gid = null)
{
if(!$gid && !$this->contentContainer->can(WriteAccess::class)) {
if (!$gid && !$this->contentContainer->can(WriteAccess::class)) {
throw new ForbiddenHttpException();
}

$gallery = $gid ? $this->getGallery($gid) : null;

if($gallery && !$gallery->content->canEdit()) {
if ($gallery && !$gallery->content->canEdit()) {
throw new ForbiddenHttpException();
}

Expand All @@ -121,10 +120,10 @@ public function actionEdit($gid = null)
}

return $this->renderPartial('modal_gallery_edit', [
'galleryForm' => $form,
'contentContainer' => $this->contentContainer,
'sortByCreated' => $this->getSettings()->sortByCreated,
'createdAt' => isset($this->gallery) ? $this->gallery->getCreatedAt() : null
'galleryForm' => $form,
'contentContainer' => $this->contentContainer,
'sortByCreated' => $this->getSettings()->sortByCreated,
'createdAt' => isset($this->gallery) ? $this->gallery->getCreatedAt() : null,
]);
}

Expand All @@ -140,15 +139,15 @@ public function actionDelete($gid)

$gallery = CustomGallery::findOne(['id' => $gid]);

if(!$gallery) {
if (!$gallery) {
throw new NotFoundHttpException();
}

if(!$gallery->content->canEdit()) {
if (!$gallery->content->canEdit()) {
throw new ForbiddenHttpException();
}

if($gallery->delete()) {
if ($gallery->delete()) {
$this->view->success(Yii::t('GalleryModule.base', 'Deleted'));
} else {
$this->view->error(Yii::t('GalleryModule.base', 'Item could not be deleted!'));
Expand All @@ -161,7 +160,7 @@ public function actionUpload()
{
$gallery = $this->getGallery();

if(!$gallery->content->canEdit()) {
if (!$gallery->content->canEdit()) {
throw new HttpException(404);
}

Expand All @@ -188,7 +187,7 @@ protected function handleMediaUpload(BaseGallery $gallery, UploadedFile $cfile)
return [
'name' => $mediaUpload->file_name,
'error' => true,
'errors' => implode(', ', $mediaUpload->getErrorSummary(true))
'errors' => implode(', ', $mediaUpload->getErrorSummary(true)),
];
}

Expand All @@ -208,7 +207,7 @@ protected function getOpenGallery($gid = null)
{
$id = $gid == null ? Yii::$app->request->get('gid') : $gid;

if(!$id) {
if (!$id) {
throw new HttpException(404);
}

Expand Down
Loading

0 comments on commit e9626cb

Please sign in to comment.