| Conditions | 5 | 
| Paths | 1 | 
| Total Lines | 65 | 
| Code Lines | 36 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 4 | ||
| Bugs | 1 | 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 | ||
| 24 | public function body() | ||
| 25 | 	{ | ||
| 26 | 		$layout = View::addTo($this)->addStyle('max-width:1200px;margin:auto;'); | ||
| 27 | \atk4\ui\Header::addTo($layout, [ __($this->label)]); | ||
| 28 | $segment = View::addTo($layout, ['ui' => 'segment']); | ||
| 29 | |||
| 30 | $form = Form::addTo($segment); | ||
| 31 | |||
| 32 | 		$form->addControl('title', __('Base page title')); | ||
| 33 | |||
| 34 | 		$form->addControl('custom_logo', [\atk4\ui\Form\Control\Checkbox::class, 'caption' => __('Use custom logo')]); | ||
| 35 | |||
| 36 | $form->model->setMulti([ | ||
| 37 | 		        'title' => Variable::recall('system.title'), | ||
| 38 | 		        'custom_logo' => (bool) Variable::recall('system.logo') | ||
| 39 | ]); | ||
| 40 | |||
| 41 | 		$logo = $form->addControl('logo', [ | ||
| 42 | \atk4\ui\Form\Control\UploadImage::class, | ||
| 43 | 				'defaultSrc' => url('logo'),  | ||
| 44 | 				'thumbnail' => (new View(['element'=>'img', 'class' => ['right', 'floated', 'image'], 'ui' => true]))->setStyle('max-width', '150px'), | ||
| 45 | 				'placeholder' => __('Upload file to replace system logo') | ||
| 46 | ]); | ||
| 47 | |||
| 48 | $form->addControlDisplayRules(['logo' => ['custom_logo' => 'checked']]); | ||
| 49 | |||
| 50 | 		$logo->onDelete(function($fileName) use ($logo) { | ||
|  | |||
| 51 | $this->storage()->delete(self::alias() . '/tmp/' . $fileName); | ||
| 52 | |||
| 53 | 			$logo->setThumbnailSrc(asset('storage/' . self::alias() . '/' . self::$defaultLogo)); | ||
| 54 | }); | ||
| 55 | |||
| 56 | 		$logo->onUpload(function ($files) use ($form, $logo) { | ||
| 57 | 			if ($files === 'error')	return $form->error('logo', __('Error uploading image')); | ||
| 58 | |||
| 59 | $tmpPath = self::alias() . '/tmp/' . $files['name']; | ||
| 60 | |||
| 61 | 			$logo->setThumbnailSrc(asset('storage/' . $tmpPath)); | ||
| 62 | |||
| 63 | $this->storage()->put($tmpPath, file_get_contents($files['tmp_name'])); | ||
| 64 | }); | ||
| 65 | |||
| 66 | 		$form->onSubmit(function($form) { | ||
| 67 | 			if ($logo = $form->model->get('custom_logo') ? $form->model->get('logo') : null) { | ||
| 68 | $storage = $this->storage(); | ||
| 69 | $from = self::alias() . '/tmp/' . $logo; | ||
| 70 | $to = self::alias() . '/' . $logo; | ||
| 71 | |||
| 72 | 				if ($storage->exists($to)) { | ||
| 73 | $storage->delete($to); | ||
| 74 | } | ||
| 75 | |||
| 76 | $storage->move($from, $to); | ||
| 77 | } | ||
| 78 | |||
| 79 | 	        Variable::memorize('system.logo', $logo); | ||
| 80 | |||
| 81 | 			Variable::memorize('system.title', $form->model->get('title')); | ||
| 82 | |||
| 83 | 			return $this->notifySuccess(__('Title and logo updated! Refresh page to see changes ...')); | ||
| 84 | }); | ||
| 85 | |||
| 86 | 		ActionBar::addItemButton('back')->link(url('view/system')); | ||
| 87 | |||
| 88 | 		ActionBar::addItemButton('save')->on('click', $form->submit()); | ||
| 89 | } | ||
| 107 |