Skip to content

Commit d940bcd

Browse files
committed
Enforce PSR-12
1 parent b30410a commit d940bcd

File tree

16 files changed

+290
-175
lines changed

16 files changed

+290
-175
lines changed

.gitlab-ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
# required for this CI Pipeline:
3+
# - squizlabs/php_codesniffer
4+
# - phpstan.neon file
5+
# recommended: captainhook/captainhook
6+
7+
8+
default:
9+
image: serversideup/php:8.1-cli
10+
11+
stages:
12+
- test
13+
14+
cache:
15+
paths:
16+
- vendor/
17+
18+
test_quality:
19+
script:
20+
- composer install
21+
- vendor/bin/phpcs --standard=PSR12 -n src
22+
# - vendor/bin/phpcs --standard=PSR12 -n tests --exclude=PSR1.Methods.CamelCapsMethodName
23+
- vendor/bin/phpstan analyse

captainhook.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"commit-msg": {
3+
"enabled": true,
4+
"actions": []
5+
},
6+
"pre-push": {
7+
"enabled": false,
8+
"actions": []
9+
},
10+
"pre-commit": {
11+
"enabled": true,
12+
"actions": [
13+
{
14+
"action": "vendor/bin/phpcbf --standard=PSR12 src",
15+
"options": []
16+
},
17+
{
18+
"action": "vendor/bin/phpstan analyze",
19+
"options": []
20+
}
21+
]
22+
},
23+
"prepare-commit-msg": {
24+
"enabled": false,
25+
"actions": []
26+
},
27+
"post-commit": {
28+
"enabled": false,
29+
"actions": []
30+
},
31+
"post-merge": {
32+
"enabled": false,
33+
"actions": []
34+
},
35+
"post-checkout": {
36+
"enabled": false,
37+
"actions": []
38+
},
39+
"post-rewrite": {
40+
"enabled": false,
41+
"actions": []
42+
},
43+
"post-change": {
44+
"enabled": false,
45+
"actions": []
46+
}
47+
}

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
}
3636
},
3737
"require-dev": {
38-
"phpstan/phpstan": "^1.10"
38+
"phpstan/phpstan": "^1.10",
39+
"squizlabs/php_codesniffer": "^3.7",
40+
"captainhook/captainhook": "^5.16"
3941
}
4042
}

