| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 50 | protected function getContainer($jobManager, $runManager, $jobTimingManager, $liveJobsGridSourceClass, $gridSourceClass) |
||
| 51 | { |
||
| 52 | $container = new Container(); |
||
| 53 | $container->setParameter('dtc_grid.theme.css', []); |
||
| 54 | $container->setParameter('dtc_grid.theme.js', []); |
||
| 55 | $container->setParameter('dtc_grid.jquery', ['url' => 'https://something']); |
||
| 56 | $container->setParameter('dtc_queue.class_job', $jobManager->getJobClass()); |
||
| 57 | $container->setParameter('dtc_queue.class_job_archive', $jobManager->getJobArchiveClass()); |
||
| 58 | $container->setParameter('dtc_queue.class_run', $runManager->getRunClass()); |
||
| 59 | $container->setParameter('dtc_queue.class_run_archive', $runManager->getRunArchiveClass()); |
||
| 60 | $container->setParameter('dtc_queue.admin.chartjs', ''); |
||
| 61 | $container->setParameter('dtc_queue.default_manager', 'orm'); |
||
| 62 | $container->setParameter('dtc_queue.record_timings', true); |
||
| 63 | $container->setParameter('dtc_queue.record_timings_timezone_offset', 0); |
||
| 64 | $container->set('dtc_queue.job_manager', $jobManager); |
||
| 65 | $container->set('dtc_queue.job_timing_manager', $jobTimingManager); |
||
| 66 | $container->set('dtc_queue.worker_manager', new WorkerManager($jobManager, new EventDispatcher())); |
||
| 67 | $rendererFactory = new RendererFactory( |
||
| 68 | new Router(new YamlFileLoader(new FileLocator(__DIR__)), 'test.yml'), |
||
| 69 | [ |
||
| 70 | 'theme.css' => [], |
||
| 71 | 'theme.js' => [], |
||
| 72 | 'page_div_style' => 'somestyle', |
||
| 73 | 'jquery' => [], |
||
| 74 | 'purl' => [], |
||
| 75 | 'datatables.css' => [], |
||
| 76 | 'datatables.js' => [], |
||
| 77 | 'jq_grid.css' => [], |
||
| 78 | 'jq_grid.js' => [], ] |
||
| 79 | ); |
||
| 80 | $templates = ['@DtcQueue/Queue/grid.html.twig' => file_get_contents(__DIR__.'/../../Resources/views/Queue/grid.html.twig'), |
||
| 81 | 'DtcGridBundle:Page:datatables.html.twig' => file_get_contents(__DIR__.'/../../vendor/mmucklo/grid-bundle/Resources/views/Grid/datatables.html.twig'), ]; |
||
| 82 | $twigEngine = new TwigEngine(new Environment(new \Twig_Loader_Array($templates)), new TemplateNameParser(), new FileLocator(__DIR__)); |
||
| 83 | $rendererFactory->setTwigEngine($twigEngine); |
||
| 84 | |||
| 85 | $container->set('twig', $twigEngine); |
||
| 86 | |||
| 87 | $container->set('dtc_grid.renderer.factory', $rendererFactory); |
||
| 88 | $liveJobsGridSource = new $liveJobsGridSourceClass($jobManager); |
||
| 89 | $container->set('dtc_queue.grid_source.jobs_waiting.orm', $liveJobsGridSource); |
||
| 90 | $liveJobsGridSource = new $liveJobsGridSourceClass($jobManager); |
||
| 91 | $liveJobsGridSource->setRunning(true); |
||
| 92 | $container->set('dtc_queue.grid_source.jobs_running.orm', $liveJobsGridSource); |
||
| 93 | $container->set('dtc_queue.job_manager', $jobManager); |
||
| 94 | $gridSourceManager = new GridSourceManager(new AnnotationReader(), __DIR__); |
||
| 95 | $container->set('dtc_grid.manager.source', $gridSourceManager); |
||
| 96 | $gridSourceJob = new $gridSourceClass($jobManager->getObjectManager(), $jobManager->getJobClass()); |
||
| 97 | $gridSourceJob->autodiscoverColumns(); |
||
| 98 | $gridSourceManager->add($jobManager->getJobClass(), $gridSourceJob); |
||
| 99 | $gridSourceJobArchive = new $gridSourceClass($jobManager->getObjectManager(), $jobManager->getJobArchiveClass()); |
||
| 100 | $gridSourceJobArchive->autodiscoverColumns(); |
||
| 101 | $gridSourceManager->add($jobManager->getJobArchiveClass(), $gridSourceJobArchive); |
||
| 102 | $gridSourceRun = new $gridSourceClass($runManager->getObjectManager(), $runManager->getRunClass()); |
||
| 103 | $gridSourceRun->autodiscoverColumns(); |
||
| 104 | $gridSourceManager->add($runManager->getRunClass(), $gridSourceRun); |
||
| 105 | $gridSourceRunArchive = new $gridSourceClass($runManager->getObjectManager(), $runManager->getRunArchiveClass()); |
||
| 106 | $gridSourceRunArchive->autodiscoverColumns(); |
||
| 107 | $gridSourceManager->add($runManager->getRunArchiveClass(), $gridSourceRunArchive); |
||
| 108 | |||
| 109 | return $container; |
||
| 110 | } |
||
| 111 | } |
||
| 112 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.