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);
|
||||
|
@ -85,7 +85,6 @@ class AntCMS
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $page
|
||||
* @return array<mixed>|false
|
||||
*/
|
||||
public function getPage(string $page)
|
||||
|
@ -109,7 +108,6 @@ class AntCMS
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $layout
|
||||
* @param string|null $theme
|
||||
* @return string
|
||||
*/
|
||||
|
@ -162,7 +160,6 @@ class AntCMS
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $pageContent
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function getPageHeaders(string $pageContent)
|
||||
|
@ -207,7 +204,6 @@ class AntCMS
|
|||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ 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);
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@ 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)
|
||||
|
@ -25,7 +22,6 @@ class AntTools
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function repairFilePath(string $path)
|
||||
|
|
|
@ -7,7 +7,6 @@ use AntCMS\AntConfig;
|
|||
class AntTwig
|
||||
{
|
||||
/**
|
||||
* @param string $content
|
||||
* @param array<mixed> $params
|
||||
* @param string|null $theme
|
||||
* @return string
|
||||
|
|
|
@ -8,7 +8,6 @@ use Symfony\Component\Yaml\Yaml;
|
|||
class AntYaml
|
||||
{
|
||||
/**
|
||||
* @param string $file
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function parseFile(string $file)
|
||||
|
@ -17,18 +16,15 @@ class AntYaml
|
|||
}
|
||||
|
||||
/**
|
||||
* @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)) {
|
||||
if (file_exists($pagePath) && unlink($pagePath)) {
|
||||
AntYaml::saveFile(antPagesList, $pages);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: //' . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/");
|
||||
break;
|
||||
|
||||
|
@ -250,11 +249,10 @@ class AdminPlugin extends AntPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @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