| Conditions | 7 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 42 |
| 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 |
||
| 39 | private function walletNode(string $name): ArrayNodeDefinition |
||
| 40 | { |
||
| 41 | return (new ArrayNodeDefinition($name)) |
||
| 42 | ->addDefaultsIfNotSet() |
||
| 43 | ->beforeNormalization() |
||
| 44 | ->ifTrue(function (array $config): bool { |
||
| 45 | return !isset($config['type']); |
||
| 46 | }) |
||
| 47 | ->then(function (array $config): array { |
||
| 48 | return ['type' => self::WALLET_FIXED, 'accounts' => $config]; |
||
| 49 | }) |
||
| 50 | ->end() |
||
| 51 | ->validate() |
||
| 52 | ->ifTrue(function (array $config): bool { |
||
| 53 | return self::WALLET_SERVICE === $config['type'] && empty($config['factory_service_id']); |
||
| 54 | }) |
||
| 55 | ->thenInvalid('Service id must be specified.') |
||
| 56 | ->end() |
||
| 57 | ->validate() |
||
| 58 | ->ifTrue(function (array $config): bool { |
||
| 59 | return self::WALLET_REDIS === $config['type'] && (empty($config['redis_client_id']) || empty($config['wallet_key'])); |
||
| 60 | }) |
||
| 61 | ->thenInvalid('Wallet key and Redis client must be specified.') |
||
| 62 | ->end() |
||
| 63 | ->validate() |
||
| 64 | ->ifTrue(function (array $config) { |
||
| 65 | return self::WALLET_MONGO === $config['type'] && (empty($config['mongo_client_id']) || empty($config['db_name']) || empty($config['collection_name'])); |
||
| 66 | }) |
||
| 67 | ->thenInvalid('Mongo client, database and collection name must be specified.') |
||
| 68 | ->end() |
||
| 69 | ->children() |
||
| 70 | ->enumNode('type') |
||
| 71 | ->values([self::WALLET_REDIS, self::WALLET_MONGO, self::WALLET_FIXED, self::WALLET_SERVICE]) |
||
| 72 | ->defaultValue(self::WALLET_FIXED) |
||
| 73 | ->end() |
||
| 74 | |||
| 75 | // Redis |
||
| 76 | ->scalarNode('redis_client_id')->cannotBeEmpty()->end() |
||
| 77 | ->scalarNode('wallet_key')->cannotBeEmpty()->end() |
||
| 78 | |||
| 79 | // Mongo |
||
| 80 | ->scalarNode('mongo_client_id')->cannotBeEmpty()->end() |
||
| 81 | ->scalarNode('db_name')->cannotBeEmpty()->end() |
||
| 82 | ->scalarNode('collection_name')->cannotBeEmpty()->end() |
||
| 83 | |||
| 84 | // Fixed |
||
| 85 | ->arrayNode('accounts') |
||
| 86 | ->useAttributeAsKey(true) |
||
| 87 | ->requiresAtLeastOneElement() |
||
| 88 | ->scalarPrototype() |
||
| 89 | ->isRequired() |
||
| 90 | ->end() |
||
| 91 | ->end() |
||
| 92 | |||
| 93 | // Service |
||
| 94 | ->scalarNode('factory_service_id')->cannotBeEmpty()->end() |
||
| 95 | ->end() |
||
| 96 | ; |
||
| 206 |