add cs fixer and PHPStan and activate it (build 436)

This commit is contained in:
crazywhalecc
2022-03-15 18:05:33 +08:00
parent d01bd69aa5
commit 1706afbcd0
163 changed files with 4572 additions and 3588 deletions

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Command\Module;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -14,67 +14,78 @@ use ZM\Utils\Manager\ModuleManager;
class ModuleListCommand extends Command
{
// the name of the command (the part after "bin/console")
// the name of the command (the part after "bin/console")
protected static $defaultName = 'module:list';
protected function configure() {
$this->setDescription("查看所有模块信息");
$this->setHelp("此功能将会把炸毛框架的模块列举出来。");
protected function configure()
{
$this->setDescription('查看所有模块信息');
$this->setHelp('此功能将会把炸毛框架的模块列举出来。');
// ...
}
protected function execute(InputInterface $input, OutputInterface $output): int {
protected function execute(InputInterface $input, OutputInterface $output): int
{
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
ZMConfig::setEnv($args['env'] ?? '');
if (ZMConfig::get('global') === false) {
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
}
//定义常量
/** @noinspection PhpIncludeInspection */
include_once DataProvider::getFrameworkRootDir() . "/src/ZM/global_defines.php";
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
Console::init(
ZMConfig::get("global", "info_level") ?? 2,
ZMConfig::get('global', 'info_level') ?? 2,
null,
$args["log-theme"] ?? "default",
($o = ZMConfig::get("console_color")) === false ? [] : $o
$args['log-theme'] ?? 'default',
($o = ZMConfig::get('console_color')) === false ? [] : $o
);
$timezone = ZMConfig::get("global", "timezone") ?? "Asia/Shanghai";
$timezone = ZMConfig::get('global', 'timezone') ?? 'Asia/Shanghai';
date_default_timezone_set($timezone);
$list = ModuleManager::getConfiguredModules();
foreach ($list as $v) {
echo "[" . Console::setColor($v["name"], "green") . "]" . PHP_EOL;
$out_list = ["类型" => "源码(source)"];
if (isset($v["version"])) $out_list["版本"] = $v["version"];
if (isset($v["description"])) $out_list["描述"] = $v["description"];
$out_list["目录"] = str_replace(DataProvider::getSourceRootDir() . "/", "", $v["module-path"]);
echo '[' . Console::setColor($v['name'], 'green') . ']' . PHP_EOL;
$out_list = ['类型' => '源码(source)'];
if (isset($v['version'])) {
$out_list['版本'] = $v['version'];
}
if (isset($v['description'])) {
$out_list['描述'] = $v['description'];
}
$out_list['目录'] = str_replace(DataProvider::getSourceRootDir() . '/', '', $v['module-path']);
$this->printList($out_list);
}
if ($list === []) {
echo Console::setColor("没有发现已编写打包配置文件zm.json的模块", "yellow") . PHP_EOL;
echo Console::setColor('没有发现已编写打包配置文件zm.json的模块', 'yellow') . PHP_EOL;
}
$list = ModuleManager::getPackedModules();
foreach ($list as $v) {
echo "[" . Console::setColor($v["name"], "gold") . "]" . PHP_EOL;
$out_list = ["类型" => "模块包(phar)"];
if (isset($v["module-config"]["version"])) $out_list["版本"] = $v["module-config"]["version"];
if (isset($v["module-config"]["description"])) $out_list["描述"] = $v["module-config"]["description"];
$out_list["位置"] = str_replace(DataProvider::getSourceRootDir() . "/", "", $v["phar-path"]);
echo '[' . Console::setColor($v['name'], 'gold') . ']' . PHP_EOL;
$out_list = ['类型' => '模块包(phar)'];
if (isset($v['module-config']['version'])) {
$out_list['版本'] = $v['module-config']['version'];
}
if (isset($v['module-config']['description'])) {
$out_list['描述'] = $v['module-config']['description'];
}
$out_list['位置'] = str_replace(DataProvider::getSourceRootDir() . '/', '', $v['phar-path']);
$this->printList($out_list);
}
if ($list === []) {
echo Console::setColor("没有发现已打包且装载的模块!", "yellow") . PHP_EOL;
echo Console::setColor('没有发现已打包且装载的模块!', 'yellow') . PHP_EOL;
}
return 0;
}
private function printList($list) {
private function printList($list)
{
foreach ($list as $k => $v) {
echo "\t" . $k . ": " . Console::setColor($v, "yellow") . PHP_EOL;
echo "\t" . $k . ': ' . Console::setColor($v, 'yellow') . PHP_EOL;
}
}
}
}

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Command\Module;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -19,42 +19,47 @@ class ModulePackCommand extends Command
// the name of the command (the part after "bin/console")
protected static $defaultName = 'module:pack';
protected function configure() {
$this->addArgument("module-name", InputArgument::REQUIRED);
$this->setDescription("将配置好的模块构建一个phar包");
$this->setHelp("此功能将会把炸毛框架的模块打包为\".phar\",供发布和执行。");
$this->addOption("target", "D", InputOption::VALUE_REQUIRED, "Output Directory | 指定输出目录");
protected function configure()
{
$this->addArgument('module-name', InputArgument::REQUIRED);
$this->setDescription('将配置好的模块构建一个phar包');
$this->setHelp('此功能将会把炸毛框架的模块打包为".phar",供发布和执行。');
$this->addOption('target', 'D', InputOption::VALUE_REQUIRED, 'Output Directory | 指定输出目录');
// ...
}
protected function execute(InputInterface $input, OutputInterface $output): int {
protected function execute(InputInterface $input, OutputInterface $output): int
{
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
ZMConfig::setEnv($args['env'] ?? '');
if (ZMConfig::get('global') === false) {
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
}
//定义常量
include_once DataProvider::getFrameworkRootDir()."/src/ZM/global_defines.php";
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
Console::init(
ZMConfig::get("global", "info_level") ?? 2,
ZMConfig::get('global', 'info_level') ?? 2,
null,
$args["log-theme"] ?? "default",
($o = ZMConfig::get("console_color")) === false ? [] : $o
$args['log-theme'] ?? 'default',
($o = ZMConfig::get('console_color')) === false ? [] : $o
);
$timezone = ZMConfig::get("global", "timezone") ?? "Asia/Shanghai";
$timezone = ZMConfig::get('global', 'timezone') ?? 'Asia/Shanghai';
date_default_timezone_set($timezone);
$list = ModuleManager::getConfiguredModules();
if (!isset($list[$input->getArgument("module-name")])) {
$output->writeln("<error>不存在模块 ".$input->getArgument("module-name")." !</error>");
if (!isset($list[$input->getArgument('module-name')])) {
$output->writeln('<error>不存在模块 ' . $input->getArgument('module-name') . ' !</error>');
return 1;
}
$result = ModuleManager::packModule($list[$input->getArgument("module-name")], $input->getOption("target"));
if ($result) Console::success("打包完成!");
else Console::error("打包失败!");
$result = ModuleManager::packModule($list[$input->getArgument('module-name')], $input->getOption('target'));
if ($result) {
Console::success('打包完成!');
} else {
Console::error('打包失败!');
}
return 0;
}
}
}

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Command\Module;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -16,51 +16,56 @@ use ZM\Utils\Manager\ModuleManager;
class ModuleUnpackCommand extends Command
{
// the name of the command (the part after "bin/console")
// the name of the command (the part after "bin/console")
protected static $defaultName = 'module:unpack';
protected function configure() {
protected function configure()
{
$this->setDefinition([
new InputArgument("module-name", InputArgument::REQUIRED),
new InputOption("overwrite-light-cache", null, null, "覆盖现有的LightCache项目"),
new InputOption("overwrite-zm-data", null, null, "覆盖现有的zm_data文件"),
new InputOption("overwrite-source", null, null, "覆盖现有的源码文件"),
new InputOption("ignore-depends", null, null, "解包时忽略检查依赖")
new InputArgument('module-name', InputArgument::REQUIRED),
new InputOption('overwrite-light-cache', null, null, '覆盖现有的LightCache项目'),
new InputOption('overwrite-zm-data', null, null, '覆盖现有的zm_data文件'),
new InputOption('overwrite-source', null, null, '覆盖现有的源码文件'),
new InputOption('ignore-depends', null, null, '解包时忽略检查依赖'),
]);
$this->setDescription("解包一个phar模块到src目录");
$this->setHelp("此功能将phar格式的模块包解包到src目录下。");
$this->setDescription('解包一个phar模块到src目录');
$this->setHelp('此功能将phar格式的模块包解包到src目录下。');
// ...
}
protected function execute(InputInterface $input, OutputInterface $output): int {
protected function execute(InputInterface $input, OutputInterface $output): int
{
ZMConfig::setDirectory(DataProvider::getSourceRootDir() . '/config');
ZMConfig::setEnv($args["env"] ?? "");
if (ZMConfig::get("global") === false) {
die (zm_internal_errcode("E00007") . "Global config load failed: " . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
ZMConfig::setEnv($args['env'] ?? '');
if (ZMConfig::get('global') === false) {
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
}
//定义常量
/** @noinspection PhpIncludeInspection */
include_once DataProvider::getFrameworkRootDir()."/src/ZM/global_defines.php";
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
Console::init(
ZMConfig::get("global", "info_level") ?? 4,
ZMConfig::get('global', 'info_level') ?? 4,
null,
$args["log-theme"] ?? "default",
($o = ZMConfig::get("console_color")) === false ? [] : $o
$args['log-theme'] ?? 'default',
($o = ZMConfig::get('console_color')) === false ? [] : $o
);
$timezone = ZMConfig::get("global", "timezone") ?? "Asia/Shanghai";
$timezone = ZMConfig::get('global', 'timezone') ?? 'Asia/Shanghai';
date_default_timezone_set($timezone);
$list = ModuleManager::getPackedModules();
if (!isset($list[$input->getArgument("module-name")])) {
$output->writeln("<error>不存在打包的模块 ".$input->getArgument("module-name")." !</error>");
if (!isset($list[$input->getArgument('module-name')])) {
$output->writeln('<error>不存在打包的模块 ' . $input->getArgument('module-name') . ' !</error>');
return 1;
}
$result = ModuleManager::unpackModule($list[$input->getArgument("module-name")], $input->getOptions());
if ($result) Console::success("解压完成!");
else Console::error("解压失败!");
$result = ModuleManager::unpackModule($list[$input->getArgument('module-name')], $input->getOptions());
if ($result) {
Console::success('解压完成!');
} else {
Console::error('解压失败!');
}
return 0;
}
}
}