Skip to content

Commit

Permalink
Update Inspector::executable to take into account multilines comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mehlah committed Jan 17, 2012
1 parent c737008 commit ce2a424
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion analysis/Inspector.php
Expand Up @@ -205,9 +205,30 @@ function($str) { return preg_quote($str, '/'); },
if ($options['filter'] && $class->getFileName()) {
$file = explode("\n", "\n" . file_get_contents($class->getFileName()));
$lines = array_intersect_key($file, array_flip($result));
$start = key($lines);

$code = implode("\n", $lines);
$tokens = token_get_all('<?php' . $code);
$tmp = array();

foreach ($tokens as $token) {
if (is_array($token)) {
if (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT, T_WHITESPACE))) {
array_push($tmp, $token[2]);
}
}
}

$lines_without_comments = array_values(array_map(
function($ln) use ($start) { return $ln + $start - 1; },
array_unique($tmp))
);

$lines = array_intersect_key($lines, array_flip($lines_without_comments));

$result = array_keys(array_filter($lines, function($line) use ($options) {
$line = trim($line);
$empty = (strpos($line, '//') === 0 || preg_match($options['pattern'], $line));
$empty = preg_match($options['pattern'], $line);
return $empty ? false : (str_replace($options['empty'], '', $line) != '');
}));
}
Expand Down

0 comments on commit ce2a424

Please sign in to comment.