| Total Complexity | 10 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class CodeDetector |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var int |
||
| 9 | */ |
||
| 10 | private $minCodeLines; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | private $patterns; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param int $minCodeLines |
||
| 19 | */ |
||
| 20 | public function setMinCodeLines($minCodeLines) |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Set array of regex code patters. |
||
| 27 | * |
||
| 28 | * @param array $patterns |
||
| 29 | */ |
||
| 30 | public function setPatterns($patterns) |
||
| 31 | { |
||
| 32 | $this->patterns = $patterns; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Determine if message contains code. |
||
| 37 | * |
||
| 38 | * @param string $message |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public function isCode($message) |
||
| 42 | { |
||
| 43 | $lines = array_map('trim', explode("\n", $message)); |
||
| 44 | $codeLines = 0; |
||
| 45 | foreach ($lines as $line) { |
||
| 46 | if ($line == "") { |
||
| 47 | continue; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($this->isCodeLine($line)) { |
||
| 51 | if (++$codeLines >= $this->minCodeLines) { |
||
| 52 | return true; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | return false; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Determines whether text line is a code line. |
||
| 62 | * |
||
| 63 | * @param string $line The line to check. |
||
| 64 | * |
||
| 65 | * @return boolean True if the line is a line of code, otherwise false. |
||
| 66 | */ |
||
| 67 | private function isCodeLine($line) |
||
| 76 | } |
||
| 77 | } |
||
| 78 |