Conditions | 18 |
Paths | 64 |
Total Lines | 100 |
Code Lines | 62 |
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 |
||
73 | public function restrict(&$files, $srcDir, $destDir, $mapper, $force = false) |
||
74 | { |
||
75 | $now = time(); |
||
76 | $targetList = ''; |
||
|
|||
77 | |||
78 | /* |
||
79 | If we're on Windows, we have to munge the time up to 2 secs to |
||
80 | be able to check file modification times. |
||
81 | (Windows has a max resolution of two secs for modification times) |
||
82 | */ |
||
83 | $osname = strtolower(Phing::getProperty('os.name')); |
||
84 | |||
85 | // indexOf() |
||
86 | $index = ((($res = strpos($osname, 'win')) === false) ? -1 : $res); |
||
87 | if ($index >= 0) { |
||
88 | $now += 2000; |
||
89 | } |
||
90 | |||
91 | $v = []; |
||
92 | |||
93 | for ($i = 0, $size = count($files); $i < $size; ++$i) { |
||
94 | $targets = $mapper->main($files[$i]); |
||
95 | if (empty($targets)) { |
||
96 | $this->task->log($files[$i] . " skipped - don't know how to handle it", Project::MSG_VERBOSE); |
||
97 | |||
98 | continue; |
||
99 | } |
||
100 | |||
101 | $src = null; |
||
102 | |||
103 | try { |
||
104 | if (null === $srcDir) { |
||
105 | $src = new File($files[$i]); |
||
106 | } else { |
||
107 | $src = $this->fileUtils->resolveFile($srcDir, $files[$i]); |
||
108 | } |
||
109 | |||
110 | if ($src->lastModified() > $now) { |
||
111 | $this->task->log( |
||
112 | 'Warning: ' . $files[$i] . ' modified in the future (' . $src->lastModified() . ' > ' . $now . ')', |
||
113 | Project::MSG_WARN |
||
114 | ); |
||
115 | } |
||
116 | } catch (IOException $ioe) { |
||
117 | $this->task->log('Unable to read file ' . $files[$i] . ' (skipping): ' . $ioe->getMessage()); |
||
118 | |||
119 | continue; |
||
120 | } |
||
121 | |||
122 | $added = false; |
||
123 | $targetList = ''; |
||
124 | |||
125 | for ($j = 0, $_j = count($targets); (!$added && $j < $_j); ++$j) { |
||
126 | $dest = null; |
||
127 | if (null === $destDir) { |
||
128 | $dest = new File($targets[$j]); |
||
129 | } else { |
||
130 | $dest = $this->fileUtils->resolveFile($destDir, $targets[$j]); |
||
131 | } |
||
132 | |||
133 | if (!$dest->exists()) { |
||
134 | $this->task->log( |
||
135 | ($files[$i] ?: '.') . ' added as ' . $dest->__toString() . " doesn't exist.", |
||
136 | Project::MSG_VERBOSE |
||
137 | ); |
||
138 | $v[] = $files[$i]; |
||
139 | $added = true; |
||
140 | } elseif ($src->lastModified() > $dest->lastModified()) { |
||
141 | $this->task->log( |
||
142 | $files[$i] . ' added as ' . $dest->__toString() . ' is outdated.', |
||
143 | Project::MSG_VERBOSE |
||
144 | ); |
||
145 | $v[] = $files[$i]; |
||
146 | $added = true; |
||
147 | } elseif (true === $force) { |
||
148 | $this->task->log( |
||
149 | $files[$i] . ' added as ' . $dest->__toString() . ' is forced to be overwritten.', |
||
150 | Project::MSG_VERBOSE |
||
151 | ); |
||
152 | $v[] = $files[$i]; |
||
153 | $added = true; |
||
154 | } else { |
||
155 | if (strlen($targetList) > 0) { |
||
156 | $targetList .= ', '; |
||
157 | } |
||
158 | $targetList .= $dest->getAbsolutePath(); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | if (!$added) { |
||
163 | $this->task->log( |
||
164 | $files[$i] . ' omitted as ' . $targetList . ' ' . (1 === count( |
||
165 | $targets |
||
166 | ) ? ' is ' : ' are ') . 'up to date.', |
||
167 | Project::MSG_VERBOSE |
||
168 | ); |
||
169 | } |
||
170 | } |
||
171 | |||
172 | return $v; |
||
173 | } |
||
198 |