Skip to content

Simplify ScreenshotHelper::slugifyUrl()#69

Open
stloyd wants to merge 1 commit intoplaywright-php:mainfrom
stloyd:chore/screenshoot-url
Open

Simplify ScreenshotHelper::slugifyUrl()#69
stloyd wants to merge 1 commit intoplaywright-php:mainfrom
stloyd:chore/screenshoot-url

Conversation

@stloyd
Copy link
Contributor

@stloyd stloyd commented Feb 16, 2026

No description provided.

@stloyd
Copy link
Contributor Author

stloyd commented Feb 16, 2026

I'm concerned it might be better to use Symfony String instead of this implementation.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

if (is_string($slug)) {
$slug = preg_replace('/^www\./', '', $slug);
}
$slug = preg_replace('#^(https?://)?(www\.)?#i', '', $url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about :

Suggested change
$slug = preg_replace('#^(https?://)?(www\.)?#i', '', $url);
$slug = preg_replace(
['#^(https?://)?(www\.)?#i', '/[^a-z0-9]+/i'],
['', '-'],
trim($url)
);
$slug = strtolower(trim($slug ?? '', '-'));
$slug = substr($slug, 0, $maxLength);
$slug = rtrim($slug, '-');
return $slug !== '' ? $slug : 'screenshot';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's simpler, but it removes the behaviour with "invalid-url" fallback

@smnandre
Copy link
Member

I'm concerned it might be better to use Symfony String instead of this implementation.

@stloyd I was going to say "I'd like to minimize the dependencies used here" ... but i'm realizing symfony/string is a dependency of symfony/console so... why not indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants