| Conditions | 20 |
| Paths | 1096 |
| Total Lines | 46 |
| 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 |
||
| 69 | private function prepareData(\SimpleXMLElement $banner) { |
||
| 70 | if ($banner->getName() != 'groups') { |
||
| 71 | $attributes = $banner->attributes(); |
||
| 72 | $this->bannerData = [ |
||
| 73 | 'group' => (string) $attributes->group ? serialize(explode(',', trim((string) $attributes->group))) : '', |
||
| 74 | 'active' => (string) $attributes->active ? (string) $attributes->active : 0, |
||
| 75 | 'active_to' => (string) $attributes->active_to ? (string) $attributes->active_to : -1, |
||
| 76 | 'where_show' => (string) $attributes->where_show ? serialize([(string) $attributes->where_show . '_0']) : serialize(['default']), |
||
| 77 | 'position' => (string) $attributes->position ? (string) $attributes->position : 0, |
||
| 78 | ]; |
||
| 79 | |||
| 80 | $this->ci->db->insert('mod_banner', $this->bannerData); |
||
| 81 | |||
| 82 | if (isset($banner->banner_i18n) && $this->ci->db->insert_id()) { |
||
| 83 | foreach ($banner->banner_i18n as $banner_i18n) { |
||
| 84 | $attributes = $banner_i18n->attributes(); |
||
| 85 | $this->bannerI18nData[] = [ |
||
| 86 | 'id' => $this->ci->db->insert_id(), |
||
| 87 | 'name' => (string) $attributes->name ? (string) $attributes->name : 'Banner', |
||
| 88 | 'description' => (string) $attributes->description ? (string) $attributes->description : '', |
||
| 89 | 'url' => (string) $attributes->url ? (string) $attributes->url : '', |
||
| 90 | 'locale' => (string) $attributes->locale ? (string) $attributes->locale : 'ru', |
||
| 91 | 'photo' => (string) $attributes->photo ? (string) $attributes->photo : '', |
||
| 92 | ]; |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | $this->messages[] = lang('Can not install banner.', 'template_manager'); |
||
|
|
|||
| 96 | return FALSE; |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | if (isset($banner->group)) { |
||
| 100 | foreach ($banner->group as $group) { |
||
| 101 | $attributes = $group->attributes(); |
||
| 102 | $this->bannerGroupsData = [ |
||
| 103 | 'name' => (string) $attributes->name ? (string) $attributes->name : '', |
||
| 104 | ]; |
||
| 105 | |||
| 106 | if ($this->bannerGroupsData) { |
||
| 107 | if (!isset($this->existed_banners_groups[$this->bannerGroupsData['name']])) { |
||
| 108 | $this->ci->db->insert('mod_banner_groups', $this->bannerGroupsData); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | } |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.