Skip to content

Commit b837248

Browse files
committed
Making undefined as constant
1 parent 66fbbe7 commit b837248

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Instrumentation/PDO/src/PDOInstrumentation.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class PDOInstrumentation
2222
{
2323
public const NAME = 'pdo';
24+
private const UNDEFINED = 'undefined';
2425

2526
public static function register(): void
2627
{
@@ -111,9 +112,9 @@ public static function register(): void
111112
/** @psalm-suppress ArgumentTypeCoercion */
112113
$builder = self::makeBuilder($instrumentation, 'PDO::query', $function, $class, $filename, $lineno)
113114
->setSpanKind(SpanKind::KIND_CLIENT);
114-
$sqlStatement = mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8');
115+
$sqlStatement = mb_convert_encoding($params[0] ?? self::UNDEFINED, 'UTF-8');
115116
if (!is_string($sqlStatement)) {
116-
$sqlStatement = 'undefined';
117+
$sqlStatement = self::UNDEFINED;
117118
}
118119
if ($class === PDO::class) {
119120
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, $sqlStatement);
@@ -125,7 +126,7 @@ public static function register(): void
125126
$span->setAttributes($attributes);
126127

127128
Context::storage()->attach($span->storeInContext($parent));
128-
if (self::isSqlCommenterEnabled() && $sqlStatement !== 'undefined') {
129+
if (self::isSqlCommenterEnabled() && $sqlStatement !== self::UNDEFINED) {
129130
$sqlStatement = self::appendSqlComments($sqlStatement, true);
130131
$span->setAttributes([
131132
TraceAttributes::DB_QUERY_TEXT => $sqlStatement,
@@ -150,9 +151,9 @@ public static function register(): void
150151
/** @psalm-suppress ArgumentTypeCoercion */
151152
$builder = self::makeBuilder($instrumentation, 'PDO::exec', $function, $class, $filename, $lineno)
152153
->setSpanKind(SpanKind::KIND_CLIENT);
153-
$sqlStatement = mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8');
154+
$sqlStatement = mb_convert_encoding($params[0] ?? self::UNDEFINED, 'UTF-8');
154155
if (!is_string($sqlStatement)) {
155-
$sqlStatement = 'undefined';
156+
$sqlStatement = self::UNDEFINED;
156157
}
157158
if ($class === PDO::class) {
158159
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, $sqlStatement);
@@ -164,7 +165,7 @@ public static function register(): void
164165
$span->setAttributes($attributes);
165166

166167
Context::storage()->attach($span->storeInContext($parent));
167-
if (self::isSqlCommenterEnabled() && $sqlStatement !== 'undefined') {
168+
if (self::isSqlCommenterEnabled() && $sqlStatement !== self::UNDEFINED) {
168169
$sqlStatement = self::appendSqlComments($sqlStatement, true);
169170
$span->setAttributes([
170171
TraceAttributes::DB_QUERY_TEXT => $sqlStatement,
@@ -189,9 +190,9 @@ public static function register(): void
189190
/** @psalm-suppress ArgumentTypeCoercion */
190191
$builder = self::makeBuilder($instrumentation, 'PDO::prepare', $function, $class, $filename, $lineno)
191192
->setSpanKind(SpanKind::KIND_CLIENT);
192-
$sqlStatement = mb_convert_encoding($params[0] ?? 'undefined', 'UTF-8');
193+
$sqlStatement = mb_convert_encoding($params[0] ?? self::UNDEFINED, 'UTF-8');
193194
if (!is_string($sqlStatement)) {
194-
$sqlStatement = 'undefined';
195+
$sqlStatement = self::UNDEFINED;
195196
}
196197
if ($class === PDO::class) {
197198
$builder->setAttribute(TraceAttributes::DB_QUERY_TEXT, $sqlStatement);
@@ -203,7 +204,7 @@ public static function register(): void
203204
$span->setAttributes($attributes);
204205

205206
Context::storage()->attach($span->storeInContext($parent));
206-
if (self::isSqlCommenterEnabled() && $sqlStatement !== 'undefined') {
207+
if (self::isSqlCommenterEnabled() && $sqlStatement !== self::UNDEFINED) {
207208
$sqlStatement = self::appendSqlComments($sqlStatement, false);
208209
$span->setAttributes([
209210
TraceAttributes::DB_QUERY_TEXT => $sqlStatement,

0 commit comments

Comments
 (0)