These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of EC-CUBE |
||
5 | * |
||
6 | * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.ec-cube.co.jp/ |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Eccube\Controller\Admin\Content; |
||
15 | |||
16 | use Eccube\Controller\AbstractController; |
||
17 | use Eccube\Form\Type\Admin\MainEditType; |
||
18 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
19 | use Symfony\Component\Filesystem\Exception\IOException; |
||
20 | use Symfony\Component\Filesystem\Filesystem; |
||
21 | use Symfony\Component\Form\Extension\Core\Type\FormType; |
||
22 | use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
||
23 | use Symfony\Component\HttpFoundation\Request; |
||
24 | use Symfony\Component\Routing\Annotation\Route; |
||
25 | |||
26 | View Code Duplication | class CssController extends AbstractController |
|
0 ignored issues
–
show
|
|||
27 | { |
||
28 | /** |
||
29 | * @Route("/%eccube_admin_route%/content/css", name="admin_content_css") |
||
30 | * @Template("@admin/Content/css.twig") |
||
31 | */ |
||
32 | public function index(Request $request) |
||
33 | { |
||
34 | $builder = $this->formFactory |
||
35 | ->createBuilder(FormType::class) |
||
36 | ->add('css', TextareaType::class, [ |
||
37 | 'required' => false |
||
38 | ]); |
||
39 | $form = $builder->getForm(); |
||
40 | |||
41 | $cssPath = $this->getParameter('eccube_html_dir').'/user_data/assets/css/customize.css'; |
||
42 | if (file_exists($cssPath) && is_writable($cssPath)) { |
||
43 | $form->get('css')->setData(file_get_contents($cssPath)); |
||
44 | } |
||
45 | |||
46 | $form->handleRequest($request); |
||
47 | if ($form->isSubmitted() && $form->isValid()) { |
||
48 | $fs = new Filesystem(); |
||
49 | try { |
||
50 | $fs->dumpFile($cssPath, $form->get('css')->getData()); |
||
51 | $this->addSuccess('admin.common.save_complete', 'admin'); |
||
52 | return $this->redirectToRoute('admin_content_css'); |
||
53 | } catch (IOException $e) { |
||
54 | $message = trans('admin.common.save_error'); |
||
55 | $this->addError($message, 'admin'); |
||
56 | log_error($message, [$cssPath, $e]); |
||
57 | } |
||
58 | } |
||
59 | return [ |
||
60 | 'form' => $form->createView() |
||
61 | ]; |
||
62 | } |
||
63 | } |
||
64 |
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.