Conditions | 16 |
Paths | 58 |
Total Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
39 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
40 | { |
||
41 | |||
42 | $fs = new Filesystem(); |
||
43 | |||
44 | // is there a web directory ? |
||
45 | |||
46 | if ($fs->exists('../web') || $fs->exists('../public_html') || $fs->exists('../public')) { |
||
47 | $gitPath = '../.git'; |
||
48 | } else { |
||
49 | // unit tests |
||
50 | $gitPath = '.git'; |
||
51 | } |
||
52 | |||
53 | // if there is no .git directory |
||
54 | if (!$fs->exists($gitPath)) { |
||
55 | $this->data['gitData'] = false; |
||
56 | return; |
||
57 | } |
||
58 | |||
59 | // get latest commit information |
||
60 | exec("git log -1", $data); |
||
61 | |||
62 | if (isset($data) && !empty($data)) { |
||
63 | |||
64 | // there is some information |
||
65 | $this->data['gitData'] = true; |
||
66 | |||
67 | foreach ($data as $d) { |
||
68 | |||
69 | if (strpos($d, 'commit') === 0) { |
||
70 | |||
71 | // commit Id |
||
72 | |||
73 | $this->data['commit'] = substr($d, 7); |
||
74 | |||
75 | } elseif (strpos($d, 'Author') === 0) { |
||
76 | |||
77 | // author and email |
||
78 | |||
79 | preg_match('$Author: ([^<]+)<(.+)>$', $d, $author); |
||
80 | |||
81 | if (isset($author[1])) { |
||
82 | $this->data['author'] = trim($author[1]); |
||
83 | } |
||
84 | if (isset($author[2])) { |
||
85 | $this->data['email'] = $author[2]; |
||
86 | } |
||
87 | |||
88 | } elseif (strpos($d, 'Date') === 0) { |
||
89 | |||
90 | $date = trim(substr($d, 5)); // ddd mmm n hh:mm:ss yyyy +gmt |
||
91 | |||
92 | // date of commit |
||
93 | $dateCommit = date_create($date); |
||
94 | |||
95 | // actual date at runtime |
||
96 | $dateRuntime = new \DateTime(); |
||
97 | $dateNow = date_create($dateRuntime->format('Y-m-d H:i:s')); |
||
98 | |||
99 | // difference |
||
100 | $time = date_diff($dateCommit, $dateNow); |
||
101 | |||
102 | // static time difference : minutes and seconds |
||
103 | $this->data['timeCommitIntervalMinutes'] = $time->format('%y')*365*24*60+$time->format('%m')*30*24*60+$time->format('%d')*24*60+$time->format('%h')*60+$time->format('%i'); |
||
104 | $this->data['timeCommitIntervalSeconds'] = $time->format('%s'); |
||
105 | |||
106 | // full readable date |
||
107 | $this->data['date'] = $date; |
||
108 | |||
109 | } elseif (strpos($d, 'Merge') === 0) { |
||
110 | |||
111 | // merge information |
||
112 | |||
113 | $this->data['merge'] = trim(substr($d, 6)); |
||
114 | |||
115 | } else { |
||
116 | |||
117 | // commit message |
||
118 | |||
119 | $this->data['message'] = trim($d); |
||
120 | |||
121 | } |
||
122 | |||
123 | } |
||
124 | |||
125 | unset($data); |
||
126 | |||
127 | exec("git status", $data); |
||
128 | |||
129 | if (isset($data[0])) { |
||
130 | |||
131 | if (strstr($data[0], 'On branch')) { |
||
132 | |||
133 | // branch name |
||
134 | |||
135 | $this->data['branch'] = trim(substr($data[0], strpos($data[0], 'On branch')+9)); |
||
136 | |||
137 | } |
||
138 | } |
||
139 | |||
140 | } else { |
||
141 | |||
142 | // no git data |
||
143 | |||
144 | $this->data['gitData'] = false; |
||
145 | |||
146 | } |
||
147 | |||
148 | |||
149 | } |
||
150 | |||
336 |