From 2c90437a99be02e55a3bd513b2143783e8d7c72b Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 30 Jan 2026 10:46:14 +0800 Subject: [PATCH] =?UTF-8?q?style(coding-standard):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=B8=A5=E6=A0=BC=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E=E5=B9=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 .php-cs-fixer.dist.php 中的 declare_strict_types 设置为 false - 从所有 PHP 类文件中移除 declare(strict_types=1) 声明 - 在 CompilerBase.php 中添加缺失的空行以改善代码可读性 - 恢复 Translator.php 中关于 noLiteralStrings 的原始配置逻辑 --- .php-cs-fixer.dist.php | 2 +- src/Php/ArgInfo.php | 2 -- src/Php/AstNodeType.php | 2 -- src/Php/ClassDef.php | 2 -- src/Php/ClassLikeDef.php | 2 -- src/Php/CompilerBase.php | 5 +++-- src/Php/ConstantDef.php | 2 -- src/Php/Constants.php | 2 -- src/Php/Encryptor.php | 2 -- src/Php/Extractor.php | 2 -- src/Php/FileScanner.php | 2 -- src/Php/FileSorter.php | 2 -- src/Php/FuncCallOptimizer.php | 2 -- src/Php/FunctionDef.php | 2 -- src/Php/InterfaceDef.php | 2 -- src/Php/MagicMethodDetector.php | 2 -- src/Php/MethodDef.php | 2 -- src/Php/Preprocessor.php | 2 -- src/Php/PropertyDef.php | 2 -- src/Php/RedoException.php | 2 -- src/Php/Reflection.php | 2 -- src/Php/SyntaxError.php | 2 -- src/Php/Translator.php | 5 +---- src/Php/Unsupported.php | 2 -- src/Php/Visitor.php | 2 -- 25 files changed, 5 insertions(+), 51 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index acf360f8..810b14fd 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -23,7 +23,7 @@ return (new PhpCsFixer\Config()) 'concat_space' => ['spacing' => 'one'], 'constant_case' => ['case' => 'lower'], 'combine_consecutive_unsets' => true, - 'declare_strict_types' => true, + 'declare_strict_types' => false, 'fully_qualified_strict_types' => ['phpdoc_tags' => []], 'general_phpdoc_annotation_remove' => ['annotations' => ['author']], 'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'location' => 'after_open', 'separate' => 'bottom'], diff --git a/src/Php/ArgInfo.php b/src/Php/ArgInfo.php index 03fcf367..fa893aeb 100644 --- a/src/Php/ArgInfo.php +++ b/src/Php/ArgInfo.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class ArgInfo diff --git a/src/Php/AstNodeType.php b/src/Php/AstNodeType.php index 92e1af8f..f75c3c9e 100644 --- a/src/Php/AstNodeType.php +++ b/src/Php/AstNodeType.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\Node; diff --git a/src/Php/ClassDef.php b/src/Php/ClassDef.php index 0aaaf606..61a7ee3c 100644 --- a/src/Php/ClassDef.php +++ b/src/Php/ClassDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class ClassDef extends ClassLikeDef diff --git a/src/Php/ClassLikeDef.php b/src/Php/ClassLikeDef.php index b2ef43eb..ca8a1198 100644 --- a/src/Php/ClassLikeDef.php +++ b/src/Php/ClassLikeDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class ClassLikeDef diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index e0708322..0f743591 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use League\CLImate\CLImate; @@ -54,6 +52,7 @@ class CompilerBase extends \PhpAot\Core\Translator public const string LITERAL_STRINGS = '_literal_strings'; public const string CLASS_ENTRY_MAP = 'class_entry_map'; + public const string FUNC_MAP = 'func_map'; public const string EXPR_VARIABLE = 'Expr_Variable'; @@ -86,7 +85,9 @@ class CompilerBase extends \PhpAot\Core\Translator * @var array */ protected array $classMap = []; + protected int $funcIndex = 0; + protected array $funcMap = []; protected array $zendTypeMap = [ diff --git a/src/Php/ConstantDef.php b/src/Php/ConstantDef.php index 16638f54..946d810a 100644 --- a/src/Php/ConstantDef.php +++ b/src/Php/ConstantDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class ConstantDef diff --git a/src/Php/Constants.php b/src/Php/Constants.php index b8b36ab3..ff7006cd 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class Constants diff --git a/src/Php/Encryptor.php b/src/Php/Encryptor.php index aa3e67d8..513a6460 100644 --- a/src/Php/Encryptor.php +++ b/src/Php/Encryptor.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\PrettyPrinter\Standard; diff --git a/src/Php/Extractor.php b/src/Php/Extractor.php index 8dc71ab1..7307ae3f 100644 --- a/src/Php/Extractor.php +++ b/src/Php/Extractor.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class Extractor diff --git a/src/Php/FileScanner.php b/src/Php/FileScanner.php index abb6a194..e6c6feb1 100644 --- a/src/Php/FileScanner.php +++ b/src/Php/FileScanner.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class FileScanner diff --git a/src/Php/FileSorter.php b/src/Php/FileSorter.php index 4646f4b4..6727a7a5 100644 --- a/src/Php/FileSorter.php +++ b/src/Php/FileSorter.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class FileSorter diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index dace99d5..e9c3cf3c 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\Node; diff --git a/src/Php/FunctionDef.php b/src/Php/FunctionDef.php index b2900025..ec33a0ba 100644 --- a/src/Php/FunctionDef.php +++ b/src/Php/FunctionDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class FunctionDef diff --git a/src/Php/InterfaceDef.php b/src/Php/InterfaceDef.php index 68b0637e..c263f09d 100644 --- a/src/Php/InterfaceDef.php +++ b/src/Php/InterfaceDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class InterfaceDef extends ClassLikeDef diff --git a/src/Php/MagicMethodDetector.php b/src/Php/MagicMethodDetector.php index a8c6a48d..17b1ad24 100644 --- a/src/Php/MagicMethodDetector.php +++ b/src/Php/MagicMethodDetector.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\NodeAbstract; diff --git a/src/Php/MethodDef.php b/src/Php/MethodDef.php index f455a8df..f3de54db 100644 --- a/src/Php/MethodDef.php +++ b/src/Php/MethodDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class MethodDef diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index edfa5680..cd1ed02f 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\Node; diff --git a/src/Php/PropertyDef.php b/src/Php/PropertyDef.php index f38006ff..246e77f1 100644 --- a/src/Php/PropertyDef.php +++ b/src/Php/PropertyDef.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\Modifiers; diff --git a/src/Php/RedoException.php b/src/Php/RedoException.php index f6251c6c..a978c969 100644 --- a/src/Php/RedoException.php +++ b/src/Php/RedoException.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class RedoException extends \RuntimeException diff --git a/src/Php/Reflection.php b/src/Php/Reflection.php index a300b377..efadf004 100644 --- a/src/Php/Reflection.php +++ b/src/Php/Reflection.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class Reflection diff --git a/src/Php/SyntaxError.php b/src/Php/SyntaxError.php index 50c3f441..147fdbe2 100644 --- a/src/Php/SyntaxError.php +++ b/src/Php/SyntaxError.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class SyntaxError extends \RuntimeException diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d4cbb09c..93369f46 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use MJS\TopSort\Implementations\StringSort; @@ -47,8 +45,7 @@ class Translator extends Preprocessor $this->optimizeLevel = $this->climate->arguments->get('optimize'); $this->buildMode = $this->climate->arguments->get('mode'); $this->debugLine = intval($this->climate->arguments->get('debug-line')); - // $this->noLiteralStrings = $this->climate->arguments->get('noLiteralStrings'); - $this->noLiteralStrings = true; + $this->noLiteralStrings = $this->climate->arguments->get('noLiteralStrings'); $this->enableProfiler = $this->climate->arguments->defined('profile'); $this->internalFunctions = array_flip(get_defined_functions()['internal']); if ($this->climate->arguments->defined('help')) { diff --git a/src/Php/Unsupported.php b/src/Php/Unsupported.php index 77568817..c7c0d961 100644 --- a/src/Php/Unsupported.php +++ b/src/Php/Unsupported.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; class Unsupported extends \RuntimeException diff --git a/src/Php/Visitor.php b/src/Php/Visitor.php index 16ffaacc..2d64dab5 100644 --- a/src/Php/Visitor.php +++ b/src/Php/Visitor.php @@ -6,8 +6,6 @@ * @contact service@swoole.com */ -declare(strict_types=1); - namespace PhpAot\Php; use PhpParser\NodeVisitorAbstract;