Code Duplication    Length = 18-21 lines in 2 locations

src/Placeholders/WhitespacePlaceholder.php 2 locations

@@ 81-98 (lines=18) @@
78
     *
79
     * @return string
80
     */
81
    protected function whitespaceInInlineElements($contents, PlaceholderContainer $placeholderContainer)
82
    {
83
        $elementsRegex = $this->getInlineElementsRegex();
84
85
        return preg_replace_callback(
86
            '/
87
                (
88
                    <('.$elementsRegex.')   # Match an inline element
89
                    (?:(?!<\/\2>).*)        # Match everything except its end tag
90
                    <\/\2>                  # Match the end tag
91
                    \s+
92
                )
93
                <('.$elementsRegex.')       # Match starting tag
94
            /xis',
95
            function ($match) use ($placeholderContainer) {
96
                return $this->replaceWhitespacesInInlineElements($match[1], $placeholderContainer).'<'.$match[3];
97
            }, $contents);
98
    }
99
100
    /**
101
     * Replace the whitespaces in inline elements with a placeholder.
@@ 51-71 (lines=21) @@
48
     *
49
     * @return string
50
     */
51
    protected function whitespaceBetweenInlineElements($contents, PlaceholderContainer $placeholderContainer)
52
    {
53
        $elementsRegex = $this->getInlineElementsRegex();
54
55
        return preg_replace_callback(
56
            '/
57
                (
58
                    <('.$elementsRegex.')       # Match the start tag and capture it
59
                    (?:(?!<\/\2>).*)            # Match everything without the end tag
60
                    <\/\2>                      # Match the captured elements end tag
61
                )
62
                \s+                             # Match minimal 1 whitespace between the elements
63
                <('.$elementsRegex.')           # Match the start of the next inline element
64
            /xi',
65
            function ($match) use ($placeholderContainer) {
66
                // Where going to respect one space between the inline elements.
67
                $placeholder = $placeholderContainer->createPlaceholder(' ');
68
69
                return $match[1].$placeholder.'<'.$match[3];
70
        }, $contents);
71
    }
72
73
    /**
74
     * Whitespaces in an inline element have a function so we replace it.