Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin:make command, remove uppercase name #378

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
'multiline_comment_opening_closing' => true,
'phpdoc_summary' => false,
'php_unit_test_class_requires_covers' => false,
'fully_qualified_strict_types' => false,
'new_with_parentheses' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
2 changes: 1 addition & 1 deletion src/Globals/global_defines_app.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
define('SOURCE_ROOT_DIR', Phar::running() !== '' ? Phar::running() : WORKING_DIR);

if (DIRECTORY_SEPARATOR === '\\') {
define('TMP_DIR', 'C:\\Windows\\Temp');
define('TMP_DIR', 'C:\Windows\Temp');
} elseif (!empty(getenv('TMPDIR'))) {
define('TMP_DIR', getenv('TMPDIR'));
} elseif (is_writable('/tmp')) {
Expand Down
8 changes: 3 additions & 5 deletions src/Globals/global_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OneBot\V12\Object\MessageSegment;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
use ZM\Config\Environment;
use ZM\Config\ZMConfig;
use ZM\Container\ContainerHolder;
Expand Down Expand Up @@ -148,7 +147,7 @@ function is_assoc_array(array $array): bool
*/
function match_pattern(string $pattern, string $subject): bool
{
$pattern = str_replace(['\*', '\\\\.*'], ['.*', '\*'], preg_quote($pattern, '/'));
$pattern = str_replace(['\*', '\\\.*'], ['.*', '\*'], preg_quote($pattern, '/'));
$pattern = '/^' . $pattern . '$/i';
return preg_match($pattern, $subject) === 1;
}
Expand Down Expand Up @@ -302,7 +301,7 @@ function redis(string $name = 'default'): RedisWrapper
* @param null|mixed $default 默认值
* @return mixed|void|ZMConfig
*/
function config(array|string $key = null, mixed $default = null)
function config(null|array|string $key = null, mixed $default = null)
{
$config = ZMConfig::getInstance();
if (is_null($key)) {
Expand All @@ -328,8 +327,7 @@ function bot_connect(int $flag, int $fd)
/**
* 获取一个 KV 库实例
*
* @param string $name KV 库名称
* @return CacheInterface
* @param string $name KV 库名称
*/
function kv(string $name = ''): Psr\SimpleCache\CacheInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Globals/script_setup_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ function _zm_setup_loader()

// 在*nix等支持多进程环境的情况,可直接运行此文件,那么就执行
if (debug_backtrace() === []) {
require((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php';
require ((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php';
echo _zm_setup_loader();
}
4 changes: 2 additions & 2 deletions src/ZM/Annotation/AnnotationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
abstract class AnnotationBase implements \IteratorAggregate, \Stringable
{
/** @var array|\Closure|string 方法名或闭包 */
public \Closure|string|array $method = '';
public array|\Closure|string $method = '';

public $class = '';

Expand Down Expand Up @@ -40,7 +40,7 @@ public function __toString(): string
/**
* 在 InstantPlugin 下调用,设置回调或匿名函数
*/
public function on(\Closure|callable|string $method): AnnotationBase
public function on(callable|\Closure|string $method): AnnotationBase
{
$this->method = $method;
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/Annotation/AnnotationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnnotationHandler

public const STATUS_RULE_FAILED = 4; // 判断事件执行的规则函数判定为false,所以不执行此方法

private string|AnnotationBase $annotation_class;
private AnnotationBase|string $annotation_class;

/** @var callable */
private $rule_callback;
Expand Down
5 changes: 1 addition & 4 deletions src/ZM/Annotation/Closed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;

Expand All @@ -15,6 +14,4 @@
* @Target("ALL")
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
class Closed extends AnnotationBase
{
}
class Closed extends AnnotationBase {}
4 changes: 1 addition & 3 deletions src/ZM/Annotation/Framework/BindEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Framework;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand Down Expand Up @@ -32,8 +31,7 @@ public function __construct(
*/
public string $event_class,
public int $level = 800
) {
}
) {}

public function getLevel(): int
{
Expand Down
5 changes: 1 addition & 4 deletions src/ZM/Annotation/Framework/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Framework;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
Expand All @@ -20,9 +19,7 @@
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Init extends AnnotationBase implements Level
{
public function __construct(public int $worker = 0, public int $level = 20)
{
}
public function __construct(public int $worker = 0, public int $level = 20) {}

public function getLevel()
{
Expand Down
5 changes: 1 addition & 4 deletions src/ZM/Annotation/Framework/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Framework;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
Expand All @@ -17,6 +16,4 @@
* @since 3.0.0
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Setup extends AnnotationBase
{
}
class Setup extends AnnotationBase {}
4 changes: 1 addition & 3 deletions src/ZM/Annotation/Http/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Http;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand All @@ -25,6 +24,5 @@ public function __construct(
* @Required()
*/
public string $prefix
) {
}
) {}
}
4 changes: 1 addition & 3 deletions src/ZM/Annotation/Http/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Http;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand All @@ -30,8 +29,7 @@ public function __construct(
* Routing path params binding. eg. {"id"="\d+"}
*/
public $params = []
) {
}
) {}

public static function make($route, $name = '', $request_method = ['GET', 'POST'], $params = []): static
{
Expand Down
4 changes: 1 addition & 3 deletions src/ZM/Annotation/Interfaces/CustomAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace ZM\Annotation\Interfaces;

interface CustomAnnotation
{
}
interface CustomAnnotation {}
4 changes: 1 addition & 3 deletions src/ZM/Annotation/Interfaces/ErgodicAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace ZM\Annotation\Interfaces;

interface ErgodicAnnotation
{
}
interface ErgodicAnnotation {}
5 changes: 2 additions & 3 deletions src/ZM/Annotation/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\Middleware;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand All @@ -22,13 +21,13 @@ class Middleware extends AnnotationBase implements ErgodicAnnotation
{
/**
* @param string[] $args
* @param mixed $name
*/
public function __construct(
/**
* @Required()
*/
public $name,
public array $args = []
) {
}
) {}
}
4 changes: 1 addition & 3 deletions src/ZM/Annotation/OneBot/BotAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class BotAction extends AnnotationBase implements Level
{
public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20)
{
}
public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20) {}

public static function make(callable $callback, string $action, bool $need_response = false, int $level = 20): BotAction
{
Expand Down
4 changes: 1 addition & 3 deletions src/ZM/Annotation/OneBot/BotActionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class BotActionResponse extends AnnotationBase implements Level
{
public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20)
{
}
public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20) {}

public function getLevel()
{
Expand Down
3 changes: 1 addition & 2 deletions src/ZM/Annotation/OneBot/BotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function __construct(
public string $detail_type = '',
public string $prefix = '',
public int $level = 20
) {
}
) {}

public static function make(
string $name = '',
Expand Down
5 changes: 1 addition & 4 deletions src/ZM/Annotation/OneBot/BotEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZM\Annotation\OneBot;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
Expand All @@ -20,9 +19,7 @@
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class BotEvent extends AnnotationBase implements Level
{
public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20)
{
}
public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20) {}

public static function make(
?string $type = null,
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/Annotation/OneBot/CommandArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
string $type = 'string',
public bool $required = false,
public string $prompt = '',
public string|\Closure|array|int|float|null $default = '',
public null|array|\Closure|float|int|string $default = '',
public int $timeout = 60,
public int $error_prompt_policy = 1
) {
Expand Down
3 changes: 1 addition & 2 deletions src/ZM/Annotation/OneBot/CommandHelp.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(
public string $description,
public string $usage,
public string $example,
) {
}
) {}

public static function make(
string $description,
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function build(string $target, string $entry): void
$separator = '\\' . DIRECTORY_SEPARATOR;
// 只打包 bin / config / resources / src / vendor 目录以及 composer.json / composer.lock / entry.php
$files = array_filter($files, function ($file) use ($separator) {
return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\\.json|README\\.md)$/', $file);
return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\.json|README\.md)$/', $file);
});
sort($files);

Expand Down
1 change: 0 additions & 1 deletion src/ZM/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ abstract class Command extends \Symfony\Component\Console\Command\Command implem
protected OutputInterface $output;

/**
* {@inheritdoc}
* @internal 不建议覆写此方法,建议使用 {@see handle()} 方法
*/
protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
3 changes: 0 additions & 3 deletions src/ZM/Command/Generate/TextGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ protected function configure()
$this->setDescription('生成一些框架本身的文本(内部' . PHP_EOL . '当前包含:class-alias-md,update-log-md');
}

/**
* {@inheritDoc}
*/
protected function handle(): int
{
return match ($this->input->getArgument('name')) {
Expand Down
12 changes: 6 additions & 6 deletions src/ZM/Command/Plugin/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class PluginCommand extends Command

private static bool $loaded = false;

public function __construct(string $name = null)
public function __construct(?string $name = null)
{
parent::__construct($name);
if (!self::$loaded) {
Expand All @@ -30,16 +30,16 @@ public function __construct(string $name = null)
/**
* 插件名称合规验证器
*/
public function validatePluginName(string $answer): string
public function validatePluginName(?string $answer): string
{
if (empty($answer)) {
throw new \RuntimeException('插件名称不能为空');
}
if (is_numeric(mb_substr($answer, 0, 1))) {
throw new \RuntimeException('插件名称不能以数字开头,且只能包含字母、数字、下划线、短横线');
}
if (!preg_match('/^[\/a-zA-Z0-9_-]+$/', $answer)) {
throw new \RuntimeException('插件名称只能包含字母、数字、下划线、短横线');
if (!preg_match('/^[\/a-z0-9_-]+$/', $answer)) {
throw new \RuntimeException('插件名称只能包含小写字母、数字、下划线、短横线');
}
$exp = explode('/', $answer);
if (count($exp) !== 2) {
Expand Down Expand Up @@ -72,7 +72,7 @@ public function validateNamespace(string $answer): string
throw new \RuntimeException('插件命名空间不能以数字开头,且只能包含字母、数字、反斜线');
}
// 只能包含字母、数字和反斜线
if (!preg_match('/^[a-zA-Z0-9\\\\]+$/', $answer)) {
if (!preg_match('/^[a-zA-Z0-9\\\]+$/', $answer)) {
throw new \RuntimeException('插件命名空间只能包含字母、数字、反斜线');
}
return $answer;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function questionWithArgument(string $name, string $question, callable
* @param string $question 问题
* @param callable $validator 验证器
*/
protected function questionWithOption(string $name, string $question, callable $validator, string $default = null): void
protected function questionWithOption(string $name, string $question, callable $validator, ?string $default = null): void
{
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
Expand Down
3 changes: 0 additions & 3 deletions src/ZM/Command/Plugin/PluginInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ protected function configure()
$this->addOption('github-token', null, InputOption::VALUE_REQUIRED, '提供的 GitHub Token');
}

/**
* {@inheritDoc}
*/
protected function handle(): int
{
$addr = $this->input->getArgument('address');
Expand Down
1 change: 0 additions & 1 deletion src/ZM/Command/Plugin/PluginMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ protected function configure()
}

/**
* {@inheritDoc}
* @throws FileSystemException
*/
protected function handle(): int
Expand Down
Loading
Loading