| Conditions | 2 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 32 |
| 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 |
||
| 29 | public function getConfigTreeBuilder(): TreeBuilder |
||
| 30 | { |
||
| 31 | $treeBuilder = new TreeBuilder(); |
||
| 32 | |||
| 33 | /** @var ArrayNodeDefinition $rootNode */ |
||
| 34 | $rootNode = $treeBuilder->root('setono_sylius_scheduler'); |
||
| 35 | |||
| 36 | $rootNodeChildren = $rootNode->children(); |
||
| 37 | $rootNodeChildren->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM); |
||
| 38 | |||
| 39 | // Wipe logs in X days after command execution |
||
| 40 | // Specify 0 to never wipe logs |
||
| 41 | $rootNodeChildren->scalarNode('wipe_logs_in')->defaultValue(0); |
||
| 42 | |||
| 43 | // We can specify emails to receive error reports on every Job |
||
| 44 | // But here we can specify emails which receive error reports for all Jobs |
||
| 45 | $rootNodeChildren->arrayNode('error_report_emails') |
||
| 46 | ->treatNullLike([]) |
||
| 47 | ->beforeNormalization()->castToArray()->end() |
||
| 48 | ->beforeNormalization() |
||
| 49 | ->always(function (array $emails) { |
||
| 50 | foreach ($emails as $email) { |
||
| 51 | Assert::true((bool) filter_var($email, FILTER_VALIDATE_EMAIL), sprintf( |
||
| 52 | "You should provide valid email. '%s' not looks like valid email.", |
||
| 53 | |||
| 54 | )); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $emails; |
||
| 58 | }) |
||
| 59 | ->end() |
||
| 60 | ->scalarPrototype() |
||
|
|
|||
| 61 | ->cannotBeEmpty() |
||
| 62 | ; |
||
| 63 | |||
| 64 | $defaultOptionsNode = $rootNode |
||
| 65 | ->children() |
||
| 66 | ->arrayNode('queue_options_defaults') |
||
| 67 | ->addDefaultsIfNotSet() |
||
| 68 | ; |
||
| 69 | $this->addQueueOptions($defaultOptionsNode); |
||
| 70 | |||
| 71 | $queueOptionsNode = $rootNode |
||
| 72 | ->children() |
||
| 73 | ->arrayNode('queue_options') |
||
| 74 | ->useAttributeAsKey('queue') |
||
| 75 | ->prototype('array') |
||
| 76 | ->end() |
||
| 77 | ; |
||
| 78 | $this->addQueueOptions($queueOptionsNode); |
||
| 79 | |||
| 80 | $this->addResourcesSection($rootNode); |
||
| 81 | |||
| 82 | return $treeBuilder; |
||
| 83 | } |
||
| 148 |