Skip to content

Commit 6b65506

Browse files
authored
Merge pull request #59 from pattisahusiwa/phpcs
Add coding standard
2 parents 0b0cc44 + 91668c8 commit 6b65506

9 files changed

+101
-10
lines changed

.gitattributes

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
*.php text eol=lf
3+
4+
/.github export-ignore
5+
/.phive export-ignore
6+
/tests export-ignore
7+
/.editorconfig export-ignore
8+
/.gitattributes export-ignore
9+
/.gitignore export-ignore
10+
/.travis.yml export-ignore
11+
/ahccli.plugin.zsh export-ignore
12+
/phpcs.xml.dist export-ignore
13+
/phpunit.xml.dist export-ignore

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
/.env
44
/.idea/
55
/vendor/
6+
/tools/
7+
68
composer.lock
79
*.local.*
810
clover.xml
911
coverage.xml
12+
phpcs.xml

.phive/phars.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpcs" version="^3.5.5" installed="3.5.5" location="./tools/phpcs" copy="false"/>
4+
<phar name="phpcbf" version="^3.5.5" installed="3.5.5" location="./tools/phpcbf" copy="false"/>
5+
</phive>

composer.json

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
"description": "Command line interface library for PHP",
44
"type": "library",
55
"keywords": [
6-
"php7", "command", "argv-parser", "cli", "cli-color", "cli-action", "console",
7-
"cli-writer", "argument-parser", "cli-option", "stream-output", "stream-input",
8-
"cli-app", "console-app", "php-cli"
6+
"php7",
7+
"command",
8+
"argv-parser",
9+
"cli",
10+
"cli-color",
11+
"cli-action",
12+
"console",
13+
"cli-writer",
14+
"argument-parser",
15+
"cli-option",
16+
"stream-output",
17+
"stream-input",
18+
"cli-app",
19+
"console-app",
20+
"php-cli"
921
],
1022
"license": "MIT",
1123
"authors": [
@@ -32,6 +44,8 @@
3244
},
3345
"scripts": {
3446
"test": "phpunit",
35-
"test:cov": "phpunit --coverage-text --coverage-clover coverage.xml --coverage-html vendor/cov"
47+
"test:cov": "phpunit --coverage-text --coverage-clover coverage.xml --coverage-html vendor/cov",
48+
"cs:sniff": "tools/phpcs",
49+
"cs:fix": "tools/phpcbf"
3650
}
3751
}

phpcs.xml.dist

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset>
3+
<arg value="psv"/>
4+
<arg name="extensions" value="php"/>
5+
6+
<file>src</file>
7+
<file>tests</file>
8+
9+
<exclude-pattern>/vendor/</exclude-pattern>
10+
11+
<rule ref="PSR12"/>
12+
13+
<rule ref="PSR12">
14+
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses" />
15+
</rule>
16+
17+
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
18+
<exclude-pattern>/src/Input/Command.php</exclude-pattern>
19+
<exclude-pattern>/src/Input/Parser.php</exclude-pattern>
20+
</rule>
21+
22+
<rule ref="PSR12.Properties.ConstantVisibility.NotFound">
23+
<exclude-pattern>/src/</exclude-pattern>
24+
</rule>
25+
26+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
27+
<exclude-pattern>/tests/</exclude-pattern>
28+
</rule>
29+
30+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
31+
<exclude-pattern>/tests/</exclude-pattern>
32+
</rule>
33+
</ruleset>

src/Application.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ public function add(Command $command, string $alias = '', bool $default = false)
166166
{
167167
$name = $command->name();
168168

169-
if ($this->commands[$name] ?? $this->aliases[$name] ?? $this->commands[$alias] ?? $this->aliases[$alias] ?? null) {
169+
if (
170+
$this->commands[$name] ??
171+
$this->aliases[$name] ??
172+
$this->commands[$alias] ??
173+
$this->aliases[$alias] ??
174+
null
175+
) {
170176
throw new InvalidArgumentException(\sprintf('Command "%s" already added', $name));
171177
}
172178

src/Helper/Shell.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@ protected function checkTimeout()
157157

158158
// @codeCoverageIgnoreEnd
159159

160-
public function setOptions(string $cwd = null, array $env = null, float $timeout = null, array $otherOptions = []): self
161-
{
160+
public function setOptions(
161+
string $cwd = null,
162+
array $env = null,
163+
float $timeout = null,
164+
array $otherOptions = []
165+
): self {
162166
$this->cwd = $cwd;
163167
$this->env = $env;
164168
$this->processTimeout = $timeout;
@@ -176,7 +180,14 @@ public function execute(bool $async = false): self
176180
$this->descriptors = $this->getDescriptors();
177181
$this->processStartTime = \microtime(true);
178182

179-
$this->process = \proc_open($this->command, $this->descriptors, $this->pipes, $this->cwd, $this->env, $this->otherOptions);
183+
$this->process = \proc_open(
184+
$this->command,
185+
$this->descriptors,
186+
$this->pipes,
187+
$this->cwd,
188+
$this->env,
189+
$this->otherOptions
190+
);
180191
$this->setInput();
181192

182193
// @codeCoverageIgnoreStart

tests/Output/ColorTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function test_colors()
5555
$this->assertSame("\033[0;31mRed\033[0m", $c->colors('<red>Red</end>'));
5656
$this->assertSame("\033[1;31mBoldRed\n\033[0m", $c->colors('<boldRed>BoldRed<eol/></end>'));
5757
$this->assertSame("\033[0;36;42mBgGreenCyan\033[0m\n", $c->colors('<bgGreenCyan>BgGreenCyan</end><eol>'));
58-
$this->assertSame("\033[0;31mRed\033[0m\nNormal\n\033[1;37mBOLD\033[0m", $c->colors("<red>Red</end>\r\nNormal\n<bold>BOLD</end>"));
58+
$this->assertSame(
59+
"\033[0;31mRed\033[0m\nNormal\n\033[1;37mBOLD\033[0m",
60+
$c->colors("<red>Red</end>\r\nNormal\n<bold>BOLD</end>")
61+
);
5962
}
6063

6164
public function test_magic_call()

tests/Output/WriterTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public function test_table()
8686
]);
8787

8888
$this->assertSame(3, \substr_count($this->buffer(), '+--------+------+------+'), '3 dashes');
89-
$this->assertBufferContains("|\33[1;37;42m A \33[0m|\33[1;37;42m B C \33[0m|\33[1;37;42m C D \33[0m|", 'Head');
89+
$this->assertBufferContains(
90+
"|\33[1;37;42m A \33[0m|\33[1;37;42m B C \33[0m|\33[1;37;42m C D \33[0m|",
91+
'Head'
92+
);
9093
$this->assertBufferContains("|\33[0;35m apple \33[0m|\33[0;35m ball \33[0m|\33[0;35m cat \33[0m|", 'Odd');
9194
$this->assertBufferContains("|\33[0;36m applet \33[0m|\33[0;36m bee \33[0m|\33[0;36m cute \33[0m|", 'Even');
9295
}

0 commit comments

Comments
 (0)