Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths:
- 'config/**'
- 'src/**'
- 'tests/**'
- '.github/workflows/rector-cs.yml'
- 'composer.json'
- 'rector.php'
- '.php-cs-fixer.dist.php'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
php: '8.0'
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ phpunit.phar
/phpunit.xml
# local phpunit cache
.phpunit.result.cache

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

$finder = (new Finder())->in([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return ConfigBuilder::build()
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Enh #132: Add benchmarks, improve performance of `Message::parse()` (@samdark)
- Bug #130: Updated `Message::parse()` to correctly support multiple placeholders (@technicated)
- Chg #130, #133: Changed `Message::parse()` to conform to PSR-3 (@technicated, @vjik)
- Enh #137: Explicitly import classes, functions, and constants in "use" section (@mspirkov)

## 2.2.0 December 13, 2025

Expand Down
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
"yiisoft/var-dumper": "^1.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"bamarni/composer-bin-plugin": "^1.8.3",
"friendsofphp/php-cs-fixer": "^3.93",
"phpbench/phpbench": "^1.0",
"phpunit/phpunit": "^9.6.23",
"rector/rector": "^2.0.17",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23.6",
"vimeo/psalm": "^4.30 || ^5.26.1 || ^6.12"
"vimeo/psalm": "^4.30 || ^5.26.1 || ^6.12",
"yiisoft/code-style": "^1.0"
},
"provide": {
"psr/log-implementation": "1.0.0"
Expand All @@ -66,6 +68,11 @@
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true,
"target-directory": "tools"
},
"config-plugin-options": {
"source-directory": "config"
},
Expand All @@ -77,13 +84,15 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
}
},
"scripts": {
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch",
"bench": "phpbench run --report=default"
"bench": "phpbench run --report=default",
"cs-fix": "php-cs-fixer fix"
}
}
3 changes: 1 addition & 2 deletions src/ContextProvider/CommonContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class CommonContextProvider implements ContextProviderInterface
{
public function __construct(
private array $data,
) {
}
) {}

