Skip to content

Upd. Contact encoder. Refactoring for the code duplication removing. - #5

Open
Glomberg wants to merge 8 commits into
masterfrom
Upd-Contact-encoder-Refacoring-for-the-code-duplication-removing-VI
Open

Upd. Contact encoder. Refactoring for the code duplication removing.#5
Glomberg wants to merge 8 commits into
masterfrom
Upd-Contact-encoder-Refacoring-for-the-code-duplication-removing-VI

Conversation

@Glomberg

Copy link
Copy Markdown
Member

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_capturing property and its corresponding test.
  • Consolidated modifyGlobalEmails() / modifyGlobalPhoneNumbers() logic by removing PHP 7.4+ “V2” implementations and version branches.
  • Updated ContactsEncoderHelper APIs to accept plain strings instead of PREG_OFFSET_CAPTURE match 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 thread ContactsEncoder.php
Comment on lines +315 to +319
if (
isset($matches[0]) && $this->helper->isEmailInLink($matches[0], $this->temp_content)
) {
return $matches[0];
}
Comment thread ContactsEncoder.php
Comment on lines +371 to 374
// check attribute exclusions
if ( $this->helper->hasAttributeExclusions($matches[0][0], $this->temp_content) ) {
return $matches[0];
}
Comment thread ContactsEncoder.php
Comment on lines 490 to 492
/**
* Method to process tel: links. For PHP < 7.4
*
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