Skip to content

Commit 4d0c283

Browse files
committed
tweak FileStreamWrapper behavior & small comment + use statements tweaks
1 parent 6cfad53 commit 4d0c283

7 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/Debug/LogEntry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function getChannelName()
153153
}
154154

155155
/**
156-
* Get meta value
156+
* Get meta value(s)
157157
*
158158
* @param string $key key to get
159159
* if not passed, return all meta values (no different than $logEntry['meta'])

src/Debug/Plugin/Method/Basic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class Basic implements SubscriberInterface
5656
*
5757
* @return Debug
5858
*
59-
* 2.0 Default message used if none passed
60-
* 2.3 Support for substitution & formatting
59+
* @since 2.0 Default message used if none passed
60+
* @since 2.3 Support for substitution & formatting
6161
*/
6262
public function assert($assertion, $msg = null)
6363
{

src/Debug/Utility/FileStreamWrapperBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FileStreamWrapperBase
2727
/** @var string */
2828
const OUTPUT_DESTINATION = 'php://memory';
2929
/** @var int */
30-
const STREAM_OPEN_FOR_INCLUDE = 128;
30+
const STREAM_OPEN_FOR_INCLUDE = 128; // STREAM_REPORT_ERRORS
3131

3232
/** @var resource|null The current context, or null if no context was passed to the caller function */
3333
public $context;
@@ -275,6 +275,6 @@ private static function registerProtocol($protocol)
275275
protected static function shouldTransform($file, $options)
276276
{
277277
$including = (bool) ($options & static::STREAM_OPEN_FOR_INCLUDE);
278-
return $including && static::isTargeted($file);
278+
return static::isTargeted($file) && ($including || \in_array($file, self::$filesTransformed, true));
279279
}
280280
}

src/Debug/Utility/Php.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace bdk\Debug\Utility;
1212

13+
use bdk\Debug\Utility\PhpType;
1314
use bdk\Debug\Utility\Reflection;
1415

1516
/**
@@ -60,7 +61,7 @@ public static function friendlyClassName($mixed)
6061
if ($reflector && \method_exists($reflector, 'getDeclaringClass')) {
6162
$reflector = $reflector->getDeclaringClass();
6263
}
63-
return \bdk\Debug\Utility\PhpType::getDebugTypeObject($reflector->getName());
64+
return PhpType::getDebugTypeObject($reflector->getName());
6465
}
6566

6667
/**
@@ -78,7 +79,7 @@ public static function friendlyClassName($mixed)
7879
*/
7980
public static function getDebugType($val)
8081
{
81-
return \bdk\Debug\Utility\PhpType::getDebugType($val);
82+
return PhpType::getDebugType($val);
8283
}
8384

8485
/**
@@ -130,7 +131,7 @@ public static function getIniFiles()
130131
*/
131132
public static function isCallable($val, $opts = 0)
132133
{
133-
return \bdk\Debug\Utility\PhpType::isCallable($val, $opts);
134+
return PhpType::isCallable($val, $opts);
134135
}
135136

136137
/**
@@ -142,7 +143,7 @@ public static function isCallable($val, $opts = 0)
142143
*/
143144
public static function isThrowable($val)
144145
{
145-
return \bdk\Debug\Utility\PhpType::isThrowable($val);
146+
return PhpType::isThrowable($val);
146147
}
147148

148149
/**

src/Debug/Utility/PhpType.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use UnitEnum;
1717

1818
/**
19-
* Php language utilities
19+
* Php type utilities
2020
*/
2121
class PhpType
2222
{
@@ -65,14 +65,16 @@ public static function assertType($value, $type, $paramName = null, $frameOffset
6565
* - 'callable' for callable array
6666
* - enum name for enum value
6767
*
68-
* @param mixed $val The value being type checked
68+
* @param mixed $val The value being type checked
69+
* @param bool $isObject Set to true if value is an object (but not Closure or UnitEnum)
6970
*
7071
* @return string
7172
*
7273
* @see https://github.com/symfony/polyfill/blob/main/src/Php80/Php80.php
7374
*/
74-
public static function getDebugType($val)
75+
public static function getDebugType($val, &$isObject = false)
7576
{
77+
$isObject = false;
7678
$type = \strtr(\strtolower(\gettype($val)), array(
7779
'boolean' => 'bool',
7880
'double' => 'float',
@@ -92,6 +94,7 @@ public static function getDebugType($val)
9294
case $val instanceof \__PHP_Incomplete_Class:
9395
return '__PHP_Incomplete_Class';
9496
case $type === 'object':
97+
$isObject = $val instanceof UnitEnum === false && $val instanceof \Closure === false;
9598
return self::getDebugTypeObject($val);
9699
default:
97100
return self::getDebugTypeResource($val);
@@ -101,7 +104,7 @@ public static function getDebugType($val)
101104
/**
102105
* Get friendly class name
103106
*
104-
* @param object $obj Object to inspect
107+
* @param object|class-string $obj Object to inspect
105108
*
106109
* @return string
107110
*/

src/Debug/Utility/Sql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static function parse($sql)
9191
DELETE.*?FROM\s+\S+|
9292
INSERT(?:\s+(?:LOW_PRIORITY|DELAYED|HIGH_PRIORITY|IGNORE|INTO))*\s+\S+|
9393
SELECT\s+(?P<select>.*?)\s+FROM\s+(?<from>\S+)|
94+
SET\s+.+|
9495
UPDATE\s+\S+
9596
)
9697
(?P<afterMethod>.*?)

tests/Backtrace/ContextTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use bdk\Backtrace;
66
use bdk\Backtrace\Normalizer;
7+
use bdk\PhpUnitPolyfill\AssertionTrait;
78
use PHPUnit\Framework\TestCase;
89

910
/**
@@ -14,6 +15,8 @@
1415
*/
1516
class ContextTest extends TestCase
1617
{
18+
use AssertionTrait;
19+
1720
public function testAddContext()
1821
{
1922
$line1 = __LINE__ + 2;
@@ -93,8 +96,8 @@ public function testAddContextXdebug()
9396
public function testGetFileLines()
9497
{
9598
self::assertFalse(Backtrace::getFileLines('/no/such/file.php'));
96-
self::assertSame(array(
97-
1 => "<?php\n",
98-
), Backtrace::getFileLines(__FILE__, 0, 1));
99+
$lines = Backtrace::getFileLines(__FILE__, 0, 1);
100+
self::assertCount(1, $lines);
101+
self::assertMatchesRegularExpression('/<\?php( declare\(ticks=1\);)?\n/', \implode("\n", $lines));
99102
}
100103
}

0 commit comments

Comments
 (0)