public function getContext(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/ContextProvider/CompositeContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class CompositeContextProvider implements ContextProviderInterface
private array $providers;

public function __construct(
ContextProviderInterface ...$providers
ContextProviderInterface ...$providers,
) {
$this->providers = $providers;
}
Expand Down
11 changes: 8 additions & 3 deletions src/ContextProvider/SystemContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use InvalidArgumentException;
use Yiisoft\Log\Message;

use function is_string;
use function sprintf;

use const DEBUG_BACKTRACE_IGNORE_ARGS;

/**
* @psalm-import-type TraceItem from Message
*/
Expand All @@ -25,7 +30,7 @@
* with {@see $traceLevel}.
*/
public function __construct(
private int $traceLevel = 0,

Check warning on line 33 in src/ContextProvider/SystemContextProvider.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * with {@see $traceLevel}. */ public function __construct( - private int $traceLevel = 0, + private int $traceLevel = -1, array $excludedTracePaths = [], ) { /** @psalm-suppress DeprecatedMethod `setExcludedTracePaths` will be private and not deprecated */
array $excludedTracePaths = [],
) {
/** @psalm-suppress DeprecatedMethod `setExcludedTracePaths` will be private and not deprecated */
Expand All @@ -37,7 +42,7 @@
/** @psalm-var list<TraceItem> $trace */
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
array_shift($trace);
return [

Check warning on line 45 in src/ContextProvider/SystemContextProvider.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); array_shift($trace); return [ - 'time' => microtime(true), 'trace' => $this->collectTrace($trace), 'memory' => memory_get_usage(), 'category' => Message::DEFAULT_CATEGORY,
'time' => microtime(true),
'trace' => $this->collectTrace($trace),
'memory' => memory_get_usage(),
Expand Down Expand Up @@ -79,8 +84,8 @@
throw new InvalidArgumentException(
sprintf(
'The trace path must be a string, %s received.',
get_debug_type($excludedTracePath)
)
get_debug_type($excludedTracePath),
),
);
}
}
Expand All @@ -107,9 +112,9 @@

foreach ($backtrace as $trace) {
if (isset($trace['file'], $trace['line'])) {
$excludedMatch = array_filter(

Check warning on line 115 in src/ContextProvider/SystemContextProvider.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayFilter": @@ @@ foreach ($backtrace as $trace) { if (isset($trace['file'], $trace['line'])) { - $excludedMatch = array_filter( - $this->excludedTracePaths, - static fn($path) => str_contains($trace['file'], $path), - ); + $excludedMatch = $this->excludedTracePaths; if (empty($excludedMatch)) { $traces[] = $trace;
$this->excludedTracePaths,
static fn($path) => str_contains($trace['file'], $path)
static fn($path) => str_contains($trace['file'], $path),
);

if (empty($excludedMatch)) {
Expand Down
20 changes: 10 additions & 10 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
private array $messages = [];

/**
* @var Target[] the log targets. Each array element represents a single {@see \Yiisoft\Log\Target} instance.
* @var Target[] the log targets. Each array element represents a single {@see Target} instance.
*/
private array $targets = [];

Expand Down Expand Up @@ -88,7 +88,7 @@
$this->setTargets($targets);
$this->contextProvider = $contextProvider ?? new SystemContextProvider();

register_shutdown_function(function () {

Check warning on line 91 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ $this->setTargets($targets); $this->contextProvider = $contextProvider ?? new SystemContextProvider(); - register_shutdown_function(function () { - // make regular flush before other shutdown functions, which allows session data collection and so on - $this->flush(); - // make sure log entries written by shutdown functions are also flushed - // ensure "flush()" is called last when there are multiple shutdown functions - register_shutdown_function([$this, 'flush'], true); - }); + } /**
// make regular flush before other shutdown functions, which allows session data collection and so on
$this->flush();
// make sure log entries written by shutdown functions are also flushed
Expand All @@ -112,23 +112,23 @@
if (!is_string($level)) {
throw new \Psr\Log\InvalidArgumentException(sprintf(
'The log message level must be a string, %s provided.',
get_debug_type($level)
get_debug_type($level),
));
}

if (!in_array($level, self::LEVELS, true)) {
throw new \Psr\Log\InvalidArgumentException(sprintf(
'Invalid log message level "%s" provided. The following values are supported: "%s".',
$level,
implode('", "', self::LEVELS)
implode('", "', self::LEVELS),
));
}

return $level;
}

/**
* @return Target[] The log targets. Each array element represents a single {@see \Yiisoft\Log\Target} instance.
* @return Target[] The log targets. Each array element represents a single {@see Target} instance.
*/
public function getTargets(): array
{
Expand All @@ -145,7 +145,7 @@
array_merge($this->contextProvider->getContext(), $context),
);

if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) {

Check warning on line 148 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": @@ @@ array_merge($this->contextProvider->getContext(), $context), ); - if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) { + if ($this->flushInterval >= 0 && count($this->messages) >= $this->flushInterval) { $this->flush(); } }
$this->flush();
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@
{
if (!$this->contextProvider instanceof SystemContextProvider) {
throw new RuntimeException(
'"Logger::setTraceLevel()" is unavailable when using a custom context provider.'
'"Logger::setTraceLevel()" is unavailable when using a custom context provider.',
);
}
/** @psalm-suppress DeprecatedMethod */
Expand All @@ -212,7 +212,7 @@
{
if (!$this->contextProvider instanceof SystemContextProvider) {
throw new RuntimeException(
'"Logger::setExcludedTracePaths()" is unavailable when using a custom context provider.'
'"Logger::setExcludedTracePaths()" is unavailable when using a custom context provider.',
);
}
/** @psalm-suppress DeprecatedMethod */
Expand All @@ -230,7 +230,7 @@
public static function assertLevelIsValid(mixed $level): void
{
self::assertLevelIsString($level);
self::assertLevelIsSupported($level);

Check warning on line 233 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ public static function assertLevelIsValid(mixed $level): void { self::assertLevelIsString($level); - self::assertLevelIsSupported($level); + } /**
}

/**
Expand All @@ -242,14 +242,14 @@
*
* @psalm-assert string $level
*/
public static function assertLevelIsString(mixed $level): void

Check warning on line 245 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "PublicVisibility": @@ @@ * * @psalm-assert string $level */ - public static function assertLevelIsString(mixed $level): void + protected static function assertLevelIsString(mixed $level): void { if (is_string($level)) { return;
{
if (is_string($level)) {
return;
}

throw new \Psr\Log\InvalidArgumentException(
sprintf('The log message level must be a string, %s provided.', get_debug_type($level))
sprintf('The log message level must be a string, %s provided.', get_debug_type($level)),
);
}

Expand All @@ -270,15 +270,15 @@
sprintf(
'Invalid log message level "%s" provided. The following values are supported: "%s".',
$level,
implode('", "', self::LEVELS)
)
implode('", "', self::LEVELS),
),
);
}

/**
* Sets a target to {@see Logger::$targets}.
*
* @param Target[] $targets The log targets. Each array element represents a single {@see \Yiisoft\Log\Target}
* @param Target[] $targets The log targets. Each array element represents a single {@see Target}
* instance or the configuration for creating the log target instance.
*
* @throws InvalidArgumentException for non-instance Target.
Expand Down
8 changes: 6 additions & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
use Yiisoft\VarDumper\VarDumper;

use function preg_replace_callback;
use function is_float;
use function is_int;
use function is_scalar;
use function is_string;

/**
* Message is a data object that stores log message data.
Expand Down Expand Up @@ -129,7 +133,7 @@ public function category(): string
$category = $this->context['category'] ?? self::DEFAULT_CATEGORY;
if (!is_string($category)) {
throw new LogicException(
'Invalid category value in log context. Expected "string", got "' . get_debug_type($category) . '".'
'Invalid category value in log context. Expected "string", got "' . get_debug_type($category) . '".',
);
}
return $category;
Expand Down Expand Up @@ -227,7 +231,7 @@ static function (array $matches) use ($context) {
}
return $matches[0];
},
$message
$message,
);
}
}
2 changes: 1 addition & 1 deletion src/Message/CategoryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function checkStructure(array $categories): void
if (!is_string($category)) {
throw new InvalidArgumentException(sprintf(
'The log message category must be a string, %s received.',
get_debug_type($category)
get_debug_type($category),
));
}
}
Expand Down
Loading