| Conditions | 36 |
| Paths | 1378 |
| Total Lines | 121 |
| Code Lines | 65 |
| 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 |
||
| 82 | protected static function _initRelationship($relationship, $options) |
||
| 83 | { |
||
| 84 | $classShortName = basename(str_replace('\\', '/', static::$rootClass)); |
||
| 85 | |||
| 86 | // apply defaults |
||
| 87 | if (empty($options['type'])) { |
||
| 88 | $options['type'] = 'one-one'; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($options['type'] == 'one-one') { |
||
| 92 | if (empty($options['local'])) { |
||
| 93 | $options['local'] = $relationship . 'ID'; |
||
| 94 | } |
||
| 95 | |||
| 96 | if (empty($options['foreign'])) { |
||
| 97 | $options['foreign'] = 'ID'; |
||
| 98 | } |
||
| 99 | } elseif ($options['type'] == 'one-many') { |
||
| 100 | if (empty($options['local'])) { |
||
| 101 | $options['local'] = 'ID'; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (empty($options['foreign'])) { |
||
| 105 | $options['foreign'] = $classShortName. 'ID'; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (!isset($options['indexField'])) { |
||
| 109 | $options['indexField'] = false; |
||
| 110 | } |
||
| 111 | |||
| 112 | if (!isset($options['conditions'])) { |
||
| 113 | $options['conditions'] = []; |
||
| 114 | } elseif (is_string($options['conditions'])) { |
||
| 115 | $options['conditions'] = [$options['conditions']]; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (!isset($options['order'])) { |
||
| 119 | $options['order'] = false; |
||
| 120 | } |
||
| 121 | } elseif ($options['type'] == 'context-children') { |
||
| 122 | if (empty($options['local'])) { |
||
| 123 | $options['local'] = 'ID'; |
||
| 124 | } |
||
| 125 | |||
| 126 | if (empty($options['contextClass'])) { |
||
| 127 | $options['contextClass'] = get_called_class(); |
||
| 128 | } |
||
| 129 | |||
| 130 | if (!isset($options['indexField'])) { |
||
| 131 | $options['indexField'] = false; |
||
| 132 | } |
||
| 133 | |||
| 134 | if (!isset($options['conditions'])) { |
||
| 135 | $options['conditions'] = []; |
||
| 136 | } |
||
| 137 | |||
| 138 | if (!isset($options['order'])) { |
||
| 139 | $options['order'] = false; |
||
| 140 | } |
||
| 141 | } elseif ($options['type'] == 'context-parent') { |
||
| 142 | if (empty($options['local'])) { |
||
| 143 | $options['local'] = 'ContextID'; |
||
| 144 | } |
||
| 145 | |||
| 146 | if (empty($options['foreign'])) { |
||
| 147 | $options['foreign'] = 'ID'; |
||
| 148 | } |
||
| 149 | |||
| 150 | if (empty($options['classField'])) { |
||
| 151 | $options['classField'] = 'ContextClass'; |
||
| 152 | } |
||
| 153 | |||
| 154 | if (empty($options['allowedClasses'])) { |
||
| 155 | $options['allowedClasses'] = static::$contextClasses; |
||
| 156 | } |
||
| 157 | } elseif ($options['type'] == 'many-many') { |
||
| 158 | if (empty($options['class'])) { |
||
| 159 | throw new Exception('Relationship type many-many option requires a class setting.'); |
||
| 160 | } |
||
| 161 | |||
| 162 | if (empty($options['linkClass'])) { |
||
| 163 | throw new Exception('Relationship type many-many option requires a linkClass setting.'); |
||
| 164 | } |
||
| 165 | |||
| 166 | if (empty($options['linkLocal'])) { |
||
| 167 | $options['linkLocal'] = $classShortName . 'ID'; |
||
| 168 | } |
||
| 169 | |||
| 170 | if (empty($options['linkForeign'])) { |
||
| 171 | $foreignShortname = basename(str_replace('\\', '/', $options['class']::$rootClass)); |
||
| 172 | $options['linkForeign'] = $foreignShortname . 'ID'; |
||
| 173 | } |
||
| 174 | |||
| 175 | if (empty($options['local'])) { |
||
| 176 | $options['local'] = 'ID'; |
||
| 177 | } |
||
| 178 | |||
| 179 | if (empty($options['foreign'])) { |
||
| 180 | $options['foreign'] = 'ID'; |
||
| 181 | } |
||
| 182 | |||
| 183 | if (!isset($options['indexField'])) { |
||
| 184 | $options['indexField'] = false; |
||
| 185 | } |
||
| 186 | |||
| 187 | if (!isset($options['conditions'])) { |
||
| 188 | $options['conditions'] = []; |
||
| 189 | } |
||
| 190 | |||
| 191 | if (!isset($options['order'])) { |
||
| 192 | $options['order'] = false; |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | if (static::isVersioned() && $options['type'] == 'history') { |
||
| 197 | if (empty($options['class'])) { |
||
| 198 | $options['class'] = get_called_class(); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | return $options; |
||
| 203 | } |
||
| 300 |