Skip to content

Commit 1ca4b29

Browse files
committed
Update CI to enforce PSR12
1 parent 510beaa commit 1ca4b29

File tree

11 files changed

+199
-101
lines changed

11 files changed

+199
-101
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
3232
- name: Install dependencies
3333
run: composer install --prefer-dist --no-progress
34+
35+
- name: PHP Lint
36+
run: vendor/bin/phpcs --standard=PSR12 -n src
3437

3538
- name: PHPUnit tests
3639
run: vendor/bin/phpunit tests

.gitlab-ci.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
# Select image from https://hub.docker.com/_/php
2-
image: thomasschaller/php-test:8.1
1+
default:
2+
image: serversideup/php:8.1-cli
3+
4+
stages:
5+
- test
36

4-
# cache vendor files for increased performance
57
cache:
68
paths:
7-
- vendor/
8-
9-
before_script:
10-
# Install dependencies
11-
# - bash ci/docker_install.sh > /dev/null
12-
- composer install
9+
- vendor/
1310

14-
phpunit:
11+
test_phpunit:
12+
stage: test
1513
script:
14+
- composer install
1615
- vendor/bin/phpunit tests
1716

18-
phpstan:
17+
test_quality:
18+
stage: test
1919
script:
20-
- vendor/bin/phpstan analyze src --level=9
20+
- composer install
21+
- vendor/bin/phpcs --standard=PSR12 -n src
22+
- vendor/bin/phpstan analyse src --level=9

captainhook.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"pre-commit": {
33
"enabled": true,
44
"actions": [
5+
{
6+
"action": "vendor/bin/phpcbf --standard=PSR12 src",
7+
"options": []
8+
},
59
{
610
"action": "vendor/bin/phpunit tests",
711
"options": []

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"phpunit/phpunit": "^10",
2727
"monolog/monolog": "2.*",
2828
"phpstan/phpstan": "^1.10",
29-
"captainhook/captainhook": "^5.16"
29+
"captainhook/captainhook": "^5.16",
30+
"squizlabs/php_codesniffer": "^3.7"
3031
}
3132
}

composer.lock

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Exceptions/FileNotFoundException.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Devdot\Monolog\Exceptions;
44

5-
class FileNotFoundException extends \Exception {
6-
public function __construct(string $filename) {
5+
class FileNotFoundException extends \Exception
6+
{
7+
public function __construct(string $filename)
8+
{
79
parent::__construct(
8-
'File not found: '.$filename,
10+
'File not found: ' . $filename,
911
);
1012
}
1113
}

src/Exceptions/LogParsingException.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Devdot\Monolog\Exceptions;
44

5-
class LogParsingException extends \Exception {
6-
public function __construct(string $filename, string $extra = null) {
5+
class LogParsingException extends \Exception
6+
{
7+
public function __construct(string $filename, string $extra = null)
8+
{
79
parent::__construct(
8-
'Failed to parse '.$filename.($extra ? PHP_EOL.$extra : '')
10+
'Failed to parse ' . $filename . ($extra ? PHP_EOL . $extra : '')
911
);
1012
}
1113
}

src/Exceptions/ParserNotReadyException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Devdot\Monolog\Exceptions;
44

5-
class ParserNotReadyException extends \Exception {
6-
public function __construct() {
5+
class ParserNotReadyException extends \Exception
6+
{
7+
public function __construct()
8+
{
79
parent::__construct(
810
'Parser is not ready!'
911
);

src/Log.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
* @author Thomas Kuschan
1010
* @copyright (c) 2023
1111
*/
12-
class Log extends \ArrayIterator implements \ArrayAccess {
12+
class Log extends \ArrayIterator implements \ArrayAccess
13+
{
1314
/**
1415
* Create a Log from a group of records
1516
* @param LogRecord ...$records One or more log entries
1617
* @no-named-arguments This will disallow named parameters and force $records to array<int, LogRecord>
1718
*/
18-
public function __construct(LogRecord ...$records) {
19+
public function __construct(LogRecord ...$records)
20+
{
1921
parent::__construct($records);
2022
}
2123

@@ -24,9 +26,11 @@ public function __construct(LogRecord ...$records) {
2426
* @param bool $ascending Sorting order, defaults to false (meaning it sorts descending)
2527
* @return void
2628
*/
27-
public function sortByDatetime(bool $ascending = false): void {
28-
if (count($this) == 0)
29+
public function sortByDatetime(bool $ascending = false): void
30+
{
31+
if (count($this) == 0) {
2932
return;
33+
}
3034

3135
// get the stored elements and rebuild the log
3236
$array = $this->getArrayCopy();
@@ -39,12 +43,13 @@ public function sortByDatetime(bool $ascending = false): void {
3943
if ($ascending) {
4044
$array = array_reverse($array);
4145
}
42-
46+
4347
// finally set this array as the new content for us
4448
parent::__construct($array);
4549
}
4650

47-
public function current(): LogRecord {
51+
public function current(): LogRecord
52+
{
4853
return parent::current();
4954
}
5055

@@ -54,14 +59,16 @@ public function current(): LogRecord {
5459
* @throws \OutOfBoundsException When the offset is not defined
5560
* @return LogRecord
5661
*/
57-
public function offsetGet(mixed $offset): LogRecord {
58-
if(parent::offsetExists($offset)) {
62+
public function offsetGet(mixed $offset): LogRecord
63+
{
64+
if (parent::offsetExists($offset)) {
5965
$offset = parent::offsetGet($offset);
60-
if ($offset !== null)
66+
if ($offset !== null) {
6167
return $offset;
68+
}
6269
}
6370
// exit with exception
64-
throw new \OutOfBoundsException('Undefined array key '.$offset);
71+
throw new \OutOfBoundsException('Undefined array key ' . $offset);
6572
}
6673

6774
/**
@@ -71,7 +78,8 @@ public function offsetGet(mixed $offset): LogRecord {
7178
* @throws \LogicException Always
7279
* @return void
7380
*/
74-
public function offsetSet(mixed $offset, mixed $value): void {
81+
public function offsetSet(mixed $offset, mixed $value): void
82+
{
7583
// we do not support setting in any way
7684
throw new \LogicException('Unsupported operation');
7785
}
@@ -82,7 +90,8 @@ public function offsetSet(mixed $offset, mixed $value): void {
8290
* @throws \LogicException Always
8391
* @return void
8492
*/
85-
public function offsetUnset(mixed $offset): void {
93+
public function offsetUnset(mixed $offset): void
94+
{
8695
throw new \LogicException('Unsupported operation');
8796
}
8897
}

src/LogRecord.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* @author Thomas Kuschan
99
* @copyright (c) 2023
1010
*/
11-
class LogRecord implements \ArrayAccess {
11+
class LogRecord implements \ArrayAccess
12+
{
1213
/**
1314
* Create a LogRecord to hold a single log entry.
1415
* @param \DateTimeImmutable $datetime
@@ -23,27 +24,31 @@ public function __construct(
2324
public readonly string $channel,
2425
public readonly string $level,
2526
public readonly string $message,
26-
public readonly array|\stdClass|string|NULL $context = [],
27-
public readonly array|\stdClass|string|NULL $extra = [],
27+
public readonly array|\stdClass|string|null $context = [],
28+
public readonly array|\stdClass|string|null $extra = [],
2829
) {
2930
}
3031

31-
public function offsetSet(mixed $offset, mixed $value): void {
32+
public function offsetSet(mixed $offset, mixed $value): void
33+
{
3234
// we do not support setting in any way
3335
throw new \LogicException('Unsupported operation');
3436
}
3537

36-
public function &offsetGet(mixed $offset): mixed {
38+
public function &offsetGet(mixed $offset): mixed
39+
{
3740
// avoid returning readonly props by ref as this is illegal
3841
$copy = $this->{$offset};
3942
return $copy;
4043
}
4144

42-
public function offsetExists(mixed $offset): bool {
45+
public function offsetExists(mixed $offset): bool
46+
{
4347
return isset($this->{$offset});
4448
}
4549

46-
public function offsetUnset(mixed $offset): void {
50+
public function offsetUnset(mixed $offset): void
51+
{
4752
throw new \LogicException('Unsupported operation');
4853
}
4954
}

0 commit comments

Comments
 (0)