mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
代码规范化
This commit is contained in:
@@ -22,7 +22,7 @@ class Command
|
||||
/** @var Console */
|
||||
private $console;
|
||||
private $name;
|
||||
private $aliases = [];
|
||||
private $aliases = [];
|
||||
private $definition;
|
||||
private $help;
|
||||
private $description;
|
||||
@@ -30,8 +30,8 @@ class Command
|
||||
private $consoleDefinitionMerged = false;
|
||||
private $consoleDefinitionMergedWithArgs = false;
|
||||
private $code;
|
||||
private $synopsis = [];
|
||||
private $usages = [];
|
||||
private $synopsis = [];
|
||||
private $usages = [];
|
||||
|
||||
/** @var Input */
|
||||
protected $input;
|
||||
@@ -172,7 +172,7 @@ class Command
|
||||
$statusCode = $this->execute($input, $output);
|
||||
}
|
||||
|
||||
return is_numeric($statusCode) ? (int)$statusCode : 0;
|
||||
return is_numeric($statusCode) ? (int) $statusCode : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,7 +362,6 @@ class Command
|
||||
return $this->help;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 描述信息
|
||||
* @return string
|
||||
@@ -465,4 +464,4 @@ class Command
|
||||
throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace think\console;
|
||||
|
||||
use think\console\input\Definition;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Definition;
|
||||
use think\console\input\Option;
|
||||
|
||||
class Input
|
||||
@@ -38,7 +38,6 @@ class Input
|
||||
private $tokens;
|
||||
private $parsed;
|
||||
|
||||
|
||||
public function __construct($argv = null)
|
||||
{
|
||||
if (null === $argv) {
|
||||
@@ -52,7 +51,6 @@ class Input
|
||||
$this->definition = new Definition();
|
||||
}
|
||||
|
||||
|
||||
protected function setTokens(array $tokens)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
@@ -71,7 +69,6 @@ class Input
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析参数
|
||||
*/
|
||||
@@ -94,7 +91,6 @@ class Input
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析短选项
|
||||
* @param string $token 当前的指令.
|
||||
@@ -178,7 +174,6 @@ class Input
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加一个短选项的值
|
||||
* @param string $shortcut 短名称
|
||||
@@ -260,7 +255,6 @@ class Input
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查原始参数是否包含某个值
|
||||
* @param string|array $values 需要检查的值
|
||||
@@ -268,7 +262,7 @@ class Input
|
||||
*/
|
||||
public function hasParameterOption($values)
|
||||
{
|
||||
$values = (array)$values;
|
||||
$values = (array) $values;
|
||||
|
||||
foreach ($this->tokens as $token) {
|
||||
foreach ($values as $value) {
|
||||
@@ -289,7 +283,7 @@ class Input
|
||||
*/
|
||||
public function getParameterOption($values, $default = false)
|
||||
{
|
||||
$values = (array)$values;
|
||||
$values = (array) $values;
|
||||
$tokens = $this->tokens;
|
||||
|
||||
while (0 < count($tokens)) {
|
||||
@@ -309,7 +303,6 @@ class Input
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证输入
|
||||
* @throws \RuntimeException
|
||||
@@ -336,7 +329,7 @@ class Input
|
||||
*/
|
||||
public function setInteractive($interactive)
|
||||
{
|
||||
$this->interactive = (bool)$interactive;
|
||||
$this->interactive = (bool) $interactive;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,7 +452,7 @@ class Input
|
||||
return $match[1] . $this->escapeToken($match[2]);
|
||||
}
|
||||
|
||||
if ($token && $token[0] !== '-') {
|
||||
if ($token && '-' !== $token[0]) {
|
||||
return $this->escapeToken($token);
|
||||
}
|
||||
|
||||
@@ -468,4 +461,4 @@ class Input
|
||||
|
||||
return implode(' ', $tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class Output
|
||||
*/
|
||||
public function setVerbosity($level)
|
||||
{
|
||||
$this->verbosity = (int)$level;
|
||||
$this->verbosity = (int) $level;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ class Output
|
||||
{
|
||||
$descriptor = new Descriptor();
|
||||
$options = array_merge([
|
||||
'raw_text' => false
|
||||
'raw_text' => false,
|
||||
], $options);
|
||||
|
||||
$descriptor->describe($this, $object, $options);
|
||||
@@ -114,4 +114,4 @@ class Output
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class Build extends Command
|
||||
$this->setName('build')
|
||||
->setDefinition([
|
||||
new Option('config', null, Option::VALUE_OPTIONAL, "build.php path"),
|
||||
new Option('module', null, Option::VALUE_OPTIONAL, "module name")
|
||||
new Option('module', null, Option::VALUE_OPTIONAL, "module name"),
|
||||
])
|
||||
->setDescription('Build Application Dirs');
|
||||
}
|
||||
|
||||
@@ -112,4 +112,4 @@ class Argument
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,4 +372,4 @@ class Definition
|
||||
|
||||
return implode(' ', $elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,10 +181,10 @@ class Option
|
||||
public function equals(Option $option)
|
||||
{
|
||||
return $option->getName() === $this->getName()
|
||||
&& $option->getShortcut() === $this->getShortcut()
|
||||
&& $option->getDefault() === $this->getDefault()
|
||||
&& $option->isArray() === $this->isArray()
|
||||
&& $option->isValueRequired() === $this->isValueRequired()
|
||||
&& $option->isValueOptional() === $this->isValueOptional();
|
||||
&& $option->getShortcut() === $this->getShortcut()
|
||||
&& $option->getDefault() === $this->getDefault()
|
||||
&& $option->isArray() === $this->isArray()
|
||||
&& $option->isValueRequired() === $this->isValueRequired()
|
||||
&& $option->isValueOptional() === $this->isValueOptional();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
|
||||
namespace think\console\output;
|
||||
|
||||
use think\console\Output;
|
||||
use think\console\input\Argument as InputArgument;
|
||||
use think\console\input\Option as InputOption;
|
||||
use think\console\input\Definition as InputDefinition;
|
||||
use think\console\Command;
|
||||
use think\Console;
|
||||
use think\console\Command;
|
||||
use think\console\input\Argument as InputArgument;
|
||||
use think\console\input\Definition as InputDefinition;
|
||||
use think\console\input\Option as InputOption;
|
||||
use think\console\Output;
|
||||
use think\console\output\descriptor\Console as ConsoleDescription;
|
||||
|
||||
class Descriptor
|
||||
@@ -254,7 +254,7 @@ class Descriptor
|
||||
$this->writeText("\n");
|
||||
$spacingWidth = $width - strlen($name);
|
||||
$this->writeText(sprintf(" <info>%s</info>%s%s", $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)
|
||||
->getDescription()), $options);
|
||||
->getDescription()), $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ class Descriptor
|
||||
private function writeText($content, array $options = [])
|
||||
{
|
||||
$this->write(isset($options['raw_text'])
|
||||
&& $options['raw_text'] ? strip_tags($content) : $content, isset($options['raw_output']) ? !$options['raw_output'] : true);
|
||||
&& $options['raw_text'] ? strip_tags($content) : $content, isset($options['raw_output']) ? !$options['raw_output'] : true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,4 +316,4 @@ class Descriptor
|
||||
|
||||
return $totalWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\output;
|
||||
|
||||
use think\console\output\formatter\Style;
|
||||
use think\console\output\formatter\Stack as StyleStack;
|
||||
use think\console\output\formatter\Style;
|
||||
|
||||
class Formatter
|
||||
{
|
||||
@@ -51,7 +51,7 @@ class Formatter
|
||||
*/
|
||||
public function setDecorated($decorated)
|
||||
{
|
||||
$this->decorated = (bool)$decorated;
|
||||
$this->decorated = (bool) $decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,4 +195,4 @@ class Formatter
|
||||
{
|
||||
return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@
|
||||
|
||||
namespace think\console\output\descriptor;
|
||||
|
||||
|
||||
use think\console\Command;
|
||||
use think\Console as ThinkConsole;
|
||||
use think\console\Command;
|
||||
|
||||
class Console
|
||||
{
|
||||
@@ -147,4 +146,4 @@ class Console
|
||||
|
||||
return $namespacedCommands;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace think\console\output\driver;
|
||||
|
||||
|
||||
use think\console\Output;
|
||||
|
||||
class Buffer
|
||||
@@ -35,7 +34,7 @@ class Buffer
|
||||
|
||||
public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL)
|
||||
{
|
||||
$messages = (array)$messages;
|
||||
$messages = (array) $messages;
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$this->buffer .= $message;
|
||||
@@ -50,4 +49,4 @@ class Buffer
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ class Console
|
||||
/** @var Output */
|
||||
private $output;
|
||||
|
||||
|
||||
public function __construct(Output $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
@@ -44,7 +43,7 @@ class Console
|
||||
return;
|
||||
}
|
||||
|
||||
$messages = (array)$messages;
|
||||
$messages = (array) $messages;
|
||||
|
||||
foreach ($messages as $message) {
|
||||
switch ($type) {
|
||||
@@ -132,7 +131,6 @@ class Console
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取终端宽度
|
||||
* @return int|null
|
||||
@@ -167,19 +165,19 @@ class Console
|
||||
|
||||
if ('\\' === DS) {
|
||||
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
|
||||
return [(int)$matches[1], (int)$matches[2]];
|
||||
return [(int) $matches[1], (int) $matches[2]];
|
||||
}
|
||||
if (preg_match('/^(\d+)x(\d+)$/', $this->getMode(), $matches)) {
|
||||
return [(int)$matches[1], (int)$matches[2]];
|
||||
return [(int) $matches[1], (int) $matches[2]];
|
||||
}
|
||||
}
|
||||
|
||||
if ($sttyString = $this->getSttyColumns()) {
|
||||
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
|
||||
return [(int)$matches[2], (int)$matches[1]];
|
||||
return [(int) $matches[2], (int) $matches[1]];
|
||||
}
|
||||
if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
|
||||
return [(int)$matches[2], (int)$matches[1]];
|
||||
return [(int) $matches[2], (int) $matches[1]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +305,6 @@ class Console
|
||||
return false === $this->isRunningOS400();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
@@ -354,13 +351,13 @@ class Console
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR === '\\') {
|
||||
return
|
||||
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD)
|
||||
|| false !== getenv('ANSICON')
|
||||
|| 'ON' === getenv('ConEmuANSI')
|
||||
|| 'xterm' === getenv('TERM');
|
||||
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD)
|
||||
|| false !== getenv('ANSICON')
|
||||
|| 'ON' === getenv('ConEmuANSI')
|
||||
|| 'xterm' === getenv('TERM');
|
||||
}
|
||||
|
||||
return function_exists('posix_isatty') && @posix_isatty($stream);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ class Nothing
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,4 +113,4 @@ class Stack
|
||||
{
|
||||
return $this->emptyStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Style
|
||||
'cyan' => ['set' => 46, 'unset' => 49],
|
||||
'white' => ['set' => 47, 'unset' => 49],
|
||||
];
|
||||
private static $availableOptions = [
|
||||
private static $availableOptions = [
|
||||
'bold' => ['set' => 1, 'unset' => 22],
|
||||
'underscore' => ['set' => 4, 'unset' => 24],
|
||||
'blink' => ['set' => 5, 'unset' => 25],
|
||||
@@ -186,4 +186,4 @@ class Style
|
||||
|
||||
return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace think\console\helper\question;
|
||||
|
||||
|
||||
class Choice extends Question
|
||||
{
|
||||
|
||||
@@ -154,4 +153,4 @@ class Choice extends Question
|
||||
return current($multiselectChoices);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace think\console\helper\question;
|
||||
|
||||
|
||||
class Confirmation extends Question
|
||||
{
|
||||
|
||||
@@ -25,7 +24,7 @@ class Confirmation extends Question
|
||||
*/
|
||||
public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i')
|
||||
{
|
||||
parent::__construct($question, (bool)$default);
|
||||
parent::__construct($question, (bool) $default);
|
||||
|
||||
$this->trueAnswerRegex = $trueAnswerRegex;
|
||||
$this->setNormalizer($this->getDefaultNormalizer());
|
||||
@@ -45,7 +44,7 @@ class Confirmation extends Question
|
||||
return $answer;
|
||||
}
|
||||
|
||||
$answerIsTrue = (bool)preg_match($regex, $answer);
|
||||
$answerIsTrue = (bool) preg_match($regex, $answer);
|
||||
if (false === $default) {
|
||||
return $answer && $answerIsTrue;
|
||||
}
|
||||
@@ -53,4 +52,4 @@ class Confirmation extends Question
|
||||
return !$answer || $answerIsTrue;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Question
|
||||
throw new \LogicException('A hidden question cannot use the autocompleter.');
|
||||
}
|
||||
|
||||
$this->hidden = (bool)$hidden;
|
||||
$this->hidden = (bool) $hidden;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class Question
|
||||
*/
|
||||
public function setHiddenFallback($fallback)
|
||||
{
|
||||
$this->hiddenFallback = (bool)$fallback;
|
||||
$this->hiddenFallback = (bool) $fallback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -206,6 +206,6 @@ class Question
|
||||
|
||||
protected function isAssoc($array)
|
||||
{
|
||||
return (bool)count(array_filter(array_keys($array), 'is_string'));
|
||||
return (bool) count(array_filter(array_keys($array), 'is_string'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user