diff --git a/lib/LogicalComment.php b/lib/LogicalComment.php new file mode 100644 index 0000000..5c8ae4d --- /dev/null +++ b/lib/LogicalComment.php @@ -0,0 +1,89 @@ +findInstanceOf($nodes, Comment::class); + /** + * @var Comment\Doc[] $commentDocList + */ + $commentDocList = $finder->findInstanceOf($nodes, Comment\Doc::class); + + + + foreach ($commentList as $comment) { + preg_match('/^(phplint(-\w+){0,3}?)(\s|$)/', $comment->getReformattedText(), $matches); + switch ($matches[0]) { + case self::DISABLE_LINE: + $this->disableReporting($comment->getLine()); + $this->enableReporting($comment->getLine() + 1); + break; + case self::DISABLE_NEXT_LINE: + $this->disableReporting($comment->getLine()); + $this->enableReporting($comment->getLine() + 2); + break; + } + } + foreach ($commentDocList as $comment) { + preg_match('/^(phplint(-\w+){0,3}?)(\s|$)/', $comment->getReformattedText(), $matches); + $value = substr($comment->getReformattedText(),count($matches[0]) + count($matches[1])); + switch ($matches[0]) { + case self::DISABLE: + $this->disableReporting($comment->getLine(), self::parseListConfig($value)); + break; + case self::ENABLE: + $this->enableReporting($comment->getLine(), self::parseListConfig($value)); + break; + case self::PHPLINT: + break; + } + } + } + + public function disableReporting($start, $rulesToDisable = []) + { + + } + public function enableReporting($start, $rulesToEnable = []) + { + + } + + /** + * Parses a config of values separated by comma. + * + * @param $value string The string to parse. + * + * @return array Result map of values and true values + */ + public static function parseListConfig($value) + { + $items = []; + $value = preg_replace('/\s*,\s*/', ':', $value); + $arr = explode(':', $value); + foreach ($arr as $name) { + $name = trim($name); + if ($name) { + $items[] = $name; + } + } + return $items; + } +} \ No newline at end of file diff --git a/test/LogicalCommentTest.php b/test/LogicalCommentTest.php new file mode 100644 index 0000000..76a2b19 --- /dev/null +++ b/test/LogicalCommentTest.php @@ -0,0 +1,13 @@ +assertEquals(LogicalComment::parseListConfig(' a,c, b, d'), ['a', 'c', 'b', 'd']); + } +} \ No newline at end of file