Upd. Contact encoder. Refactoring for the code duplication removing. - #5
Open
Glomberg wants to merge 8 commits into
Open
Conversation
…balPhoneNumbers`.
…balPhoneNumbers`.
…ern_without_capturing` removed.
There was a problem hiding this comment.
Pull request overview
This PR refactors the ContactsEncoder implementation to reduce duplicated logic, primarily by removing PHP-version-specific branches and simplifying how match context is handled during global email/phone replacements.
Changes:
- Removed the unused
plain_email_pattern_without_capturingproperty and its corresponding test. - Consolidated
modifyGlobalEmails()/modifyGlobalPhoneNumbers()logic by removing PHP 7.4+ “V2” implementations and version branches. - Updated
ContactsEncoderHelperAPIs to accept plain strings instead ofPREG_OFFSET_CAPTUREmatch arrays.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
ContactsEncoder.php |
Removes version-specific callback branches and V2 link encoders; centralizes email/phone replacement logic. |
Helper/ContactsEncoderHelper.php |
Changes helper method signatures to accept email strings and uses strpos() to find positions. |
tests/ContactsEncoder/TestContactsEncoderPatterns.php |
Removes the test for the deleted regex property. |
Suppressed comments (1)
ContactsEncoder.php:378
isInsideScriptTag()is called with$matches[0][0], which is only the first character of the matched phone string. This makes the script-tag containment check unreliable.
// check if in script
if ( $this->helper->isInsideScriptTag($matches[0][0], $this->temp_content) ) {
return $matches[0];
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+315
to
+319
| if ( | ||
| isset($matches[0]) && $this->helper->isEmailInLink($matches[0], $this->temp_content) | ||
| ) { | ||
| return $matches[0]; | ||
| } |
Comment on lines
+371
to
374
| // check attribute exclusions | ||
| if ( $this->helper->hasAttributeExclusions($matches[0][0], $this->temp_content) ) { | ||
| return $matches[0]; | ||
| } |
Comment on lines
490
to
492
| /** | ||
| * Method to process tel: links. For PHP < 7.4 | ||
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://app.doboard.com/1/task/41418