From 192a9aa52d95efc6a2ee927afda8477c7381d380 Mon Sep 17 00:00:00 2001 From: O3-Shop Date: Sat, 8 Apr 2023 22:47:11 +0200 Subject: [PATCH] improve code --- Application/Core/TinyMCE/Configuration.php | 5 +++++ Application/Core/TinyMCE/Loader.php | 17 +++++++++++++---- Application/Core/TinyMCE/Options/ContentCss.php | 5 ++++- .../Core/TinyMCE/Options/FilemanagerUrl.php | 1 + Application/Core/TinyMCE/Options/Language.php | 2 +- Application/Core/TinyMCE/Options/MinHeight.php | 4 ++-- Application/Core/TinyMCE/Options/Setup.php | 2 +- Application/Core/TinyMCE/Options/Toolbar.php | 12 ++++++++++-- Application/Core/TinyMCE/PluginList.php | 4 ++++ .../Core/TinyMCE/Plugins/Nonbreaking.php | 3 +++ Application/Core/TinyMCE/Plugins/Pagebreak.php | 3 +++ .../Core/TinyMCE/Plugins/PluginInterface.php | 3 +++ Application/Core/TinyMCE/Plugins/Preview.php | 3 +++ .../Core/TinyMCE/Plugins/SearchReplace.php | 3 +++ Application/Core/TinyMCE/Plugins/Table.php | 3 +++ .../Core/TinyMCE/Plugins/Visualblocks.php | 3 +++ Application/Core/TinyMCE/Plugins/WordCount.php | 3 +++ .../Core/TinyMCE/Toolbar/ToolbarInterface.php | 3 +++ Application/Core/TinyMCE/Toolbar/Undo.php | 3 +++ Application/Core/TinyMCE/ToolbarList.php | 4 ++++ Application/Core/TinyMCE/Utils.php | 2 +- Application/Core/config.php | 2 +- phpstan.neon | 10 ++++++++++ 23 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 phpstan.neon diff --git a/Application/Core/TinyMCE/Configuration.php b/Application/Core/TinyMCE/Configuration.php index 0b0bdbc..0b246f5 100644 --- a/Application/Core/TinyMCE/Configuration.php +++ b/Application/Core/TinyMCE/Configuration.php @@ -53,6 +53,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Options\ToolbarSticky; class Configuration { protected Loader $loader; + /** @var array */ protected array $options = []; public function __construct(Loader $loader) @@ -89,6 +90,10 @@ class Configuration { $sConfig = ''; + /** + * @var string $param + * @var string $value + */ foreach ($this->options as $param => $value) { $sConfig .= "$param: $value, "; } diff --git a/Application/Core/TinyMCE/Loader.php b/Application/Core/TinyMCE/Loader.php index 26b0731..5996c4e 100644 --- a/Application/Core/TinyMCE/Loader.php +++ b/Application/Core/TinyMCE/Loader.php @@ -49,7 +49,11 @@ class Loader { if (!$this->isEnabledForCurrentController()) return ''; - if ($this->contentIsPlain()) return $this->language->translateString('TINYMCE_PLAINCMS'); + if ($this->contentIsPlain()) { + /** @var string $message */ + $message = $this->language->translateString('TINYMCE_PLAINCMS'); + return $message; + } $configuration = oxNew(Configuration::class, $this); $configuration->build(); @@ -66,6 +70,7 @@ class Loader */ protected function isEnabledForCurrentController(): bool { + /** @var string[] $aEnabledClasses */ $aEnabledClasses = $this->getShopConfig()->getConfigParam( "aTinyMCE_classes", []); return in_array( $this->getShopConfig()->getActiveView()->getClassKey(), $aEnabledClasses); @@ -109,7 +114,7 @@ class Loader $sInit = str_replace( "'CONFIG':'VALUES'", $configuration->getConfig(), - file_get_contents(__DIR__.'/../../../out/scripts/init.js') + (string) file_get_contents(__DIR__.'/../../../out/scripts/init.js') ); $smarty = Registry::getUtilsView()->getSmarty(); $sSufix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : ''; @@ -131,6 +136,7 @@ class Loader $smarty = Registry::getUtilsView()->getSmarty(); $sSuffix = ($smarty->_tpl_vars["__oxid_include_dynamic"]) ? '_dynamic' : ''; + /** @var array $aInclude */ $aInclude = (array) Registry::getConfig()->getGlobalParameter('includes' . $sSuffix); $aInclude[3][] = Registry::getConfig()->getActiveView()->getViewConfig()->getModuleUrl( @@ -138,14 +144,17 @@ class Loader 'out/tinymce/tinymce.min.js' ); + /** @var string[] $aExtjs */ $aExtjs = Registry::getConfig()->getConfigParam('aTinyMCE_extjs', []); foreach ($aExtjs as $js) { $aInclude[3][] = $js; } - if (strlen(trim(Registry::getConfig()->getConfigParam('sTinyMCE_apikey', '')))) { + /** @var string $apiKey */ + $apiKey = Registry::getConfig()->getConfigParam('sTinyMCE_apikey', ''); + if (strlen(trim($apiKey))) { $aInclude[3][] = "https://cdn.tiny.cloud/1/". - trim(Registry::getConfig()->getConfigParam('sTinyMCE_apikey', '')). + trim($apiKey). "/tinymce/6/plugins.min.js"; } diff --git a/Application/Core/TinyMCE/Options/ContentCss.php b/Application/Core/TinyMCE/Options/ContentCss.php index 52e4135..c9bde1a 100644 --- a/Application/Core/TinyMCE/Options/ContentCss.php +++ b/Application/Core/TinyMCE/Options/ContentCss.php @@ -36,12 +36,15 @@ class ContentCss extends AbstractOption public function get(): string { + /** @var string $theme */ + $theme = Registry::getConfig()->getConfigParam('sTheme'); + return implode( ',', [ $this->darkMode ? 'dark' : - '/out/'.strtolower(Registry::getConfig()->getConfigParam('sTheme')).'/src/css/styles.min.css' + '/out/'.strtolower($theme).'/src/css/styles.min.css' ] ); } diff --git a/Application/Core/TinyMCE/Options/FilemanagerUrl.php b/Application/Core/TinyMCE/Options/FilemanagerUrl.php index ff1bade..25f242a 100644 --- a/Application/Core/TinyMCE/Options/FilemanagerUrl.php +++ b/Application/Core/TinyMCE/Options/FilemanagerUrl.php @@ -35,6 +35,7 @@ class FilemanagerUrl extends AbstractOption public function get(): string { + /** @var string $sFilemanagerKey */ $sFilemanagerKey = md5_file(Registry::getConfig()->getConfigParam("sShopDir")."/config.inc.php"); Registry::get(UtilsServer::class)->setOxCookie("filemanagerkey", $sFilemanagerKey); diff --git a/Application/Core/TinyMCE/Options/Language.php b/Application/Core/TinyMCE/Options/Language.php index 905a467..acd0031 100644 --- a/Application/Core/TinyMCE/Options/Language.php +++ b/Application/Core/TinyMCE/Options/Language.php @@ -46,7 +46,7 @@ class Language extends AbstractOption "nl" => "nl", "ru" => "ru" ); - return $aLang[ $oLang->getLanguageAbbr( $oLang->getTplLanguage() ) ] ?? "en"; + return $aLang[ $oLang->getLanguageAbbr( (int) $oLang->getTplLanguage() ) ] ?? "en"; } public function mustQuote(): bool diff --git a/Application/Core/TinyMCE/Options/MinHeight.php b/Application/Core/TinyMCE/Options/MinHeight.php index 215c7f2..b08cbee 100644 --- a/Application/Core/TinyMCE/Options/MinHeight.php +++ b/Application/Core/TinyMCE/Options/MinHeight.php @@ -31,9 +31,9 @@ class MinHeight extends AbstractOption public function get(): string { - $profile = Registry::getSession()->getVariable('profile'); + $profile = (array) Registry::getSession()->getVariable('profile'); - if (isset($profile) && $profile[1]) { + if (array_key_exists(1, $profile)) { return (string) (max($profile[1] * 20, 350)); } diff --git a/Application/Core/TinyMCE/Options/Setup.php b/Application/Core/TinyMCE/Options/Setup.php index 92ad479..7f48baf 100644 --- a/Application/Core/TinyMCE/Options/Setup.php +++ b/Application/Core/TinyMCE/Options/Setup.php @@ -34,7 +34,7 @@ class Setup extends AbstractOption editor.options.register("filemanager_url", { processor: "string" }); } JS; - return trim(preg_replace('!\s+!', ' ', $js)); + return trim((string) preg_replace('!\s+!', ' ', $js)); } /** diff --git a/Application/Core/TinyMCE/Options/Toolbar.php b/Application/Core/TinyMCE/Options/Toolbar.php index 79265d4..cc43d88 100644 --- a/Application/Core/TinyMCE/Options/Toolbar.php +++ b/Application/Core/TinyMCE/Options/Toolbar.php @@ -48,7 +48,11 @@ class Toolbar extends AbstractOption $this->getMultiLineToolbar($toolbarList); } - protected function getSingleLineToolbar($toolbarList): string + /** + * @param ToolbarList $toolbarList + * @return string + */ + protected function getSingleLineToolbar(ToolbarList $toolbarList): string { $all = []; @@ -90,7 +94,11 @@ class Toolbar extends AbstractOption return $toolbarElements . ' | ' . $pluginToolbarElements; } - protected function getMultiLineToolbar($toolbarList): string + /** + * @param ToolbarList $toolbarList + * @return string + */ + protected function getMultiLineToolbar(ToolbarList $toolbarList): string { $list = []; diff --git a/Application/Core/TinyMCE/PluginList.php b/Application/Core/TinyMCE/PluginList.php index 368385a..5cf21a8 100644 --- a/Application/Core/TinyMCE/PluginList.php +++ b/Application/Core/TinyMCE/PluginList.php @@ -37,6 +37,7 @@ use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Lists; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Media; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Nonbreaking; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Pagebreak; +use O3\TinyMCE\Application\Core\TinyMCE\Plugins\PluginInterface; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Preview; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Quickbars; use O3\TinyMCE\Application\Core\TinyMCE\Plugins\Roxy; @@ -47,6 +48,9 @@ use O3\TinyMCE\Application\Core\TinyMCE\Plugins\WordCount; class PluginList { + /** + * @return array + */ public function get(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/Nonbreaking.php b/Application/Core/TinyMCE/Plugins/Nonbreaking.php index e2c4e18..0e7db21 100644 --- a/Application/Core/TinyMCE/Plugins/Nonbreaking.php +++ b/Application/Core/TinyMCE/Plugins/Nonbreaking.php @@ -30,6 +30,9 @@ class Nonbreaking extends AbstractPlugin return 'nonbreaking'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/Pagebreak.php b/Application/Core/TinyMCE/Plugins/Pagebreak.php index a3d05ca..ce2f91d 100644 --- a/Application/Core/TinyMCE/Plugins/Pagebreak.php +++ b/Application/Core/TinyMCE/Plugins/Pagebreak.php @@ -30,6 +30,9 @@ class Pagebreak extends AbstractPlugin return 'pagebreak'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/PluginInterface.php b/Application/Core/TinyMCE/Plugins/PluginInterface.php index 26c80be..400a079 100644 --- a/Application/Core/TinyMCE/Plugins/PluginInterface.php +++ b/Application/Core/TinyMCE/Plugins/PluginInterface.php @@ -27,6 +27,9 @@ interface PluginInterface { public function getPluginName(): string; + /** + * @return string[] + */ public function getToolbarElements(): array; public function getScriptPath(): ?string; diff --git a/Application/Core/TinyMCE/Plugins/Preview.php b/Application/Core/TinyMCE/Plugins/Preview.php index a67f776..9408767 100644 --- a/Application/Core/TinyMCE/Plugins/Preview.php +++ b/Application/Core/TinyMCE/Plugins/Preview.php @@ -30,6 +30,9 @@ class Preview extends AbstractPlugin return 'preview'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/SearchReplace.php b/Application/Core/TinyMCE/Plugins/SearchReplace.php index 4c50ce2..6c4f9fa 100644 --- a/Application/Core/TinyMCE/Plugins/SearchReplace.php +++ b/Application/Core/TinyMCE/Plugins/SearchReplace.php @@ -30,6 +30,9 @@ class SearchReplace extends AbstractPlugin return 'searchreplace'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/Table.php b/Application/Core/TinyMCE/Plugins/Table.php index 8808b9f..bb10b0f 100644 --- a/Application/Core/TinyMCE/Plugins/Table.php +++ b/Application/Core/TinyMCE/Plugins/Table.php @@ -30,6 +30,9 @@ class Table extends AbstractPlugin return 'table'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/Visualblocks.php b/Application/Core/TinyMCE/Plugins/Visualblocks.php index da4c645..b56e03c 100644 --- a/Application/Core/TinyMCE/Plugins/Visualblocks.php +++ b/Application/Core/TinyMCE/Plugins/Visualblocks.php @@ -30,6 +30,9 @@ class Visualblocks extends AbstractPlugin return 'visualblocks'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return [ diff --git a/Application/Core/TinyMCE/Plugins/WordCount.php b/Application/Core/TinyMCE/Plugins/WordCount.php index f4185b8..af77516 100644 --- a/Application/Core/TinyMCE/Plugins/WordCount.php +++ b/Application/Core/TinyMCE/Plugins/WordCount.php @@ -30,6 +30,9 @@ class WordCount extends AbstractPlugin return 'wordcount'; } + /** + * @return string[] + */ public function getToolbarElements(): array { return []; diff --git a/Application/Core/TinyMCE/Toolbar/ToolbarInterface.php b/Application/Core/TinyMCE/Toolbar/ToolbarInterface.php index 98bab24..5106c68 100644 --- a/Application/Core/TinyMCE/Toolbar/ToolbarInterface.php +++ b/Application/Core/TinyMCE/Toolbar/ToolbarInterface.php @@ -25,5 +25,8 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Toolbar; interface ToolbarInterface { + /** + * @return string[] + */ public function getButtons(): array; } \ No newline at end of file diff --git a/Application/Core/TinyMCE/Toolbar/Undo.php b/Application/Core/TinyMCE/Toolbar/Undo.php index 18e2bd9..bb450a9 100644 --- a/Application/Core/TinyMCE/Toolbar/Undo.php +++ b/Application/Core/TinyMCE/Toolbar/Undo.php @@ -25,6 +25,9 @@ namespace O3\TinyMCE\Application\Core\TinyMCE\Toolbar; class Undo extends AbstractToolbar { + /** + * @return string[] + */ public function getButtons(): array { return [ diff --git a/Application/Core/TinyMCE/ToolbarList.php b/Application/Core/TinyMCE/ToolbarList.php index 50acdd6..fd2c518 100644 --- a/Application/Core/TinyMCE/ToolbarList.php +++ b/Application/Core/TinyMCE/ToolbarList.php @@ -31,9 +31,13 @@ use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Blocks; use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Indent; use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\Lists; use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\RemoveFormat; +use O3\TinyMCE\Application\Core\TinyMCE\Toolbar\ToolbarInterface; class ToolbarList { + /** + * @return array> + */ public function get(): array { return [ diff --git a/Application/Core/TinyMCE/Utils.php b/Application/Core/TinyMCE/Utils.php index 8890ddf..a3ff6d6 100644 --- a/Application/Core/TinyMCE/Utils.php +++ b/Application/Core/TinyMCE/Utils.php @@ -25,7 +25,7 @@ namespace O3\TinyMCE\Application\Core\TinyMCE; class Utils { - public function quote($string): string + public function quote(string $string): string { return '"'.addslashes($string).'"'; } diff --git a/Application/Core/config.php b/Application/Core/config.php index 342edb9..fe26963 100755 --- a/Application/Core/config.php +++ b/Application/Core/config.php @@ -21,7 +21,7 @@ declare(strict_types=1); -function checkAccess($action) +function checkAccess(string $action): void { if($_COOKIE['filemanagerkey'] !== md5($_SERVER['DOCUMENT_ROOT'].$_COOKIE['admin_sid'])) die('Access Denied!!'); } \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..9e92148 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +parameters: + scanFiles: + - .ide-helper.php + - ../../o3-shop/shop-ce/source/oxfunctions.php + paths: + - Application + excludePaths: + - Application/fileman + level: 9 + phpVersion: 70400 \ No newline at end of file