Code styling /w Rector
This commit is contained in:
parent
e1667b6374
commit
af375a5499
11 changed files with 29 additions and 43 deletions
|
@ -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,
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -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<mixed>|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<mixed>
|
||||
*/
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ use League\CommonMark\Extension\Embed\EmbedExtension;
|
|||
|
||||
class AntMarkdown
|
||||
{
|
||||
/**
|
||||
* @param string $md
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function renderMarkdown(string $md)
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,6 @@ class AntPluginLoader
|
|||
public function loadPlugins()
|
||||
{
|
||||
$plugins = array();
|
||||
$files = array();
|
||||
|
||||
$files = AntTools::getFileList(antPluginPath, null, true);
|
||||
|
||||
|
|
|
@ -4,10 +4,7 @@ namespace AntCMS;
|
|||
|
||||
class AntTools
|
||||
{
|
||||
/**
|
||||
* @param string $dir
|
||||
* @param (null|string)|null $extension
|
||||
* @param null|bool $returnPath
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
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)
|
||||
|
|
|
@ -6,8 +6,7 @@ use AntCMS\AntConfig;
|
|||
|
||||
class AntTwig
|
||||
{
|
||||
/**
|
||||
* @param string $content
|
||||
/**
|
||||
* @param array<mixed> $params
|
||||
* @param string|null $theme
|
||||
* @return string
|
||||
|
|
|
@ -7,8 +7,7 @@ use Symfony\Component\Yaml\Yaml;
|
|||
|
||||
class AntYaml
|
||||
{
|
||||
/**
|
||||
* @param string $file
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function parseFile(string $file)
|
||||
|
@ -16,19 +15,16 @@ class AntYaml
|
|||
return Yaml::parseFile($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
/**
|
||||
* @param array<mixed> $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<mixed>|null
|
||||
*/
|
||||
public static function parseYaml(string $yaml)
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue