| Conditions | 7 |
| Paths | 7 |
| Total Lines | 67 |
| 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 |
||
| 83 | private function getTypeCode( |
||
| 84 | string $classname, |
||
| 85 | string $enumClass, |
||
| 86 | string $type, |
||
| 87 | string $name, |
||
| 88 | $defaultOnNull |
||
| 89 | ): string { |
||
| 90 | $code = <<<PHP |
||
| 91 | public const NAME = '$name'; |
||
| 92 | |||
| 93 | protected function getEnumClass(): string |
||
| 94 | { |
||
| 95 | return \\{$enumClass}::class; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function getName(): string |
||
| 99 | { |
||
| 100 | return static::NAME; |
||
| 101 | } |
||
| 102 | PHP; |
||
| 103 | switch ($type) { |
||
| 104 | case self::TYPE_INT: |
||
| 105 | $baseClass = AbstractIntegerEnumType::class; |
||
| 106 | break; |
||
| 107 | case self::TYPE_STRING: |
||
| 108 | $baseClass = AbstractEnumType::class; |
||
| 109 | |||
| 110 | if ($defaultOnNull !== null) { |
||
| 111 | $defaultOnNullCode = $this->valueAsCode($defaultOnNull); |
||
| 112 | $code .= <<<PHP |
||
| 113 | |||
| 114 | protected function onNullFromDatabase() |
||
| 115 | { |
||
| 116 | return \\{$enumClass}::get({$defaultOnNullCode}); |
||
| 117 | } |
||
| 118 | |||
| 119 | protected function onNullFromPhp() |
||
| 120 | { |
||
| 121 | return {$defaultOnNullCode}; |
||
| 122 | } |
||
| 123 | PHP; |
||
| 124 | } |
||
| 125 | break; |
||
| 126 | case self::TYPE_ENUM: |
||
| 127 | $baseClass = AbstractEnumSQLDeclarationType::class; |
||
| 128 | break; |
||
| 129 | case self::TYPE_JSON_COLLECTION: |
||
| 130 | $baseClass = AbstractJsonCollectionEnumType::class; |
||
| 131 | break; |
||
| 132 | case self::TYPE_CSV_COLLECTION: |
||
| 133 | $baseClass = AbstractCsvCollectionEnumType::class; |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | throw new LogicException(sprintf('Unexpected type "%s"', $type)); |
||
| 137 | } |
||
| 138 | |||
| 139 | return <<<PHP |
||
| 140 | |||
| 141 | if (!\class_exists($classname::class)) { |
||
| 142 | class $classname extends \\{$baseClass} |
||
| 143 | { |
||
| 144 | $code |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | PHP; |
||
| 149 | } |
||
| 150 | |||
| 175 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.