Conditions | 12 |
Paths | 13 |
Total Lines | 39 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
111 | public function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { |
||
112 | static $filesize = null; |
||
113 | static $progress = null; |
||
114 | |||
115 | switch($notification_code) { |
||
116 | case STREAM_NOTIFY_AUTH_REQUIRED: |
||
117 | case STREAM_NOTIFY_AUTH_RESULT: |
||
118 | break; |
||
119 | case STREAM_NOTIFY_CONNECT: |
||
120 | if(!$progress) { |
||
121 | $this->output->writeln(sprintf("<info>Downloading</info>")); |
||
122 | } |
||
123 | break; |
||
124 | |||
125 | case STREAM_NOTIFY_FILE_SIZE_IS: |
||
126 | $filesize = $bytes_max; |
||
127 | $progress = new ProgressBar($this->output); |
||
128 | $progress->start($filesize / 100); |
||
129 | break; |
||
130 | |||
131 | case STREAM_NOTIFY_PROGRESS: |
||
132 | if ($bytes_transferred > 0) { |
||
133 | if (!isset($filesize)) { |
||
134 | $this->output->writeln(sprintf("<info>Unknown file size.. %2d kb done..</info>", $bytes_transferred/1024)); |
||
135 | } else { |
||
136 | $progress->setProgress($bytes_transferred / 100); |
||
137 | } |
||
138 | } |
||
139 | break; |
||
140 | |||
141 | case STREAM_NOTIFY_COMPLETED: |
||
142 | case STREAM_NOTIFY_FAILURE: |
||
143 | if($progress) { |
||
144 | $progress->clear(); |
||
145 | $progress->finish(); |
||
146 | } |
||
147 | break; |
||
148 | } |
||
149 | } |
||
150 | |||
152 | } |