Skip to content

Commit

Permalink
chore: fixing CS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luislard committed Nov 28, 2023
1 parent 98a74fc commit 8281d3f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
},
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"cs:fix": "@php ./vendor/bin/phpcbf",
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-suggestions --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache",
"tests:unit": "@php ./vendor/phpunit/phpunit/phpunit --testsuite=unit",
"tests:unit:no-cov": "@php ./vendor/phpunit/phpunit/phpunit --testsuite=unit --no-coverage",
Expand Down
18 changes: 9 additions & 9 deletions tests/src/TestLogger/AbstractLoggerV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractLoggerV1 implements LoggerInterface
*
* @return void
*/
public function emergency($message, array $context = array())
public function emergency($message, array $context = [])
{
$this->log(LogLevel::EMERGENCY, $message, $context);
}
Expand All @@ -46,7 +46,7 @@ public function emergency($message, array $context = array())
*
* @return void
*/
public function alert($message, array $context = array())
public function alert($message, array $context = [])
{
$this->log(LogLevel::ALERT, $message, $context);
}
Expand All @@ -61,7 +61,7 @@ public function alert($message, array $context = array())
*
* @return void
*/
public function critical($message, array $context = array())
public function critical($message, array $context = [])
{
$this->log(LogLevel::CRITICAL, $message, $context);
}
Expand All @@ -75,7 +75,7 @@ public function critical($message, array $context = array())
*
* @return void
*/
public function error($message, array $context = array())
public function error($message, array $context = [])
{
$this->log(LogLevel::ERROR, $message, $context);
}
Expand All @@ -91,7 +91,7 @@ public function error($message, array $context = array())
*
* @return void
*/
public function warning($message, array $context = array())
public function warning($message, array $context = [])
{
$this->log(LogLevel::WARNING, $message, $context);
}
Expand All @@ -104,7 +104,7 @@ public function warning($message, array $context = array())
*
* @return void
*/
public function notice($message, array $context = array())
public function notice($message, array $context = [])
{
$this->log(LogLevel::NOTICE, $message, $context);
}
Expand All @@ -119,7 +119,7 @@ public function notice($message, array $context = array())
*
* @return void
*/
public function info($message, array $context = array())
public function info($message, array $context = [])
{
$this->log(LogLevel::INFO, $message, $context);
}
Expand All @@ -132,8 +132,8 @@ public function info($message, array $context = array())
*
* @return void
*/
public function debug($message, array $context = array())
public function debug($message, array $context = [])
{
$this->log(LogLevel::DEBUG, $message, $context);
}
}
}
29 changes: 21 additions & 8 deletions tests/src/TestLogger/TestLoggerV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ class TestLoggerV1 extends AbstractLoggerV1
/**
* @var array
*/
// phpcs:ignore Inpsyde.CodeQuality.ForbiddenPublicProperty.Found
public $records = [];

// phpcs:ignore Inpsyde.CodeQuality.ForbiddenPublicProperty.Found
public $recordsByLevel = [];

