diff --git a/modules/cms/ServiceProvider.php b/modules/cms/ServiceProvider.php index 59e3337e5..603052295 100644 --- a/modules/cms/ServiceProvider.php +++ b/modules/cms/ServiceProvider.php @@ -3,14 +3,12 @@ use App; use Lang; use Event; -use Backend; use BackendMenu; use BackendAuth; use Backend\Models\UserRole; use Backend\Classes\WidgetManager; use October\Rain\Support\ModuleServiceProvider; use System\Classes\SettingsManager; -use System\Classes\CombineAssets; use Cms\Classes\ComponentManager; use Cms\Classes\Page as CmsPage; use Cms\Classes\CmsObject; @@ -242,7 +240,7 @@ class ServiceProvider extends ModuleServiceProvider protected function registerBackendWidgets() { WidgetManager::instance()->registerFormWidgets(function ($manager) { - $manager->registerFormWidget('Cms\FormWidgets\Components'); + $manager->registerFormWidget(FormWidgets\Components::class); }); } @@ -267,7 +265,7 @@ class ServiceProvider extends ModuleServiceProvider 'description' => 'cms::lang.maintenance.settings_menu_description', 'category' => SettingsManager::CATEGORY_CMS, 'icon' => 'icon-plug', - 'class' => 'Cms\Models\MaintenanceSetting', + 'class' => Models\MaintenanceSetting::class, 'permissions' => ['cms.manage_themes'], 'order' => 300 ], @@ -297,13 +295,13 @@ class ServiceProvider extends ModuleServiceProvider }); Event::listen('pages.menuitem.getTypeInfo', function ($type) { - if ($type == 'cms-page') { + if ($type === 'cms-page') { return CmsPage::getMenuTypeInfo($type); } }); Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) { - if ($type == 'cms-page') { + if ($type === 'cms-page') { return CmsPage::resolveMenuItem($item, $url, $theme); } }); @@ -321,7 +319,7 @@ class ServiceProvider extends ModuleServiceProvider }); Event::listen('backend.richeditor.getTypeInfo', function ($type) { - if ($type == 'cms-page') { + if ($type === 'cms-page') { return CmsPage::getRichEditorTypeInfo($type); } }); diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index f3bdb2d91..ac29d6ad7 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -148,7 +148,7 @@ class Controller $url = Request::path(); } - if (!strlen($url)) { + if (empty($url)) { $url = '/'; } @@ -156,10 +156,8 @@ class Controller * Hidden page */ $page = $this->router->findByUrl($url); - if ($page && $page->is_hidden) { - if (!BackendAuth::getUser()) { - $page = null; - } + if ($page && $page->is_hidden && !BackendAuth::getUser()) { + $page = null; } /* diff --git a/modules/cms/classes/Layout.php b/modules/cms/classes/Layout.php index 62df7e8e3..8c681321d 100644 --- a/modules/cms/classes/Layout.php +++ b/modules/cms/classes/Layout.php @@ -41,7 +41,7 @@ class Layout extends CmsCompoundObject */ public function isFallBack() { - return $this->fileName == self::FALLBACK_FILE_NAME; + return $this->fileName === self::FALLBACK_FILE_NAME; } /** @@ -50,6 +50,6 @@ class Layout extends CmsCompoundObject */ public function getCodeClassParent() { - return '\Cms\Classes\LayoutCode'; + return LayoutCode::class; } } diff --git a/modules/cms/classes/MediaLibrary.php b/modules/cms/classes/MediaLibrary.php index 34a445e41..8506c1081 100644 --- a/modules/cms/classes/MediaLibrary.php +++ b/modules/cms/classes/MediaLibrary.php @@ -17,7 +17,7 @@ class MediaLibrary extends SystemMediaLibrary */ protected function init() { - traceLog('Class Cms\Classes\MediaLibrary has been deprecated, use ' . SystemMediaLibrary::class . ' instead.'); + traceLog('Class ' . __CLASS__ . ' has been deprecated, use ' . SystemMediaLibrary::class . ' instead.'); parent::init(); } } diff --git a/modules/cms/classes/Page.php b/modules/cms/classes/Page.php index 23d2b169f..4c1b9bef7 100644 --- a/modules/cms/classes/Page.php +++ b/modules/cms/classes/Page.php @@ -72,7 +72,7 @@ class Page extends CmsCompoundObject */ public function getCodeClassParent() : string { - return '\Cms\Classes\PageCode'; + return PageCode::class; } /** diff --git a/modules/cms/components/Resources.php b/modules/cms/components/Resources.php index 251e93096..a8993997b 100644 --- a/modules/cms/components/Resources.php +++ b/modules/cms/components/Resources.php @@ -185,8 +185,7 @@ class Resources extends ComponentBase if (File::isDirectory($baseTheme.'/assets')) { return $baseTheme.'/assets'; } - else { - return $baseTheme.'/resources'; - } + + return $baseTheme.'/resources'; } } diff --git a/modules/cms/components/ViewBag.php b/modules/cms/components/ViewBag.php index ece5cd9a2..076e55e11 100644 --- a/modules/cms/components/ViewBag.php +++ b/modules/cms/components/ViewBag.php @@ -52,8 +52,8 @@ class ViewBag extends ComponentBase /** * Determine if an attribute exists on the object. - * @param string $key - * @return void + * @param string $key + * @return bool */ public function __isset($key) { diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index d0c7c4498..572afdcf1 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -24,6 +24,7 @@ use Backend\Classes\Controller; use Backend\Classes\WidgetManager; use October\Rain\Router\Router as RainRouter; use ApplicationException; +use Cms\Classes\Asset; /** * CMS index @@ -126,7 +127,7 @@ class Index extends Controller $this->vars['templatePath'] = Request::input('path'); - if ($type == 'page') { + if ($type === 'page') { $router = new RainRouter; $this->vars['pageUrl'] = $router->urlFromPattern($template->url); } @@ -203,7 +204,7 @@ class Index extends Controller 'tabTitle' => $this->getTabTitle($type, $template) ]; - if ($type == 'page') { + if ($type === 'page') { $result['pageUrl'] = Url::to($template->url); $router = new Router($this->theme); $router->clearCache(); @@ -223,7 +224,7 @@ class Index extends Controller $type = Request::input('type'); $template = $this->createTemplate($type); - if ($type == 'asset') { + if ($type === 'asset') { $template->fileName = $this->widget->assetList->getCurrentRelativePath(); } @@ -306,7 +307,7 @@ class Index extends Controller } // Can only expand components at this stage - if ((!$type = post('tokenType')) && $type != 'component') { + if ((!$type = post('tokenType')) && $type !== 'component') { return; } @@ -345,11 +346,11 @@ class Index extends Controller protected function resolveTypeClassName($type) { $types = [ - 'page' => '\Cms\Classes\Page', - 'partial' => '\Cms\Classes\Partial', - 'layout' => '\Cms\Classes\Layout', - 'content' => '\Cms\Classes\Content', - 'asset' => '\Cms\Classes\Asset' + 'page' => Page::class, + 'partial' => Partial::class, + 'layout' => Layout::class, + 'content' => Content::class, + 'asset' => Asset::class ]; if (!array_key_exists($type, $types)) { @@ -388,7 +389,7 @@ class Index extends Controller protected function getTabTitle($type, $template) { - if ($type == 'page') { + if ($type === 'page') { $result = $template->title ?: $template->getFileName(); if (!$result) { $result = trans('cms::lang.page.new'); @@ -397,7 +398,7 @@ class Index extends Controller return $result; } - if ($type == 'partial' || $type == 'layout' || $type == 'content' || $type == 'asset') { + if ($type === 'partial' || $type === 'layout' || $type === 'content' || $type === 'asset') { $result = in_array($type, ['asset', 'content']) ? $template->getFileName() : $template->getBaseFileName(); if (!$result) { $result = trans('cms::lang.'.$type.'.new'); @@ -504,8 +505,7 @@ class Index extends Controller */ protected function convertLineEndings($markup) { - $markup = str_replace("\r\n", "\n", $markup); - $markup = str_replace("\r", "\n", $markup); + $markup = str_replace(["\r\n", "\r"], "\n", $markup); return $markup; } diff --git a/modules/cms/controllers/Themes.php b/modules/cms/controllers/Themes.php index 378ab6666..ac3a06803 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -17,6 +17,7 @@ use Cms\Classes\ThemeManager; use System\Classes\SettingsManager; use Backend\Classes\Controller; use Exception; +use Backend\Widgets\Form; /** * Theme selector controller @@ -57,7 +58,7 @@ class Themes extends Controller /* * Enable AJAX for Form widgets */ - if (post('mode') == 'import') { + if (post('mode') === 'import') { $this->makeImportFormWidget($this->findThemeObject())->bindToController(); } } @@ -116,7 +117,7 @@ class Themes extends Controller $widgetConfig->arrayName = 'Theme'; $widgetConfig->context = 'update'; - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); + $widget = $this->makeWidget(Form::class, $widgetConfig); return $widget; } diff --git a/modules/cms/helpers/Cms.php b/modules/cms/helpers/Cms.php index 566ce4c53..d94ac1bdf 100644 --- a/modules/cms/helpers/Cms.php +++ b/modules/cms/helpers/Cms.php @@ -32,8 +32,7 @@ class Cms if (self::$actionExists) { return Url::action($routeAction, ['slug' => $path]); } - else { - return Url::to($path); - } + + return Url::to($path); } } diff --git a/modules/cms/helpers/File.php b/modules/cms/helpers/File.php index a99457e43..aa10b35d7 100644 --- a/modules/cms/helpers/File.php +++ b/modules/cms/helpers/File.php @@ -30,7 +30,7 @@ class File public static function validateExtension($fileName, $allowedExtensions, $allowEmpty = true) { $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); - if (!strlen($extension)) { + if (empty($extension)) { return $allowEmpty; } diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 1dd99f8b5..69194d310 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -5,6 +5,7 @@ use Model; use Cms\Classes\Theme as CmsTheme; use System\Classes\CombineAssets; use Exception; +use System\Models\File; /** * Customization data used by a theme @@ -106,11 +107,11 @@ class ThemeData extends Model continue; } - if ($field['type'] == 'repeater') { + if ($field['type'] === 'repeater') { $this->jsonable[] = $id; } - elseif ($field['type'] == 'fileupload') { - $this->attachOne[$id] = 'System\Models\File'; + elseif ($field['type'] === 'fileupload') { + $this->attachOne[$id] = File::class; unset($data[$id]); } } diff --git a/modules/cms/twig/Loader.php b/modules/cms/twig/Loader.php index c74450c8c..9172cd25b 100644 --- a/modules/cms/twig/Loader.php +++ b/modules/cms/twig/Loader.php @@ -112,7 +112,7 @@ class Loader extends LoaderBase implements Twig_LoaderInterface */ protected function validateCmsObject($name) { - if ($name == $this->obj->getFilePath()) { + if ($name === $this->obj->getFilePath()) { return true; } diff --git a/modules/system/twig/Loader.php b/modules/system/twig/Loader.php index eb17d3717..a581df9b9 100644 --- a/modules/system/twig/Loader.php +++ b/modules/system/twig/Loader.php @@ -42,7 +42,7 @@ class Loader implements Twig_LoaderInterface } $view = $name; - if (File::extension($view) == $this->extension) { + if (File::extension($view) === $this->extension) { $view = substr($view, 0, -strlen($this->extension)); } diff --git a/tests/fixtures/cms/reference/namespaces-aliases.php.stub b/tests/fixtures/cms/reference/namespaces-aliases.php.stub index 4213c29d1..a3425a4ce 100644 --- a/tests/fixtures/cms/reference/namespaces-aliases.php.stub +++ b/tests/fixtures/cms/reference/namespaces-aliases.php.stub @@ -1,7 +1,7 @@ getProperty($name); $property->setAccessible(true); @@ -48,19 +50,19 @@ class CodeParserTest extends TestCase $controller = new Controller($theme); $obj = $parser->source(null, $layout, $controller); - $this->assertInstanceOf('\Cms\Classes\LayoutCode', $obj); + $this->assertInstanceOf(LayoutCode::class, $obj); /* * Test the file contents */ $body = preg_replace('/^\s*function/m', 'public function', $layout->code); - $expectedContent = 'assertEquals($expectedContent, file_get_contents($info['filePath'])); @@ -136,11 +138,11 @@ class CodeParserTest extends TestCase $this->assertFileExists($info['filePath']); - $expectedContent = 'assertEquals($expectedContent, file_get_contents($info['filePath'])); } @@ -163,14 +165,14 @@ class CodeParserTest extends TestCase $this->assertFileExists($info['filePath']); $controller = new Controller($theme); $obj = $parser->source($page, null, $controller); - $this->assertInstanceOf('\Cms\Classes\PageCode', $obj); + $this->assertInstanceOf(PageCode::class, $obj); $body = preg_replace('/^\s*function/m', 'public function', $page->code); - $expectedContent = 'assertEquals($expectedContent, file_get_contents($info['filePath'])); } @@ -200,11 +202,11 @@ class CodeParserTest extends TestCase $this->assertInstanceOf('\Cms\Classes\PageCode', $obj); $body = preg_replace('/^\s*function/m', 'public function', $page->code); - $expectedContent = 'assertEquals($expectedContent, file_get_contents($info['filePath'])); @@ -226,14 +228,14 @@ class CodeParserTest extends TestCase $this->assertFileExists($info['filePath']); $controller = new Controller($theme); $obj = $parser->source($page, null, $controller); - $this->assertInstanceOf('\Cms\Classes\PageCode', $obj); + $this->assertInstanceOf(PageCode::class, $obj); $body = preg_replace('/^\s*function/m', 'public function', $page->code); - $expectedContent = 'assertEquals($expectedContent, file_get_contents($info['filePath'])); } @@ -261,9 +263,9 @@ class CodeParserTest extends TestCase $this->assertFileExists($info['filePath']); $controller = new Controller($theme); $obj = $parser->source($page, null, $controller); - $this->assertInstanceOf('\Cms\Classes\PageCode', $obj); + $this->assertInstanceOf(PageCode::class, $obj); - $referenceFilePath = base_path().'/tests/fixtures/cms/reference/namespaces.php.stub'; + $referenceFilePath = base_path() . '/tests/fixtures/cms/reference/namespaces.php.stub'; $this->assertFileExists($referenceFilePath); $referenceContents = $this->getContents($referenceFilePath); @@ -290,9 +292,9 @@ class CodeParserTest extends TestCase $this->assertFileExists($info['filePath']); $controller = new Controller($theme); $obj = $parser->source($page, null, $controller); - $this->assertInstanceOf('\Cms\Classes\PageCode', $obj); + $this->assertInstanceOf(PageCode::class, $obj); - $referenceFilePath = base_path().'/tests/fixtures/cms/reference/namespaces-aliases.php.stub'; + $referenceFilePath = base_path() . '/tests/fixtures/cms/reference/namespaces-aliases.php.stub'; $this->assertFileExists($referenceFilePath); $referenceContents = $this->getContents($referenceFilePath); @@ -301,15 +303,15 @@ class CodeParserTest extends TestCase $this->assertEquals($referenceContents, $this->getContents($info['filePath'])); } - // - // Helpers - // + // + // Helpers + // - protected function getContents($path) - { + protected function getContents($path) + { $content = file_get_contents($path); $content = preg_replace('~\R~u', PHP_EOL, $content); // Normalize EOL return $content; - } + } }