| Conditions | 6 |
| Paths | 7 |
| Total Lines | 65 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 44 | function find_signed_off($commit = 'HEAD', $childs = array(), $level = 0) |
||
| 45 | { |
||
| 46 | $commit = trim($commit); |
||
| 47 | |||
| 48 | // Where we are at. |
||
| 49 | debugPrint('Attempting to find signed off on commit ' . $commit); |
||
| 50 | |||
| 51 | // To many recrusions here. |
||
| 52 | if ($level > 10) |
||
| 53 | { |
||
| 54 | debugPrint('Recusion limit exceeded on find_signed_off'); |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | |||
| 58 | // What string tests should we look for? |
||
| 59 | $stringTests = array('Signed-off-by:', 'Signed by'); |
||
| 60 | |||
| 61 | // Get message data and clean it up, should only need the last line. |
||
| 62 | $message = trim(shell_exec('git show -s --format=%B ' . $commit)); |
||
| 63 | $lines = explode("\n", trim(str_replace("\r", "\n", $message))); |
||
| 64 | $lastLine = $lines[count($lines) - 1]; |
||
| 65 | |||
| 66 | // Debug info. |
||
| 67 | debugPrint('Testing line "' . $lastLine . '"'); |
||
| 68 | |||
| 69 | // loop through each test and find one. |
||
| 70 | $result = false; |
||
| 71 | foreach ($stringTests as $testedString) |
||
| 72 | { |
||
| 73 | debugPrint('Testing "' . $testedString . '"'); |
||
| 74 | |||
| 75 | $result = stripos($lastLine, $testedString); |
||
| 76 | |||
| 77 | // We got a result. |
||
| 78 | if ($result !== false) |
||
| 79 | { |
||
| 80 | debugPrint('Found "' . $testedString . '"'); |
||
| 81 | break; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | // Debugger. |
||
| 86 | $debugMsgs = array( |
||
| 87 | 'raw body' => '"' . rtrim(shell_exec('git show -s --format=%B ' . $commit)) . '"', |
||
| 88 | 'body' => '"' . rtrim(shell_exec('git show -s --format=%b ' . $commit)) . '"', |
||
| 89 | 'commit notes' => '"' . rtrim(shell_exec('git show -s --format=%N ' . $commit)) . '"', |
||
| 90 | 'ref names' => '"' . rtrim(shell_exec('git show -s --format=%d ' . $commit)) . '"', |
||
| 91 | 'commit hash' => '"' . rtrim(shell_exec('git show -s --format=%H ' . $commit)) . '"', |
||
| 92 | 'tree hash' => '"' . rtrim(shell_exec('git show -s --format=%T ' . $commit)) . '"', |
||
| 93 | 'parent hash' => '"' . rtrim(shell_exec('git show -s --format=%P ' . $commit)) . '"', |
||
| 94 | 'result' => '"' . $result . '"', |
||
|
|
|||
| 95 | 'testedString' => '"' . $testedString . '"', |
||
| 96 | ); |
||
| 97 | debugPrint('Commit ' . $commit . ' at time ' . time() . ": " . rtrim(print_r($debugMsgs, true))); |
||
| 98 | |||
| 99 | |||
| 100 | // No result and found a merge? Lets go deeper. |
||
| 101 | if ($result === false && preg_match('~Merge ([A-Za-z0-9]{40}) into ([A-Za-z0-9]{40})~i', $lastLine, $merges)) |
||
| 102 | { |
||
| 103 | debugPrint('Found Merge, attempting to get more parent commit: ' . $merges[1]); |
||
| 104 | |||
| 105 | return find_signed_off($merges[1], array_merge(array($merges[1]), $childs), ++$level); |
||
| 106 | } |
||
| 107 | |||
| 108 | return $result !== false; |
||
| 109 | } |
||
| 174 | } |