diff --git a/src/sbp/sbp.php b/src/sbp/sbp.php index ecd48b7..8af9ba6 100644 --- a/src/sbp/sbp.php +++ b/src/sbp/sbp.php @@ -191,6 +191,10 @@ static public function replaceString($match) { $GLOBALS['commentStrings'][] = $id; } + elseif(strpos($match[0], '?') === 0) + { + $GLOBALS['htmlCodes'][] = $id; + } else { $GLOBALS['quotedStrings'][] = $id; @@ -321,28 +325,58 @@ static protected function replace($content, $replace) static public function parse($content) { $GLOBALS['replaceStrings'] = array(); + $GLOBALS['htmlCodes'] = array(); $GLOBALS['quotedStrings'] = array(); $GLOBALS['commentStrings'] = array(); - $content = static::replace($content, array( - self::SUBST => self::SUBST.self::SUBST, - '#<\?(?!php)#' => ''. + $content, array( - /***********/ - /* PHPUnit */ - /***********/ - '#^(\s*)(.+\s)?should\s+not\s(.+);\s*$#m' + + /***************************/ + /* Complete PHP shrot-tags */ + /***************************/ + '#<\?(?!php)#' + => '<\?php#' + => '', + + + /*******************************/ + /* Escape the escape-character */ + /*******************************/ + self::SUBST + => self::SUBST.self::SUBST, + + + /*************************************************************/ + /* Save the comments, quoted string and HTML out of PHP tags */ + /*************************************************************/ + '#'.self::COMMENTS.'|'.self::stringRegex().'|\?>.+<\?php#sU' + => array(get_class(), 'replaceString'), + + + /*************************************/ + /* should key-word fo PHPUnit assert */ + /*************************************/ + '#^(\s*)(\S.*\s)?should\s+not\s(.*[^;]);*\s*$#mU' => function ($match) { list($all, $spaces, $before, $after) = $match; return $spaces . '>assertFalse(' . $before . preg_replace('#(? function ($match) { list($all, $spaces, $before, $after) = $match; @@ -350,7 +384,6 @@ static public function parse($content) }, )); - $content = preg_replace_callback('#'.self::COMMENTS.'|'.self::stringRegex().'|\?'.'>.*<\?php#sU', array(get_class(), 'replaceString'), $content); $validSubst = self::validSubst('(?:'.implode('|', $GLOBALS['quotedStrings']).')'); $validComments = self::validSubst('(?:'.implode('|', $GLOBALS['commentStrings']).')'); @@ -363,12 +396,8 @@ static public function parse($content) $__file = var_export($__file, true); $__dir = var_export($__dir, true); - if(!$count) - { - $content = ''.$content; - } - $content = static::replace($content, array( + /*********/ /* Class */ /*********/ @@ -427,9 +456,9 @@ static public function parse($content) => $__dir, - /**************/ - /* Constantes */ - /**************/ + /*************/ + /* Constants */ + /*************/ '#'.self::START.'('.self::CONSTNAME.')\s*=#' => '$1const $2 =', @@ -442,6 +471,10 @@ static public function parse($content) '#([\(;\s\.+/*=]):('.self::CONSTNAME.')#' => '$1static::$2', + + /*************/ + /* Functions */ + /*************/ '#'.self::START.'<(?![\?=])#' => '$1return ', @@ -454,13 +487,17 @@ static public function parse($content) '#(? 'function $1', + + /****************/ + /* > to $this-> */ + /****************/ '#([\(;\s\.+/*:+\/\*\?\&\|\!\^\~]\s*|return(?:\(\s*|\s+)|[=-]\s+)>(\$?'.self::VALIDNAME.')#' => '$1$this->$2', - /*************/ - /* Attributs */ - /*************/ + /**************/ + /* Attributes */ + /**************/ '#'.self::START.'-\s*(('.$validComments.'\s*)*\$'.self::VALIDNAME.')#U' => '$1private $2', @@ -480,9 +517,9 @@ static public function parse($content) => '$1static protected $2', - /************/ - /* Méthodes */ - /************/ + /***********/ + /* Methods */ + /***********/ '#'.self::START.'\*\s*(('.$validComments.'\s*)*'.self::VALIDNAME.')#U' => '$1protected function $2', @@ -518,9 +555,9 @@ static public function parse($content) => "break;", - /***************/ - /* Assignation */ - /***************/ + /***********/ + /* Summons */ + /***********/ '#(\$.*\S)\s*\*\*=\s*('.self::VALIDNAME.')\s*\(\s*\)#U' => "$1 = $2($1)", @@ -542,6 +579,10 @@ static public function parse($content) '#(\$.*\S)(\!\!|\!|~);#U' => "$1 = $2$1;", + + /***************/ + /* Comparisons */ + /***************/ '#\seq\s#' => " == ",