diff --git a/src/config/filters/HereNowdoc.xml b/src/config/filters/HereNowdoc.xml new file mode 100644 index 0000000..18b3e47 --- /dev/null +++ b/src/config/filters/HereNowdoc.xml @@ -0,0 +1,20 @@ + + + + + + + + + + 1 + + + + + + diff --git a/src/lib/PreCommit/Filter/HereNowdoc.php b/src/lib/PreCommit/Filter/HereNowdoc.php new file mode 100644 index 0000000..a3e2cf5 --- /dev/null +++ b/src/lib/PreCommit/Filter/HereNowdoc.php @@ -0,0 +1,66 @@ +findTextBlockTags($content) as $tag) { + $content = $this->cut($tag, $content); + } + + return $content; + } + + /** + * Cut text code block + * + * @param string $tag + * @param string $content + * @return string + */ + protected function cut($tag, $content) + { + return preg_replace( + '/(=[ ]*)<<<[\'"]?'.$tag.'[\'"]?\r?\n(\r|\n|.)*?'.$tag.';/', + '$1\'\'; //replaced code because skipped validation', + $content + ); + } + + /** + * Find text block tags + * + * @param string $content + * @return array + */ + protected function findTextBlockTags($content) + { + //find blocks + preg_match_all('/=[ ]*<<<[\'"]?([A-z0-9]+)[\'"]?\r?\n/', $content, $matches); + + return empty($matches[1]) ? [] : array_unique($matches[1]); + } +}