| Total Complexity | 40 |
| Total Lines | 218 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like PluginItem often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PluginItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace XoopsModules\Mymenus\Plugins\MyMenus; |
||
| 29 | class PluginItem extends Mymenus\PluginItem |
||
| 30 | { |
||
| 31 | public static function eventBoot() |
||
| 32 | { |
||
| 33 | $registry = Mymenus\Registry::getInstance(); |
||
| 34 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 35 | $memberHandler = xoops_getHandler('member'); |
||
| 36 | |||
| 37 | $user = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser'] : null; |
||
| 38 | if (!$user) { |
||
| 39 | $user = $memberHandler->createUser(); |
||
| 40 | $user->setVar('uid', 0); |
||
| 41 | $user->setVar('uname', $GLOBALS['xoopsConfig']['anonymous']); |
||
| 42 | } |
||
| 43 | |||
| 44 | $ownerid = Request::getInt('uid', null, 'GET'); |
||
| 45 | $owner = $memberHandler->getUser($ownerid); |
||
| 46 | //if uid > 0 but user does not exists |
||
| 47 | if (!($owner instanceof \XoopsUser)) { |
||
| 48 | //create new user |
||
| 49 | $owner = $memberHandler->createUser(); |
||
| 50 | } |
||
| 51 | if ($owner->isNew()) { |
||
| 52 | $owner->setVar('uid', 0); |
||
| 53 | $owner->setVar('uname', $GLOBALS['xoopsConfig']['anonymous']); |
||
| 54 | } |
||
| 55 | $registry->setEntry('user', $user->getValues()); |
||
| 56 | $registry->setEntry('owner', $owner->getValues()); |
||
| 57 | $registry->setEntry('user_groups', ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]); |
||
| 58 | $registry->setEntry('user_uid', ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
||
| 59 | $registry->setEntry('get_uid', Request::getInt('uid', 0, 'GET')); |
||
| 60 | } |
||
| 61 | |||
| 62 | public static function eventLinkDecoration() |
||
| 63 | { |
||
| 64 | $registry = Mymenus\Registry::getInstance(); |
||
| 65 | $linkArray = $registry->getEntry('link_array'); |
||
| 66 | $linkArray['link'] = self::doDecoration($linkArray['link']); |
||
| 67 | //if (!eregi('mailto:', $linkArray['link']) && !eregi('://', $linkArray['link'])) { |
||
| 68 | if (!preg_match('/mailto:/i', $linkArray['link']) && !preg_match('#://#i', $linkArray['link'])) { |
||
| 69 | $linkArray['link'] = XOOPS_URL . '/' . $linkArray['link']; //Do not do this in other decorators |
||
| 70 | } |
||
| 71 | $registry->setEntry('link_array', $linkArray); |
||
| 72 | } |
||
| 73 | |||
| 74 | public static function eventImageDecoration() |
||
| 75 | { |
||
| 76 | $registry = Mymenus\Registry::getInstance(); |
||
| 77 | $linkArray = $registry->getEntry('link_array'); |
||
| 78 | if ($linkArray['image'] && !filter_var($linkArray['image'], FILTER_VALIDATE_URL)) { |
||
| 79 | $linkArray['image'] = XOOPS_URL . '/' . $linkArray['image']; |
||
| 80 | //Do not do this in other decorators |
||
| 81 | $linkArray['image'] = self::doDecoration($linkArray['image']); |
||
| 82 | $registry->setEntry('link_array', $linkArray); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | public static function eventTitleDecoration() |
||
| 87 | { |
||
| 88 | $registry = Mymenus\Registry::getInstance(); |
||
| 89 | $linkArray = $registry->getEntry('link_array'); |
||
| 90 | $linkArray['title'] = self::doDecoration($linkArray['title']); |
||
| 91 | $registry->setEntry('link_array', $linkArray); |
||
| 92 | } |
||
| 93 | |||
| 94 | public static function eventAltTitleDecoration() |
||
| 95 | { |
||
| 96 | $registry = Mymenus\Registry::getInstance(); |
||
| 97 | $linkArray = $registry->getEntry('link_array'); |
||
| 98 | if (!$linkArray['alt_title']) { |
||
| 99 | $linkArray['alt_title'] = $linkArray['title']; |
||
| 100 | } |
||
| 101 | $linkArray['alt_title'] = self::doDecoration($linkArray['alt_title']); |
||
| 102 | $registry->setEntry('link_array', $linkArray); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @param $string |
||
| 107 | * |
||
| 108 | * @return mixed |
||
| 109 | */ |
||
| 110 | protected static function doDecoration($string) |
||
| 111 | { |
||
| 112 | $registry = Mymenus\Registry::getInstance(); |
||
| 113 | //if (!eregi("{(.*\|.*)}", $string, $reg)) { |
||
| 114 | if (!preg_match('/{(.*\|.*)}/i', $string, $reg)) { |
||
| 115 | return $string; |
||
| 116 | } |
||
| 117 | |||
| 118 | $expression = $reg[0]; |
||
| 119 | list($validator, $value) = array_map('strtolower', explode('|', $reg[1])); |
||
| 120 | |||
| 121 | //just to prevent any bad admin to get easy passwords |
||
| 122 | if ('pass' === $value) { |
||
| 123 | return $string; |
||
| 124 | } |
||
| 125 | |||
| 126 | if ('user' === $validator) { |
||
| 127 | $user = $registry->getEntry('user'); |
||
| 128 | $value = isset($user[$value]) ? $user[$value] : static::getExtraValue('user', $value); |
||
| 129 | $string = str_replace($expression, $value, $string); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ('uri' === $validator) { |
||
| 133 | $value = Request::getString($value, 0, 'GET'); |
||
| 134 | $string = str_replace($expression, $value, $string); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ('owner' === $validator) { |
||
| 138 | $owner = $registry->getEntry('owner'); |
||
| 139 | $value = isset($owner[$value]) ? $owner[$value] : static::getExtraValue('owner', $value); |
||
| 140 | $string = str_replace($expression, $value, $string); |
||
| 141 | } |
||
| 142 | |||
| 143 | return $string; |
||
| 144 | } |
||
| 145 | |||
| 146 | public static function eventFormLinkDescription() |
||
| 147 | { |
||
| 148 | $registry = Mymenus\Registry::getInstance(); |
||
| 149 | $description = $registry->getEntry('form_link_description'); |
||
| 150 | } |
||
| 151 | |||
| 152 | public static function eventHasAccess() |
||
| 153 | { |
||
| 154 | $registry = Mymenus\Registry::getInstance(); |
||
| 155 | $menu = $registry->getEntry('menu'); |
||
| 156 | $groups = $registry->getEntry('user_groups'); |
||
| 157 | if (0 == $menu['visible'] || !array_intersect($menu['groups'], $groups)) { |
||
| 158 | $registry->setEntry('has_access', 'no'); |
||
| 159 | |||
| 160 | return; |
||
| 161 | } |
||
| 162 | $hooks = array_intersect($menu['hooks'], get_class_methods(__CLASS__)); |
||
| 163 | |||
| 164 | foreach ($hooks as $method) { |
||
| 165 | if (!self::$method()) { |
||
| 166 | $registry->setEntry('has_access', 'no'); |
||
| 167 | |||
| 168 | return; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | public static function eventAccessFilter() |
||
| 174 | { |
||
| 175 | static::loadLanguage('mymenus'); |
||
| 176 | $registry = Mymenus\Registry::getInstance(); |
||
| 177 | $accessFilter = $registry->getEntry('accessFilter'); |
||
| 178 | $accessFilter['is_owner']['name'] = _PL_MYMENUS_MYMENUS_ISOWNER; |
||
| 179 | $accessFilter['is_owner']['method'] = 'isOwner'; |
||
| 180 | $accessFilter['is_not_owner']['name'] = _PL_MYMENUS_MYMENUS_ISNOTOWNER; |
||
| 181 | $accessFilter['is_not_owner']['method'] = 'isNotOwner'; |
||
| 182 | $registry->setEntry('accessFilter', $accessFilter); |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @return bool |
||
| 187 | */ |
||
| 188 | public function isOwner() |
||
| 189 | { |
||
| 190 | $registry = Mymenus\Registry::getInstance(); |
||
| 191 | |||
| 192 | return (0 != $registry->getEntry('user_uid') |
||
| 193 | && $registry->getEntry('user_uid') == $registry->getEntry('get_uid')); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | public function isNotOwner() |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param string $type |
||
| 206 | * @param $value |
||
| 207 | * |
||
| 208 | * @return int |
||
| 209 | */ |
||
| 210 | public static function getExtraValue($type = 'user', $value) |
||
| 211 | { |
||
| 247 | } |
||
| 248 | } |
||
| 249 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths