diff --git a/rector.php b/rector.php index e6b6d57..a8a51cc 100644 --- a/rector.php +++ b/rector.php @@ -5,6 +5,7 @@ declare(strict_types=1); use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector; use Rector\Php80\Rector\FunctionLike\MixedTypeRector; use Rector\Php80\Rector\FunctionLike\UnionTypesRector; use Rector\Set\ValueObject\SetList; @@ -21,6 +22,7 @@ return static function (RectorConfig $rectorConfig): void { MixedTypeRector::class, EncapsedStringsToSprintfRector::class, ConsistentPregDelimiterRector::class, + RemoveAnnotationRector::class, ]); $rectorConfig->sets([ @@ -28,5 +30,6 @@ return static function (RectorConfig $rectorConfig): void { SetList::CODE_QUALITY, SetList::CODING_STYLE, SetList::NAMING, + SetList::DEAD_CODE, ]); }; diff --git a/src/AntCMS/AntCMS.php b/src/AntCMS/AntCMS.php index 826f833..9db6ccf 100644 --- a/src/AntCMS/AntCMS.php +++ b/src/AntCMS/AntCMS.php @@ -73,7 +73,7 @@ class AntCMS */ public static function renderException(string $exceptionCode, int $httpCode = 404, string $exceptionString = 'That request caused an exception to be thrown.') { - $exceptionString = $exceptionString . " (Code $exceptionCode)"; + $exceptionString .= " (Code {$exceptionCode})"; $pageTemplate = self::getPageLayout(); $pageTemplate = str_replace('{{ AntCMSTitle }}', 'An error ocurred', $pageTemplate); @@ -84,8 +84,7 @@ class AntCMS exit; } - /** - * @param string $page + /** * @return array|false */ public function getPage(string $page) @@ -108,8 +107,7 @@ class AntCMS } } - /** - * @param string $layout + /** * @param string|null $theme * @return string */ @@ -161,8 +159,7 @@ class AntCMS return $template; } - /** - * @param string $pageContent + /** * @return array */ public static function getPageHeaders(string $pageContent) @@ -206,8 +203,7 @@ class AntCMS return AntConfig::currentConfig('siteInfo'); } - /** - * @param string $path + /** * @return void */ public function serveContent(string $path) diff --git a/src/AntCMS/AntCache.php b/src/AntCMS/AntCache.php index 83845e9..aea413c 100644 --- a/src/AntCMS/AntCache.php +++ b/src/AntCMS/AntCache.php @@ -21,7 +21,7 @@ class AntCache $config = AntConfig::currentConfig(); if ($config['enableCache']) { try { - file_put_contents($cachePath, (string)$content); + file_put_contents($cachePath, $content); return true; } catch (\Exception) { return false; diff --git a/src/AntCMS/AntConfig.php b/src/AntCMS/AntConfig.php index ffe93e7..ed25d38 100644 --- a/src/AntCMS/AntConfig.php +++ b/src/AntCMS/AntConfig.php @@ -86,11 +86,12 @@ class AntConfig */ public static function saveConfig(array $config) { - foreach (self::$ConfigKeys as $defaultKey) { - if (!array_key_exists($defaultKey, $config)) { - throw new Exception("New config is missing the required {$defaultKey} key from it's array!"); + foreach (self::$ConfigKeys as $ConfigKey) { + if (!array_key_exists($ConfigKey, $config)) { + throw new Exception("New config is missing the required {$ConfigKey} key from it's array!"); } } + return AntYaml::saveFile(antConfigFile, $config); } } diff --git a/src/AntCMS/AntMarkdown.php b/src/AntCMS/AntMarkdown.php index 8132458..9951242 100644 --- a/src/AntCMS/AntMarkdown.php +++ b/src/AntCMS/AntMarkdown.php @@ -17,8 +17,7 @@ use League\CommonMark\Extension\Embed\EmbedExtension; class AntMarkdown { - /** - * @param string $md + /** * @return string */ public static function renderMarkdown(string $md) diff --git a/src/AntCMS/AntPages.php b/src/AntCMS/AntPages.php index 82de787..291a128 100644 --- a/src/AntCMS/AntPages.php +++ b/src/AntCMS/AntPages.php @@ -59,7 +59,6 @@ class AntPages } /** - * @param string $navTemplate * @param string $currentPage optional - What page is the active page. Used for highlighting the active page in the navbar * @return string */ diff --git a/src/AntCMS/AntPluginLoader.php b/src/AntCMS/AntPluginLoader.php index f4faa2e..cf3d654 100644 --- a/src/AntCMS/AntPluginLoader.php +++ b/src/AntCMS/AntPluginLoader.php @@ -10,7 +10,6 @@ class AntPluginLoader public function loadPlugins() { $plugins = array(); - $files = array(); $files = AntTools::getFileList(antPluginPath, null, true); diff --git a/src/AntCMS/AntTools.php b/src/AntCMS/AntTools.php index 36a89c5..f0dd60a 100644 --- a/src/AntCMS/AntTools.php +++ b/src/AntCMS/AntTools.php @@ -4,10 +4,7 @@ namespace AntCMS; class AntTools { - /** - * @param string $dir - * @param (null|string)|null $extension - * @param null|bool $returnPath + /** * @return array */ public static function getFileList(string $dir, ?string $extension = null, ?bool $returnPath = false) @@ -24,8 +21,7 @@ class AntTools return $files; } - /** - * @param string $path + /** * @return string */ public static function repairFilePath(string $path) diff --git a/src/AntCMS/AntTwig.php b/src/AntCMS/AntTwig.php index 3377958..6286ea4 100644 --- a/src/AntCMS/AntTwig.php +++ b/src/AntCMS/AntTwig.php @@ -6,8 +6,7 @@ use AntCMS\AntConfig; class AntTwig { - /** - * @param string $content + /** * @param array $params * @param string|null $theme * @return string diff --git a/src/AntCMS/AntYaml.php b/src/AntCMS/AntYaml.php index 27bc079..4a06d01 100644 --- a/src/AntCMS/AntYaml.php +++ b/src/AntCMS/AntYaml.php @@ -7,8 +7,7 @@ use Symfony\Component\Yaml\Yaml; class AntYaml { - /** - * @param string $file + /** * @return array */ public static function parseFile(string $file) @@ -16,19 +15,16 @@ class AntYaml return Yaml::parseFile($file); } - /** - * @param string $file + /** * @param array $data - * @return bool */ - public static function saveFile(string $file, array $data) + public static function saveFile(string $file, array $data): bool { $yaml = Yaml::dump($data); - return boolval(file_put_contents($file, $yaml)); + return (bool) file_put_contents($file, $yaml); } - /** - * @param string $yaml + /** * @return array|null */ public static function parseYaml(string $yaml) diff --git a/src/Plugins/Admin/AdminPlugin.php b/src/Plugins/Admin/AdminPlugin.php index 9f95b5f..ca417b0 100644 --- a/src/Plugins/Admin/AdminPlugin.php +++ b/src/Plugins/Admin/AdminPlugin.php @@ -11,7 +11,6 @@ use AntCMS\AntTwig; class AdminPlugin extends AntPlugin { - /** @return string */ public function getName(): string { return 'Admin'; @@ -158,6 +157,7 @@ class AdminPlugin extends AntPlugin if (!str_ends_with($pagePath, ".md")) { $pagePath .= '.md'; } + $pagePath = AntTools::repairFilePath($pagePath); $page = "--AntCMS--\nTitle: New Page Title\nAuthor: Author\nDescription: Description of this page.\nKeywords: Keywords\n--AntCMS--\n"; } @@ -200,12 +200,11 @@ class AdminPlugin extends AntPlugin } } - if (file_exists($pagePath)) { - // If we were able to delete the page, update the pages list with the updated pages array. - if (unlink($pagePath)) { - AntYaml::saveFile(antPagesList, $pages); - } + // If we were able to delete the page, update the pages list with the updated pages array. + if (file_exists($pagePath) && unlink($pagePath)) { + AntYaml::saveFile(antPagesList, $pages); } + header('Location: //' . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/"); break; @@ -249,12 +248,11 @@ class AdminPlugin extends AntPlugin exit; } - /** - * @param bool $value + /** * @return string */ private function boolToWord(bool $value) { - return (bool) $value ? 'true' : 'false'; + return $value ? 'true' : 'false'; } }