Skip to content

Commit d504366

Browse files
committed
Add PHPCS & fix its errors
1 parent 9c7be18 commit d504366

13 files changed

+229
-44
lines changed

.phpcs.xml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Tighten">
3+
<!--
4+
The name attribute of the ruleset tag is displayed
5+
when running PHP_CodeSniffer with the -v command line
6+
argument. The description tag below is not displayed anywhere
7+
except in this file, so it can contain information for
8+
developers who may change this file in the future.
9+
-->
10+
<description>Tighten's Laravel Coding Standards</description>
11+
12+
<!--
13+
If no files or directories are specified on the command line
14+
your custom standard can specify what files should be checked
15+
instead.
16+
17+
Note that specifying any file or directory path
18+
on the command line will ignore all file tags.
19+
-->
20+
<file>app</file>
21+
<file>config</file>
22+
<file>tests</file>
23+
24+
<!--
25+
You can hard-code ignore patterns directly into your
26+
custom standard so you don't have to specify the
27+
patterns on the command line.
28+
-->
29+
<exclude-pattern>*/cache/*</exclude-pattern>
30+
<exclude-pattern>*/*.js</exclude-pattern>
31+
<exclude-pattern>*/*.css</exclude-pattern>
32+
<exclude-pattern>*/*.xml</exclude-pattern>
33+
<exclude-pattern>*/*.blade.php</exclude-pattern>
34+
<exclude-pattern>*/autoload.php</exclude-pattern>
35+
<exclude-pattern>*/docs/*</exclude-pattern>
36+
<exclude-pattern>*/vendor/*</exclude-pattern>
37+
38+
<!--
39+
You can hard-code command line values into your custom standard.
40+
Note that this does not work for the command line values:
41+
-v[v][v], -l, -d, -sniffs and -standard
42+
-->
43+
<arg name="colors"/>
44+
<arg value="p"/>
45+
46+
<!--
47+
You can hard-code custom php.ini settings into your custom standard.
48+
The following tag sets the memory limit to 64M.
49+
-->
50+
<ini name="memory_limit" value="128M"/>
51+
52+
<!--
53+
Include all sniffs in the PSR2 standard. Note that the
54+
path to the standard does not have to be specified as the
55+
PSR2 standard exists inside the PHP_CodeSniffer install
56+
directory.
57+
-->
58+
<rule ref="PSR2"/>
59+
60+
<!-- Disable missing namespace rule for tests and database files -->
61+
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
62+
<exclude-pattern>*/database/*</exclude-pattern>
63+
<exclude-pattern>*/tests/*</exclude-pattern>
64+
</rule>
65+
<!-- Disable camel caps rule for tests -->
66+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
67+
<exclude-pattern>*/tests/*</exclude-pattern>
68+
</rule>
69+
<!-- Disable method visibility rule for tests -->
70+
<rule ref="Squiz.Scope.MethodScope">
71+
<exclude-pattern>*/tests/*</exclude-pattern>
72+
</rule>
73+
<!-- Make the soft line length warning silent -->
74+
<!--
75+
<rule ref="Generic.Files.LineLength.TooLong">
76+
<severity>0</severity>
77+
</rule>
78+
-->
79+
80+
<!-- Enable some extra rules -->
81+
<!-- Force [] short array syntax -->
82+
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
83+
<!-- Enforce 1 space around concatenation operators -->
84+
<rule ref="Squiz.Strings.ConcatenationSpacing">
85+
<properties>
86+
<property name="spacing" value="1" />
87+
</properties>
88+
</rule>
89+
<!-- Warn when double quotes are used over single quotes -->
90+
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
91+
<!-- Except when the double quotes contain a variable -->
92+
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
93+
<severity>0</severity>
94+
</rule>
95+
96+
<!-- Class name should match the file name -->
97+
<rule ref="Squiz.Classes.ClassFileName"/>
98+
99+
<!-- Expect one space after NOT (!) operator -->
100+
<rule ref="Generic.Formatting.SpaceAfterNot"/>
101+
</ruleset>
102+

app/Commands/HelpCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class HelpCommand extends Command
2323

2424
public function handle(): void
2525
{
26-
$this->line("\n <fg=white;options=bold>Takeout</> <fg=green;options=bold>" . config('app.version') . "</>");
26+
$this->line("\n <fg=white;options=bold>Takeout</> <fg=green;options=bold>" . config('app.version') . '</>');
2727
$this->line("\n <comment>Usage:</comment>");
2828
$this->line(" takeout <command> [arguments]\n");
29-
$this->line(" <comment>Commands:</comment>");
29+
$this->line(' <comment>Commands:</comment>');
3030

3131
foreach ($this->commands as $command => $description) {
3232
$spaces = $this->makeSpaces(strlen($command));
@@ -36,6 +36,6 @@ public function handle(): void
3636

3737
public function makeSpaces($count)
3838
{
39-
return str_repeat(" ", $this->indent - $count);
39+
return str_repeat(' ', $this->indent - $count);
4040
}
4141
}

app/Commands/StopCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function stoppableContainers(): array
3939

4040
return [
4141
$label,
42-
function(CliMenu $menu) use ($container, $label) {
42+
function (CliMenu $menu) use ($container, $label) {
4343
$this->stop($menu->getSelectedItem()->getText());
4444

4545
foreach ($menu->getItems() as $item) {

app/Services/MySql.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function buildParameters(): array
3333
{
3434
$parameters = parent::buildParameters();
3535

36-
$parameters["allow_empty_password"] = $parameters["root_password"] === "" ? "yes" : "no";
36+
$parameters['allow_empty_password'] = $parameters['root_password'] === '' ? 'yes' : 'no';
3737

3838
return $parameters;
3939
}

app/Services/Sftp.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function prompts(): void
6262
{
6363
parent::prompts();
6464

65-
if ($this->promptResponses['mapped_directory'] !== "") {
65+
if ($this->promptResponses['mapped_directory'] !== '') {
6666
$this->dockerRunTemplate = '-v "${:local_mapping}" ' . $this->dockerRunTemplate;
6767
}
6868
}
@@ -71,13 +71,22 @@ protected function buildParameters(): array
7171
{
7272
$parameters = parent::buildParameters();
7373

74-
if ($parameters['mapped_directory'] !== "") {
75-
$parameters['local_mapping'] = trim($parameters['mapped_directory'], ' ') . ':/home/'
76-
. $parameters['user_name'] . '/' . $parameters['upload_directory'];
74+
if ($parameters['mapped_directory'] !== '') {
75+
$parameters['local_mapping'] = sprintf(
76+
'%s:/home/%s/%s',
77+
trim($parameters['mapped_directory'], ' '),
78+
$parameters['user_name'],
79+
$parameters['upload_directory']
80+
);
81+
7782
$parameters['user_config'] = $parameters['user_name'] . ':' . $parameters['password'] . ':1001';
7883
} else {
79-
$parameters['user_config'] = $parameters['user_name'] . ':' . $parameters['password']
80-
. ':::' . $parameters["upload_directory"];
84+
$parameters['user_config'] = sprintf(
85+
'%s:%s:::%s',
86+
$parameters['user_name'],
87+
$parameters['password'],
88+
$parameters['upload_directory']
89+
);
8190
}
8291

8392
return $parameters;

app/Shell/Docker.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ public function bootContainer(string $dockerRunTemplate, array $parameters): voi
136136

137137
$command = sprintf(
138138
'docker run -d --name "${:container_name}" %s %s',
139-
$this->networking->networkSettings($parameters['alias'], $parameters['image_name']),
140-
$dockerRunTemplate
139+
$this->networking->networkSettings($parameters['alias'], $parameters['image_name']),
140+
$dockerRunTemplate
141141
);
142142

143143
$process = $this->shell->exec($command, $parameters);
144144

145145
if (! $process->isSuccessful()) {
146-
throw new Exception("Failed installing " . $parameters['image_name']);
146+
throw new Exception('Failed installing ' . $parameters['image_name']);
147147
}
148148
}
149149

app/Shell/DockerNetworking.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function ensureNetworkCreated($name = 'takeout'): void
4040

4141
public function baseAliasExists(string $name): bool
4242
{
43-
$output = $this->shell->execQuietly('docker ps --filter "label=com.tighten.takeout.Base_Alias=' . $name . '" --format "table {{.ID}}|{{.Names}}"')->getOutput();
43+
$output = $this->shell->execQuietly(
44+
'docker ps --filter "label=com.tighten.takeout.Base_Alias=' . $name . '" --format "table {{.ID}}|{{.Names}}"'
45+
)->getOutput();
46+
4447
$collection = $this->formatter->rawTableOutputToCollection($output);
4548

4649
return $collection->isNotEmpty();

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"mockery/mockery": "^1.3.1",
2626
"nunomaduro/laravel-console-menu": "^3.0",
2727
"phpunit/phpunit": "^8.5",
28+
"squizlabs/php_codesniffer": "^3.5",
2829
"tightenco/tlint": "^5.0"
2930
},
3031
"autoload": {

composer.lock

+57-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/DockerContainersTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ function it_formats_output_to_tables()
2929

3030
$output = app(Docker::class)->takeoutContainers();
3131

32-
$expectedTable = [
33-
['container_id' => '123456789abc', 'names' => 'TO-meilisearch', 'status' => 'Up 15 Minutes', 'ports' => '7700:7700'],
34-
];
32+
$expectedTable = [[
33+
'container_id' => '123456789abc',
34+
'names' => 'TO-meilisearch',
35+
'status' => 'Up 15 Minutes',
36+
'ports' => '7700:7700'
37+
]];
3538

3639
$this->assertEquals($expectedTable, $output->toArray());
3740
}

tests/Feature/MicrosoftDockerTagsTest.php

+7-24
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
use App\Services\MsSql;
66
use App\Shell\MicrosoftDockerTags;
77
use GuzzleHttp\Client;
8-
use GuzzleHttp\Psr7\Stream as Psr7Stream;
98
use Mockery as M;
109
use Tests\TestCase;
1110

1211
class MicrosoftDockerTagsTest extends TestCase
1312
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
require_once(base_path('tests/support/MicrosoftDockerTagsFakestream.php'));
18+
}
19+
1420
/** @test */
1521
function it_gets_a_general_availability_release()
1622
{
@@ -47,26 +53,3 @@ function it_reverses_tag_list()
4753
$this->assertEquals('2024-GA-ubuntu-18.04', $dockerTags->getLatestTag());
4854
}
4955
}
50-
51-
class MicrosoftDockerTagsFakestream extends Psr7Stream
52-
{
53-
public function __construct($stream, $options = [])
54-
{
55-
// Do nothing
56-
}
57-
58-
public function __toString()
59-
{
60-
return json_encode([
61-
'name' => 'mssql/server',
62-
'tags' => [
63-
'2017-CU1-ubuntu',
64-
'2017-GDR3',
65-
'2019-RC1',
66-
'2019-GA-ubuntu-16.04',
67-
'2024-GA-ubuntu-18.04',
68-
'latest',
69-
],
70-
]);
71-
}
72-
}

