Skip to content

Commit

Permalink
chore: run php-cs-fixer for the ./
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 2, 2022
1 parent 8e36450 commit 24d17d5
Show file tree
Hide file tree
Showing 41 changed files with 292 additions and 55 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('runtime')
->exclude('.github')
->exclude('vendor')
->in(__DIR__)
)
Expand Down
23 changes: 15 additions & 8 deletions example/cliapp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

use Toolkit\Cli\Cli;
use Toolkit\PFlag\CliApp;
Expand All @@ -10,18 +17,19 @@
// run demo:
// php example/cliapp.php

$app = CliApp::newWith(function (CliApp $app) {
$cli = CliApp::newWith(static function (CliApp $app): void {
$app->setName('myApp');
$app->setDesc('my cli application. v1.0.1');
})
->add('test1', fn(FlagsParser $fs) => vdump($fs->getOpts()), [
->add('test1', fn (FlagsParser $fs) => vdump($fs->getOpts()), [
'desc' => 'the test 1 command',
'options' => [
'opt1' => 'opt1 for command test1',
'opt2' => 'int;opt2 for command test1',
],
]);

$app->add('test2', function (FlagsParser $fs) {
$cli->add('test2', function (FlagsParser $fs): void {
Cli::info('options:');
vdump($fs->getOpts());
Cli::info('arguments:');
Expand All @@ -37,9 +45,8 @@
]
]);

$app->add('show-err', fn() => throw new RuntimeException('test show exception'));
$cli->add('show-err', fn () => throw new RuntimeException('test show exception'));

$app->addHandler(DemoCmdHandler::class);

$app->run();
$cli->addHandler(DemoCmdHandler::class);

$cli->run();
14 changes: 10 additions & 4 deletions example/clicmd.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

use Toolkit\Cli\Cli;
use Toolkit\PFlag\CliCmd;
Expand All @@ -11,7 +18,7 @@
// php example/clicmd.php --name inhere value1
// php example/clicmd.php --age 23 --name inhere value1

CliCmd::newWith(function (CliCmd $cmd) {
CliCmd::newWith(static function (CliCmd $cmd): void {
$cmd->name = 'demo';
$cmd->desc = 'description for demo command';

Expand All @@ -28,11 +35,10 @@
->withArguments([
'arg1' => 'this is arg1, is string'
])
->setHandler(function (FlagsParser $fs) {
->setHandler(function (FlagsParser $fs): void {
Cli::info('options:');
vdump($fs->getOpts());
Cli::info('arguments:');
vdump($fs->getArgs());
})
->run();

10 changes: 8 additions & 2 deletions example/not-stop_on_first.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php
// run: php example/not-stop_on_first.php
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

use Toolkit\PFlag\Flags;

Expand Down
11 changes: 9 additions & 2 deletions example/refer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

$flags = ['--name', 'inhere', '--tags', 'php', '-t', 'go', '--tags', 'java', '-f', 'arg0'];
echo "count: ", count($flags), "\n";
echo 'count: ', count($flags), "\n";

$cur = current($flags);
$key = key($flags);
Expand Down
2 changes: 1 addition & 1 deletion example/sflags-demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@
$fs->getArgs()
);

// vdump($fs->getArg('arrArg'));
// vdump($fs->getArg('arrArg'));
17 changes: 15 additions & 2 deletions src/CliApp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag;

Expand Down Expand Up @@ -660,14 +667,20 @@ public function setParams(array $params): void

/**
* @param string $name
*
* @return void
*/
public function setName(string $name): void
{
$this->params['name'] = $name;
}

/**
* @param string $name
*/
public function setDesc(string $name): void
{
$this->params['name'] = $name;
}

/**
* @return FlagsParser
*/
Expand Down
8 changes: 8 additions & 0 deletions src/CliCmd.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag;

Expand All @@ -18,6 +25,7 @@ class CliCmd
}

public string $name = '';

public string $desc = 'command description';

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Concern/HelperRenderTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Concern;

Expand Down
9 changes: 8 additions & 1 deletion src/Concern/RuleParserTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Concern;

Expand Down Expand Up @@ -292,7 +299,7 @@ protected function parseRuleOptName(string $key): array

// max length string as option name.
if (($kl = strlen($k)) > 1) {
if (!$name ) {
if (!$name) {
$name = $k;
} elseif ($kl > strlen($name)) {
$aliases[] = $name;
Expand Down
7 changes: 7 additions & 0 deletions src/Contract/CmdHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Contract;

Expand Down
2 changes: 1 addition & 1 deletion src/Contract/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
interface ParserInterface
{
public const KIND_OPT = 'option';

public const KIND_ARG = 'argument';

/**
Expand Down Expand Up @@ -282,5 +283,4 @@ public function unlock(): void;
* @return bool
*/
public function isLocked(): bool;

}
7 changes: 7 additions & 0 deletions src/Contract/ValidatorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Contract;

Expand Down
7 changes: 7 additions & 0 deletions src/Contract/ValueInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Contract;

Expand Down
8 changes: 7 additions & 1 deletion src/Exception/FlagParseException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Exception;

use Throwable;
use Toolkit\PFlag\FlagsParser;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Flag/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Toolkit\PFlag\Flag;

use Toolkit\Cli\Helper\FlagHelper;
use Toolkit\PFlag\Exception\FlagException;
use Toolkit\PFlag\FlagType;
use Toolkit\PFlag\FlagUtil;
Expand Down Expand Up @@ -200,5 +199,4 @@ public function toArray(): array
$info['shorts'] = $this->shorts;
return $info;
}

}
7 changes: 7 additions & 0 deletions src/FlagUtil.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag;

Expand Down
9 changes: 9 additions & 0 deletions src/FlagsParser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag;

Expand Down Expand Up @@ -30,6 +37,7 @@ abstract class FlagsParser implements ParserInterface
use RuleParserTrait;

public const TRIM_CHARS = "; \t\n\r\0\x0B";

public const OPT_MAX_WIDTH = 16;

public const RULE_SEP = ';';
Expand All @@ -49,6 +57,7 @@ abstract class FlagsParser implements ParserInterface
* - posix: `-abc` will expand: `-a=bc`
*/
public const SHORT_STYLE_GUN = 'gnu';

public const SHORT_STYLE_POSIX = 'posix';

public const DEFINE_ITEM = [
Expand Down
8 changes: 7 additions & 1 deletion src/Helper/ValueBinding.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Helper;

Expand All @@ -7,5 +14,4 @@
*/
class ValueBinding
{

}
8 changes: 7 additions & 1 deletion src/Helper/ValueCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Helper;

Expand All @@ -23,6 +30,5 @@ public function new(): self
*/
public function collect(FlagsParser $fs): void
{

}
}
7 changes: 7 additions & 0 deletions src/Validator/AbstractValidator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/

namespace Toolkit\PFlag\Validator;

Expand Down
Loading

0 comments on commit 24d17d5

Please sign in to comment.