Completed
Pull Request — 4.0 (#4084)
by
unknown
06:18
created

CssController::index()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 31

Duplication

Lines 31
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
nc 10
nop 1
dl 31
loc 31
rs 8.8017
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.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
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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