Skip to content

Commit

Permalink
Update strings package (#226)
Browse files Browse the repository at this point in the history
* Update strings package

* Fix check

* Fix tests

* Fix tests

* Add example doc
  • Loading branch information
xepozz committed Oct 8, 2023
1 parent e16d64d commit 7557311
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -38,7 +38,7 @@
"yiisoft/json": "^1.0",
"yiisoft/profiler": "^3.0",
"yiisoft/proxy": "^1.0.1",
"yiisoft/strings": "^2.0",
"yiisoft/strings": "^2.2",
"yiisoft/var-dumper": "^1.0"
},
"require-dev": {
Expand Down
8 changes: 7 additions & 1 deletion config/di.php
Expand Up @@ -58,7 +58,13 @@
},
FilesystemStreamCollector::class => [
'__construct()' => [
'ignoredPathPatterns' => [],
'ignoredPathPatterns' => [
/**
* Examples:
* - templates/
* - src/Directory/To/Ignore
*/
],
'ignoredClasses' => [
ClosureExporter::class,
UseStatementParser::class,
Expand Down
2 changes: 2 additions & 0 deletions src/Collector/Stream/FilesystemStreamProxy.php
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\Debug\Collector\Stream;

use Yiisoft\Strings\CombinedRegexp;
use Yiisoft\Yii\Debug\Helper\BacktraceIgnoreMatcher;
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapper;
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapperInterface;
Expand Down Expand Up @@ -67,6 +68,7 @@ public static function register(): void
*/
class_exists(BacktraceIgnoreMatcher::class);
class_exists(StreamWrapper::class);
class_exists(CombinedRegexp::class);
stream_wrapper_unregister('file');
stream_wrapper_register('file', self::class, STREAM_IS_URL);
self::$registered = true;
Expand Down
2 changes: 2 additions & 0 deletions src/Collector/Stream/HttpStreamProxy.php
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\Debug\Collector\Stream;

use Yiisoft\Strings\CombinedRegexp;
use Yiisoft\Yii\Debug\Helper\BacktraceIgnoreMatcher;
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapper;
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapperInterface;
Expand Down Expand Up @@ -68,6 +69,7 @@ public static function register(): void
*/
class_exists(BacktraceIgnoreMatcher::class);
class_exists(StreamWrapper::class);
class_exists(CombinedRegexp::class);
stream_wrapper_unregister('http');
stream_wrapper_register('http', self::class, STREAM_IS_URL);
stream_wrapper_unregister('https');
Expand Down
10 changes: 5 additions & 5 deletions src/Helper/BacktraceIgnoreMatcher.php
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Yii\Debug\Helper;

use Yiisoft\Strings\CombinedRegexp;

/**
* All backtrace parameters should contain at least 4 elements in the following order:
* 0 – Called method
Expand All @@ -30,11 +32,9 @@ public static function isIgnoredByClass(array $backtrace, array $classes): bool

public static function doesStringMatchPattern(string $string, array $patterns): bool
{
foreach ($patterns as $ignoredPathPattern) {
if (preg_match($ignoredPathPattern, $string) > 0) {
return true;
}
if (empty($patterns)) {
return false;
}
return false;
return (new CombinedRegexp($patterns))->matches($string);
}
}
10 changes: 5 additions & 5 deletions tests/Unit/Collector/FilesystemStreamCollectorTest.php
Expand Up @@ -92,7 +92,7 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
yield 'mkdir ignored by path' => [
$path,
$mkdirBefore,
['/' . basename(__FILE__, '.php') . '/'],
[basename(__FILE__, '.php')],
[],
$mkdirOperation,
$mkdirAfter,
Expand Down Expand Up @@ -139,7 +139,7 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
yield 'rename ignored by path' => [
$path,
$renameBefore,
['/' . basename(__FILE__, '.php') . '/'],
[ basename(__FILE__, '.php') ],
[],
$renameOperation,
$renameAfter,
Expand Down Expand Up @@ -185,7 +185,7 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
yield 'rmdir ignored by path' => [
$path,
$rmdirBefore,
['/' . basename(__FILE__, '.php') . '/'],
[basename(__FILE__, '.php')],
[],
$rmdirOperation,
$rmdirAfter,
Expand Down Expand Up @@ -232,7 +232,7 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
yield 'unlink ignored by path' => [
$path,
$unlinkBefore,
['/' . basename(__FILE__, '.php') . '/'],
[basename(__FILE__, '.php')],
[],
$unlinkOperation,
$unlinkAfter,
Expand Down Expand Up @@ -291,7 +291,7 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
yield 'file stream ignored by path' => [
$path,
$fileStreamBefore,
['/' . basename(__FILE__, '.php') . '/'],
[basename(__FILE__, '.php')],
[],
$fileStreamOperation,
$fileStreamAfter,
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Collector/HttpStreamCollectorTest.php
Expand Up @@ -108,7 +108,7 @@ function (string $url, array $collected) {
yield 'file stream ignored by path' => [
$url,
$httpStreamBefore,
['/' . basename(__FILE__, '.php') . '/'],
[basename(__FILE__, '.php')],
[],
[],
$httpStreamOperation,
Expand All @@ -130,7 +130,7 @@ function (string $url, array $collected) {
$httpStreamBefore,
[],
[],
['/example/'],
['example'],
$httpStreamOperation,
$httpStreamAfter,
[],
Expand Down

0 comments on commit 7557311

Please sign in to comment.