Skip to content

Simplify ScreenshotHelper::slugifyUrl()#69

Merged
smnandre merged 1 commit intoplaywright-php:mainfrom
stloyd:chore/screenshoot-url
Feb 25, 2026
Merged

Simplify ScreenshotHelper::slugifyUrl()#69
smnandre merged 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

@smnandre smnandre merged commit d66df8c into playwright-php:main Feb 25, 2026
11 checks passed
@stloyd stloyd deleted the chore/screenshoot-url branch February 25, 2026 20:18
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