| Conditions | 19 |
| Paths | 321 |
| Total Lines | 104 |
| Code Lines | 80 |
| 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 |
||
| 72 | public function getListOfConfigs() |
||
| 73 | { |
||
| 74 | |||
| 75 | $resultArray = []; |
||
| 76 | |||
| 77 | $doNotShow = $this->Config()->get('do_not_show'); |
||
| 78 | |||
| 79 | $config = Config::inst(); |
||
| 80 | $alsoSet = $config->getAll(); |
||
| 81 | |||
| 82 | $classes = $this->configurableClasses(); |
||
| 83 | foreach ($classes as $class) { |
||
| 84 | $reflector = new ReflectionClass($class); |
||
| 85 | $fileName = $reflector->getFileName(); |
||
| 86 | $fileName = str_replace(Director::baseFolder(), '', $fileName); |
||
| 87 | $statics = $reflector->getStaticProperties(); |
||
| 88 | |||
| 89 | //lists |
||
| 90 | $deltaList = $this->getDeltas($config, $class); |
||
| 91 | $staticList = []; |
||
| 92 | $dynamicList = array_keys($alsoSet[strtolower($class)]); |
||
| 93 | $staticListDefaultOnes = []; |
||
| 94 | $staticListCachingStatics = []; |
||
| 95 | foreach (array_keys($statics) as $key) { |
||
| 96 | if (in_array($key, $doNotShow, true)) { |
||
| 97 | $staticListDefaultOnes[$key] = $key; |
||
| 98 | } elseif ( |
||
| 99 | substr($key, 0, 1) === '_' || |
||
| 100 | strpos($key, 'cache') !== false |
||
| 101 | ) { |
||
| 102 | $staticListCachingStatics[$key] = $key; |
||
| 103 | } else { |
||
| 104 | $staticList[$key] = $key; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $vendor = 'n/a'; |
||
| 108 | $package = 'n/a'; |
||
| 109 | $shorterClassname = $class; |
||
| 110 | $classNameArray = explode('\\', $class); |
||
| 111 | if (count($classNameArray) > 1) { |
||
| 112 | $vendor = $classNameArray[0]; |
||
| 113 | $package = $classNameArray[1]; |
||
| 114 | array_shift($classNameArray); |
||
| 115 | array_shift($classNameArray); |
||
| 116 | $shorterClassname = implode(' / ', $classNameArray); |
||
| 117 | } |
||
| 118 | $lists = [ |
||
| 119 | 'runtime' => $deltaList, |
||
| 120 | 'property' => $staticList, |
||
| 121 | 'caching' => $staticListCachingStatics, |
||
| 122 | 'system' => $staticListDefaultOnes, |
||
| 123 | 'dynamic' => $dynamicList, |
||
| 124 | ]; |
||
| 125 | $shortClassName = ClassInfo::shortName($class); |
||
| 126 | $ancestry = ClassInfo::ancestry($class); |
||
| 127 | foreach($lists as $type => $list) { |
||
| 128 | if (count($list)) { |
||
| 129 | foreach($list as $property) { |
||
| 130 | $key = str_replace('/', '-', $fileName.'-'.$property); |
||
| 131 | if(!isset($resultArray[$key])) { |
||
| 132 | $value = $config->get($class, $property, Config::UNINHERITED); |
||
| 133 | $hasValue = $value ? true : false; |
||
| 134 | $originalValue = ''; |
||
| 135 | if(is_object($value)) { |
||
| 136 | $value = 'object'; |
||
| 137 | } else { |
||
| 138 | if($reflector->hasProperty($property)) { |
||
| 139 | $propertyObject = $reflector->getProperty($property); |
||
| 140 | $propertyObject->setAccessible(true); |
||
| 141 | $originalValue = $propertyObject->getValue($reflector); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | $isDefault = true; |
||
| 145 | $default = ''; |
||
| 146 | if($originalValue && $originalValue !== $value) { |
||
| 147 | $isDefault = false; |
||
| 148 | if($value && $originalValue) { |
||
| 149 | $default = $originalValue; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | $hasDefault = $originalValue ? true : false; |
||
| 153 | $resultArray[$key] = [ |
||
| 154 | 'Vendor' => $vendor, |
||
| 155 | 'Package' => $package, |
||
| 156 | 'ClassName' => $class, |
||
| 157 | 'ShorterClassName' => $shorterClassname, |
||
| 158 | 'ShortClassName' => $shortClassName, |
||
| 159 | 'FileLocation' => $fileName, |
||
| 160 | 'ParentClasses' => $ancestry, |
||
| 161 | 'Property' => $property, |
||
| 162 | 'Type' => $type, |
||
| 163 | 'IsDefault' => $isDefault, |
||
| 164 | 'HasDefault' => $hasDefault, |
||
| 165 | 'HasValue' => $hasValue, |
||
| 166 | 'Default' => $default, |
||
| 167 | 'Value' => $value, |
||
| 168 | ]; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | return $resultArray; |
||
| 176 | } |
||
| 229 |