/**
Expand Down Expand Up @@ -101,7 +103,7 @@ public function hasRecord($record, $level)
if (is_string($record)) {
$record = ['message' => $record];
}
return $this->hasRecordThatPasses(function ($rec) use ($record) {
return $this->hasRecordThatPasses(static function ($rec) use ($record) {
if ($rec['message'] !== $record['message']) {
return false;
}
Expand All @@ -114,14 +116,14 @@ public function hasRecord($record, $level)

public function hasRecordThatContains($message, $level)
{
return $this->hasRecordThatPasses(function ($rec) use ($message) {
return $this->hasRecordThatPasses(static function ($rec) use ($message) {
return strpos($rec['message'], $message) !== false;
}, $level);
}

public function hasRecordThatMatches($regex, $level)
{
return $this->hasRecordThatPasses(function ($rec) use ($regex) {
return $this->hasRecordThatPasses(static function ($rec) use ($regex) {
return preg_match($regex, $rec['message']) > 0;
}, $level);
}
Expand All @@ -132,6 +134,7 @@ public function hasRecordThatPasses(callable $predicate, $level)
return false;
}
foreach ($this->recordsByLevel[$level] as $i => $rec) {
// phpcs:ignore NeutronStandard.Functions.DisallowCallUserFunc.CallUserFunc
if (call_user_func($predicate, $rec, $i)) {
return true;
}
Expand All @@ -141,21 +144,31 @@ public function hasRecordThatPasses(callable $predicate, $level)

public function __call($method, $args)
{
if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
$genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];
if (
preg_match(
'/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/',
$method,
$matches
) > 0
) {
$genericMethod = $matches[1]
. ('Records' !== $matches[3] ? 'Record' : '')
. $matches[3];
$level = strtolower($matches[2]);
if (method_exists($this, $genericMethod)) {
$args[] = $level;
// phpcs:ignore NeutronStandard.Functions.DisallowCallUserFunc.CallUserFunc
return call_user_func_array([$this, $genericMethod], $args);
}
}
throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
throw new \BadMethodCallException(
'Call to undefined method ' . get_class($this) . '::' . $method . '()'
);
}

public function reset()
{
$this->records = [];
$this->recordsByLevel = [];
}

}
}
8 changes: 6 additions & 2 deletions tests/src/TestLogger/TestLoggerV2V3.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class TestLoggerV2V3 implements LoggerInterface
{
use LoggerTrait;

// phpcs:ignore Inpsyde.CodeQuality.ForbiddenPublicProperty.Found, PHPCompatibility.Classes.NewTypedProperties.Found
public array $records = [];

// phpcs:ignore Inpsyde.CodeQuality.ForbiddenPublicProperty.Found, PHPCompatibility.Classes.NewTypedProperties.Found
public array $recordsByLevel = [];

/**
Expand Down Expand Up @@ -62,7 +65,7 @@ public function hasRecord($record, $level)
$record = ['message' => $record];
}

return $this->hasRecordThatPasses(function ($rec) use ($record) {
return $this->hasRecordThatPasses(static function ($rec) use ($record) {

Check warning on line 68 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Argument type is missing

Check warning on line 68 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Return type is missing

Check warning on line 68 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Argument type is missing

Check warning on line 68 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Return type is missing
if ($rec['message'] !== $record['message']) {
return false;
}
Expand Down Expand Up @@ -117,6 +120,7 @@ public function hasRecordThatPasses(callable $predicate, $level)
*/
public function __call($method, $args)
{
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@trigger_error(sprintf('Since psr/log-util 1.1: Method "%s" is deprecated and should not be called. Use method "%s" instead.', __FUNCTION__, $method), \E_USER_DEPRECATED);

Check warning on line 124 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Line 124 exceeds 100 characters; contains 180 characters.

Check warning on line 124 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Silencing errors is strongly discouraged. Use proper error checking instead. Found: @trigger_error(sprintf('Since psr/log-util 1.1: Method "%s" is deprecated and should not be called. Use method "%s" instead.'...

Check warning on line 124 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Line 124 exceeds 100 characters; contains 180 characters.

Check warning on line 124 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Silencing errors is strongly discouraged. Use proper error checking instead. Found: @trigger_error(sprintf('Since psr/log-util 1.1: Method "%s" is deprecated and should not be called. Use method "%s" instead.'...

if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {

Check warning on line 126 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Line 126 exceeds 100 characters; contains 121 characters.

Check warning on line 126 in tests/src/TestLogger/TestLoggerV2V3.php

View workflow job for this annotation

GitHub Actions / coding-standards-analysis-php / coding-standards-php

Line 126 exceeds 100 characters; contains 121 characters.
Expand Down Expand Up @@ -335,4 +339,4 @@ public function reset()
$this->records = [];
$this->recordsByLevel = [];
}
}
}

0 comments on commit 8281d3f

Please sign in to comment.