| Conditions | 4 |
| Paths | 3 |
| Total Lines | 66 |
| Code Lines | 34 |
| 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 |
||
| 15 | public function render() |
||
| 16 | { |
||
| 17 | $app = $this->app; |
||
| 18 | $document = $app->document; |
||
| 19 | $document->js->add('available-sites.js'); |
||
| 20 | $document->page_title = 'Select a website'; |
||
| 21 | |||
| 22 | /* @var $site \Icybee\Modules\Sites\Site */ |
||
| 23 | $site = $app->site; |
||
| 24 | $ws_title = \ICanBoogie\escape($site->admin_title ? $site->admin_title : $site->title .':' . $site->language); |
||
| 25 | |||
| 26 | $available = $site->model |
||
| 27 | ->where('site_id IN(' . implode(',', $app->user->restricted_sites_ids) . ')') |
||
| 28 | ->order('admin_title, title') |
||
| 29 | ->all; |
||
| 30 | |||
| 31 | $uri = substr($_SERVER['REQUEST_URI'], strlen($site->path)); |
||
| 32 | $options = []; |
||
| 33 | |||
| 34 | foreach ($available as $site) |
||
| 35 | { |
||
| 36 | $title = $site->title . ':' . $site->language; |
||
| 37 | |||
| 38 | if ($site->admin_title) |
||
| 39 | { |
||
| 40 | $title .= ' (' . $site->admin_title . ')'; |
||
| 41 | } |
||
| 42 | |||
| 43 | $options[$site->url . $uri] = $title; |
||
| 44 | } |
||
| 45 | |||
| 46 | $form = new Form([ |
||
| 47 | |||
| 48 | Form::ACTIONS => new Button('Change', [ |
||
| 49 | |||
| 50 | 'class' => 'btn-primary', |
||
| 51 | 'type' => 'submit' |
||
| 52 | |||
| 53 | ]), |
||
| 54 | |||
| 55 | Form::RENDERER => Form\GroupRenderer::class, |
||
| 56 | |||
| 57 | Element::CHILDREN => [ |
||
| 58 | |||
| 59 | new Element('select', [ |
||
| 60 | |||
| 61 | Element::DESCRIPTION => "Select one of the website available to your profile.", |
||
| 62 | Element::OPTIONS => $options |
||
| 63 | |||
| 64 | ]) |
||
| 65 | ], |
||
| 66 | |||
| 67 | 'name' => 'change-working-site', |
||
| 68 | 'class' => 'form-primary' |
||
| 69 | |||
| 70 | ]); |
||
| 71 | |||
| 72 | return <<<EOT |
||
| 73 | <div id="block--site-access-denied" class="block-alert"> |
||
| 74 | <h2>Access denied</h2> |
||
| 75 | <p>You don't have permission to access the administration interface for the website <q>$ws_title</q>, |
||
| 76 | please select another website to work with:</p> |
||
| 77 | $form |
||
| 78 | </div> |
||
| 79 | EOT; |
||
| 80 | } |
||
| 81 | } |
||
| 82 |