tests/Feature/ServicesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function all_array_is_keyed_by_shortnames_and_values_are_fqcns()
2828
$filtered = collect($services->all())->filter(function ($fqcn, $shortname) {
2929
return Str::contains($fqcn, 'App\Services');
3030
})->filter(function ($fqcn, $shortname) {
31-
return !! preg_match('/^[a-z][a-z0-9]+$/', $shortname);
31+
return ! ! preg_match('/^[a-z][a-z0-9]+$/', $shortname);
3232
});
3333

3434
$this->assertEquals($all->count(), $filtered->count());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use GuzzleHttp\Psr7\Stream as Psr7Stream;
6+
7+
class MicrosoftDockerTagsFakestream extends Psr7Stream
8+
{
9+
public function __construct($stream, $options = [])
10+
{
11+
// Do nothing
12+
}
13+
14+
public function __toString()
15+
{
16+
return json_encode([
17+
'name' => 'mssql/server',
18+
'tags' => [
19+
'2017-CU1-ubuntu',
20+
'2017-GDR3',
21+
'2019-RC1',
22+
'2019-GA-ubuntu-16.04',
23+
'2024-GA-ubuntu-18.04',
24+
'latest',
25+
],
26+
]);
27+
}
28+
}

0 commit comments

Comments
 (0)