src/Commands/AboutLog.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class AboutLog extends Command
3232
* @return int
3333
*/
3434
public function handle()
35-
{
36-
// gather all channels as they are used
35+
{
36+
// gather all channels as they are used
3737
$mainChannels = [
38-
'Default Channel' => config('logging.default'),
38+
'Default Channel' => config('logging.default'),
3939
'Deprecations Channel' => config('logging.deprecations.channel'),
4040
];
41-
41+
4242
// now parse the main channels for their used channels
4343
$channels = [];
4444

@@ -48,24 +48,24 @@ public function handle()
4848
['level' => 'emergency'],
4949
);
5050

51-
foreach($mainChannels as $key => $channel) {
52-
if($channel == null) {
51+
foreach ($mainChannels as $key => $channel) {
52+
if ($channel == null) {
5353
// overwrite with null string
5454
$mainChannels[$key] = self::STR_NULL;
5555
continue;
5656
}
5757

58-
$channels[$channel] = config('logging.channels.'.$channel);
58+
$channels[$channel] = config('logging.channels.' . $channel);
5959

6060
// check if this channel has sub-channels
61-
if(count(config('logging.channels.'.$channel.'.channels', []))) {
62-
$subchannels = config('logging.channels.'.$channel.'.channels');
63-
foreach($subchannels as $sub) {
64-
$channels[$sub] = config('logging.channels.'.$sub);
61+
if (count(config('logging.channels.' . $channel . '.channels', []))) {
62+
$subchannels = config('logging.channels.' . $channel . '.channels');
63+
foreach ($subchannels as $sub) {
64+
$channels[$sub] = config('logging.channels.' . $sub);
6565
}
6666

6767
// update the channel string for this main channel
68-
$mainChannels[$key] = $channel.': '.implode(', ', $subchannels);
68+
$mainChannels[$key] = $channel . ': ' . implode(', ', $subchannels);
6969
}
7070
}
7171

@@ -77,27 +77,29 @@ public function handle()
7777
CommandHelper::displaySection($this, 'Logging Configuration', array_merge($config, $mainChannels));
7878

7979
// get data from channels
80-
foreach($channels as $channel => $config) {
80+
foreach ($channels as $channel => $config) {
8181
// make sure each channel has driver and level
8282

8383
// custom sort the config: first driver, level, path, rest alphabetical
8484
$arr = [
8585
'driver' => $config['driver'] ?? null,
8686
'level' => $config['level'] ?? null,
8787
];
88-
if(isset($config['path'])) $arr['path'] = $config['path'];
88+
if (isset($config['path'])) {
89+
$arr['path'] = $config['path'];
90+
}
8991
ksort($config);
9092
$config = array_merge($arr, $config);
9193

9294
$display = [];
9395
// now sift through the config
94-
foreach($config as $key => $value) {
96+
foreach ($config as $key => $value) {
9597
// make arrays into strings
96-
if(is_array($value)) {
98+
if (is_array($value)) {
9799
$value = implode(', ', $value);
98100
}
99101

100-
switch($key) {
102+
switch ($key) {
101103
// filter away what shouldnt be shown
102104
case 'username':
103105
case 'password':
@@ -107,11 +109,10 @@ public function handle()
107109
break;
108110
case 'path':
109111
// now check if this file exists and when it was modified
110-
if(file_exists($value)) {
111-
$value = '<fg=gray><'.date('Y-m-d H:i:s', (int) filemtime($value)).'></> '.$value;
112-
}
113-
else {
114-
$value = '<fg=gray><file missing></> <fg=red>'.$value.'</>';
112+
if (file_exists($value)) {
113+
$value = '<fg=gray><' . date('Y-m-d H:i:s', (int) filemtime($value)) . '></> ' . $value;
114+
} else {
115+
$value = '<fg=gray><file missing></> <fg=red>' . $value . '</>';
115116
}
116117
break;
117118
case 'level':
@@ -120,16 +121,16 @@ public function handle()
120121
break;
121122
}
122123

123-
if(is_bool($value)) {
124+
if (is_bool($value)) {
124125
$value = $value ? self::STR_TRUE : self::STR_FALSE;
125126
}
126127

127128
$display[$key] = $value ?? self::STR_NULL;
128129
}
129130

130-
CommandHelper::displaySection($this, 'Channel: '.$channel, $display);
131+
CommandHelper::displaySection($this, 'Channel: ' . $channel, $display);
131132
}
132-
133+
133134
$this->newLine();
134135

135136
return Command::SUCCESS;

src/Commands/ClearLog.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ class ClearLog extends Command
3131
* @return int
3232
*/
3333
public function handle()
34-
{
34+
{
3535
// make sure the all flag is set when no channel is provided
36-
if(empty($this->argument('channel')) && $this->option('all') === false) {
36+
if (empty($this->argument('channel')) && $this->option('all') === false) {
3737
$this->error('No channel name provided. If you wish to clear all logs, set the --all option explicitly.');
3838
return Command::INVALID;
3939
}
4040

4141
// now create the channel driver objects safely
4242
$channels = [];
43-
if($this->argument('channel')) {
43+
if ($this->argument('channel')) {
4444
$channel = $this->argument('channel');
4545
$channels[] = (string) (is_array($channel) ? $channel[0] : $channel);
4646
// check if this channel is configured
47-
if(empty(config('logging.channels.'.$channels[0]))) {
47+
if (empty(config('logging.channels.' . $channels[0]))) {
4848
$this->error('Channel is not configured!');
4949
return Command::INVALID;
5050
}
5151
}
52-
if($this->option('all')) {
52+
if ($this->option('all')) {
5353
$channels = [
5454
config('logging.default'),
5555
config('logging.deprecations.channel'),
@@ -66,13 +66,13 @@ public function handle()
6666
// and load the files through the driver
6767
$files = $multidriver->getFilenames();
6868

69-
$this->line('Found '.count($files).' log files');
69+
$this->line('Found ' . count($files) . ' log files');
7070

7171
// loop through the files and clear them
72-
foreach($files as $file) {
72+
foreach ($files as $file) {
7373
$this->line($file);
7474
// clear the file
75-
if(unlink($file) == false) {
75+
if (unlink($file) == false) {
7676
$this->error('Failed unlinking file!');
7777
continue;
7878
}

src/Commands/SearchLog.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputArgument;
88

9-
class SearchLog extends ShowLog {
9+
class SearchLog extends ShowLog
10+
{
1011
protected $description = 'Search through all log entries';
1112

1213
/**
@@ -16,34 +17,38 @@ class SearchLog extends ShowLog {
1617
'search' => '',
1718
];
1819

19-
public function __construct() {
20+
public function __construct()
21+
{
2022
// basically, we use the parent class and add an arugment
2123
parent::__construct();
2224
$this->addArgument('search', InputArgument::REQUIRED, 'Search term to be searched for in the logs.');
2325
$this->setName('log:search');
2426
}
2527

26-
public function handle() {
28+
public function handle()
29+
{
2730
// basically, we add the search term to the filter and then we let the parent function handle it normally
2831
$search = $this->argument('search');
2932
$this->filter['search'] = (string) (is_array($search) ? $search[0] : $search);
30-
$this->line('Running search via log:show for <bg=yellow>'.$this->filter['search'].'</>');
33+
$this->line('Running search via log:show for <bg=yellow>' . $this->filter['search'] . '</>');
3134
parent::handle();
3235

3336
return Command::SUCCESS;
3437
}
3538

36-
protected function addHighlightingToRecord(LogRecord $record): LogRecord {
39+
protected function addHighlightingToRecord(LogRecord $record): LogRecord
40+
{
3741
$message = preg_replace(
3842
[
39-
'/('.$this->filter['search'].')/i',
40-
'/\\\\<bg=yellow>('.$this->filter['search'].')<\/>/i', // the sequence \<bg=yellow> causes errors, even when everything is escaped like \\<...> (maybe a Symfony bug?)
43+
'/(' . $this->filter['search'] . ')/i',
44+
'/\\\\<bg=yellow>(' . $this->filter['search'] . ')<\/>/i', // the sequence \<bg=yellow> causes errors, even when everything is escaped like \\<...> (maybe a Symfony bug?)
4145
],
4246
[
4347
'<bg=yellow>$1</>',
4448
'<bg=yellow>\\\\$1</>', // solution to the issue above: include the backslash in the highlighting
4549
],
46-
$record['message']);
50+
$record['message']
51+
);
4752
$driver = $record->getDriver();
4853
$record = new LogRecord(
4954
$record['datetime'],
@@ -57,16 +62,18 @@ protected function addHighlightingToRecord(LogRecord $record): LogRecord {
5762
return $record;
5863
}
5964

60-
protected function printRecord(LogRecord $record): void {
65+
protected function printRecord(LogRecord $record): void
66+
{
6167
// simply add highlighting and then let the parent handle it
6268
$record = $this->addHighlightingToRecord($record);
6369
parent::printRecord($record);
6470
}
6571

66-
protected function printRecordSingleline(LogRecord $record): void {
72+
protected function printRecordSingleline(LogRecord $record): void
73+
{
6774
// same as print Record
6875
// simply add highlighting and then let the parent handle it
6976
$record = $this->addHighlightingToRecord($record);
7077
parent::printRecordSingleline($record);
7178
}
72-
}
79+
}

0 commit comments

Comments
 (0)