| Total Complexity | 11 | 
| Total Lines | 74 | 
| Duplicated Lines | 4.05 % | 
| Changes | 1 | ||
| Bugs | 1 | Features | 0 | 
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php | ||
| 12 | class ScriptController extends Controller | ||
| 13 | { | ||
| 14 | public function redisAction() | ||
| 15 |     { | ||
| 16 | $clients = []; | ||
| 17 |         foreach ($this->container->getServiceIds() as $id) { | ||
| 1 ignored issue–
                            show | |||
| 18 | View Code Duplication |             if (substr($id, 0, 9) === 'snc_redis' && $this->container->get($id) instanceof Client) { | |
| 19 | $clients[] = $id; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 |         foreach ($clients as $snc) { | ||
| 24 | $this->container->get($snc)->flushdb(); | ||
| 25 | } | ||
| 26 | |||
| 27 | return new JsonResponse(['success' => 1], 200, [ | ||
| 28 | 'Cache-Control' => 'no-cache', | ||
| 29 | ]); | ||
| 30 | } | ||
| 31 | |||
| 32 | public function cacheAction() | ||
| 33 |     { | ||
| 34 | global $kernel; | ||
| 35 | |||
| 36 |         if ('AppCache' === get_class($kernel)) { | ||
| 37 | $kernel = $kernel->getKernel(); | ||
| 38 | } | ||
| 39 | |||
| 40 | $commands = [ | ||
| 41 | 'clear', | ||
| 42 | 'warmup', | ||
| 43 | ]; | ||
| 44 |         foreach ($commands as $command) { | ||
| 45 | $application = new Application($kernel); | ||
| 46 | $application->setAutoExit(false); | ||
| 47 | $input = new ArrayInput([ | ||
| 48 | 'command' => 'cache:'.$command, | ||
| 49 | '--env' => $kernel->getEnvironment(), | ||
| 50 | ]); | ||
| 51 | $application->run($input); | ||
| 52 | } | ||
| 53 | |||
| 54 | return new JsonResponse(['success' => 1], 200, [ | ||
| 55 | 'Cache-Control' => 'no-cache', | ||
| 56 | ]); | ||
| 57 | } | ||
| 58 | |||
| 59 | public function lexikAction() | ||
| 77 | ]); | ||
| 78 | } | ||
| 79 | |||
| 80 | public function generateAction() | ||
| 89 |