| Conditions | 20 |
| Paths | 65 |
| Total Lines | 101 |
| Code Lines | 53 |
| 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 |
||
| 87 | public function getAllVariables(): MapperVariables |
||
| 88 | { |
||
| 89 | $thisName = $this->name(); |
||
| 90 | |||
| 91 | if (!isset(MapperCache::me()->allVariables[$thisName])) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * All available variables |
||
| 95 | * Columns are always PUBLIC |
||
| 96 | * Complex, Constraints and Embedded are always PROTECTED |
||
| 97 | */ |
||
| 98 | $allVars = get_object_vars($this); |
||
| 99 | $publicVars = Utils::getObjectVars($this); |
||
| 100 | $protectedVars = Utils::arrayDiff($allVars, $publicVars); |
||
| 101 | |||
| 102 | $constraints = []; |
||
| 103 | $embedded = []; |
||
| 104 | $complex = []; |
||
| 105 | $columns = []; |
||
| 106 | |||
| 107 | foreach ($publicVars as $varName => $varValue) { |
||
| 108 | $this->checkProperty($varValue, $varName); |
||
| 109 | $columns[$varName] = $varValue; |
||
| 110 | } |
||
| 111 | |||
| 112 | foreach ($protectedVars as $varName => $varValue) { |
||
| 113 | $this->checkProperty($varValue, $varName); |
||
| 114 | |||
| 115 | if (isset($varValue[Constraint::LOCAL_COLUMN])) { |
||
| 116 | $constraints[$varName] = $varValue; |
||
| 117 | } else { |
||
| 118 | if (isset($varValue[Embedded::NAME])) { |
||
| 119 | $embedded[$varName] = $varValue; |
||
| 120 | } else if (isset($varValue[Complex::TYPE])) { |
||
| 121 | $complex[$varName] = $varValue; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | /** ----------------------COMPLEX------------------------ */ |
||
| 127 | foreach ($complex as $complexName => $complexValue) { |
||
| 128 | $this->$complexName = new Complex($complexValue); |
||
| 129 | MapperCache::me()->complex[$thisName][$complexName] = $this->$complexName; |
||
| 130 | } |
||
| 131 | // У нас может не быть комплексов |
||
| 132 | if (!isset(MapperCache::me()->complex[$thisName])) { |
||
| 133 | MapperCache::me()->complex[$thisName] = []; |
||
| 134 | } |
||
| 135 | /** ----------------------EMBEDDED------------------------ */ |
||
| 136 | foreach ($embedded as $embeddedName => $embeddedValue) { |
||
| 137 | $this->$embeddedName = new Embedded($embeddedValue); |
||
| 138 | MapperCache::me()->embedded[$thisName][$embeddedName] = $this->$embeddedName; |
||
| 139 | } |
||
| 140 | // У нас может не быть эмбедов |
||
| 141 | if (!isset(MapperCache::me()->embedded[$thisName])) { |
||
| 142 | MapperCache::me()->embedded[$thisName] = []; |
||
| 143 | } |
||
| 144 | /** ----------------------COLUMNS------------------------ */ |
||
| 145 | if (!isset(MapperCache::me()->columns[$thisName])) { |
||
| 146 | foreach ($columns as $columnName => $columnValue) { |
||
| 147 | $this->$columnName = new Column($columnValue); |
||
| 148 | MapperCache::me()->columns[$thisName][$columnName] = $this->$columnName; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | // У нас может не быть колонок |
||
| 152 | if (!isset(MapperCache::me()->columns[$thisName])) { |
||
| 153 | MapperCache::me()->columns[$thisName] = []; |
||
| 154 | } |
||
| 155 | /** ----------------------CONSTRAINTS------------------------ */ |
||
| 156 | $temporaryConstraints = []; |
||
| 157 | if (!isset(MapperCache::me()->constraints[$thisName])) { |
||
| 158 | $entityClass = get_parent_class($this); |
||
| 159 | |||
| 160 | foreach ($constraints as $constraintName => $constraintValue) { |
||
| 161 | $temporaryConstraint = new Constraint($constraintValue); |
||
| 162 | // we asking provide self instance while table still not ready |
||
| 163 | //$temporaryConstraint->localTable = $this->getTable(); |
||
| 164 | |||
| 165 | // If we use View - we do not always need to define constraint fields |
||
| 166 | if ($entityClass !== View::class && is_string($temporaryConstraint->localColumn)) { |
||
| 167 | $temporaryConstraint->localColumn = $this->findColumnByOriginName($temporaryConstraint->localColumn); |
||
| 168 | } |
||
| 169 | $temporaryConstraints[$constraintName] = $temporaryConstraint; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | // У нас может не быть констрейнтов |
||
| 174 | if (!isset(MapperCache::me()->constraints[$thisName])) { |
||
| 175 | MapperCache::me()->constraints[$thisName] = []; |
||
| 176 | } |
||
| 177 | MapperCache::me()->allVariables[$thisName] = new MapperVariables($columns, $constraints, $embedded, $complex); |
||
| 178 | |||
| 179 | // Now fill constraint as map is ready |
||
| 180 | foreach ($temporaryConstraints as $constraintName => $temporaryConstraint) { |
||
| 181 | $temporaryConstraint->localTable = $this->getTable(); |
||
| 182 | $this->$constraintName = $temporaryConstraint; |
||
| 183 | MapperCache::me()->constraints[$thisName][$constraintName] = $this->$constraintName; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | return MapperCache::me()->allVariables[$thisName]; |
||
| 188 | } |
||
| 397 |