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
9 changes: 8 additions & 1 deletion src/TicketSwapErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function highlight(string $message, ?string $tip, ?string $identif

// Full Qualified Class Names
$message = (string) preg_replace(
"/([\\\]?[A-Z0-9]{1}[A-Za-z0-9_\-]+[\\\]+[A-Z0-9]{1}[A-Za-z0-9_\-\\\]+)/",
"/([\\\]?[A-Z0-9]{1}[A-Za-z0-9_\-]+[\\\]+[A-Z0-9]{1}[A-Za-z0-9_\-\\\]+(?:::[A-Za-z0-9_]+)?)/",
'<fg=yellow>$1</>',
$message,
);
Expand All @@ -247,6 +247,13 @@ public static function highlight(string $message, ?string $tip, ?string $identif
$message,
);

// Class reference (e.g. ClassName::CONSTANT, ClassName::class)
$message = (string) preg_replace(
'/(?<=[\s])([A-Z][A-Za-z0-9_]+::[A-Za-z0-9_]+)(?=[\.\s\|><,\(\)\{\}]|$)/',
'<fg=yellow>$1</>',
$message,
);

// Function
$message = (string) preg_replace(
'/(?<=function\s)(\w+)(?=\s)/',
Expand Down
23 changes: 22 additions & 1 deletion tests/TicketSwapErrorFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static function provideHighlight() : iterable
true
];
yield [
"Array has 3 duplicate keys with value '<fg=yellow>App\Activity</>' (<fg=yellow>\App\Activity</>::class).",
"Array has 3 duplicate keys with value '<fg=yellow>App\Activity</>' (<fg=yellow>\App\Activity::class</>).",
"Array has 3 duplicate keys with value 'App\Activity' (\App\Activity::class).",
null,
null,
Expand All @@ -282,6 +282,27 @@ public static function provideHighlight() : iterable
null,
true,
];
yield [
'Something <fg=yellow>CommandHandlersHaveSerializableCommandFunctionalTest::SKIPPED</>.',
'Something CommandHandlersHaveSerializableCommandFunctionalTest::SKIPPED.',
null,
null,
true,
];
yield [
'Constant <fg=yellow>App\Models\ExampleModel::SOME_CONSTANT</> is never used.',
'Constant App\Models\ExampleModel::SOME_CONSTANT is never used.',
null,
null,
true,
];
yield [
'Case <fg=yellow>App\Enum\Status::Active</> not handled.',
'Case App\Enum\Status::Active not handled.',
null,
null,
true,
];
}

/**
Expand Down