Failed Conditions
Pull Request — 3.0.9-dev (#1466)
by k-yamamura
74:16 queued 48:01
created

LogController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 60
ccs 12
cts 24
cp 0.5
rs 10
c 2
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B index() 0 42 3
A parseLogFile() 0 14 3
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller\Admin\Setting\System;
26
27
use Eccube\Application;
28
use Eccube\Event\EccubeEvents;
29
use Eccube\Event\EventArgs;
30
use Symfony\Component\HttpFoundation\Request;
31
32
class LogController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
33
{
34 1
    public function index(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
35
    {
36 1
        $formData = array();
37
        // default
38
        $formData['files'] = 'site_'.date('Y-m-d').'.log';
39 1
        $formData['line_max'] = '50';
40
41
        $builder = $app['form.factory']
42
            ->createBuilder('admin_system_log');
43
44
        $event = new EventArgs(
45
            array(
46
                'builder' => $builder,
47
                'data' => $formData,
48 1
            ),
49
            $request
50
        );
51
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_LOG_INDEX_INITIALIZE, $event);
52
53
        $form = $builder->getForm();
54
55
        if ('POST' === $request->getMethod()) {
56
            $form->handleRequest($request);
57
            if ($form->isValid()) {
58
                $formData = $form->getData();
59
            }
60
            $event = new EventArgs(
61
                array(
62
                    'form' => $form,
63
                ),
64
                $request
65
            );
66
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_LOG_INDEX_COMPLETE, $event);
67
        }
68
69
        $logFile = $app['config']['root_dir'].'/app/log/'.$formData['files'];
70
71 1
        return $app->render('Setting/System/log.twig', array(
72 1
            'form' => $form->createView(),
73 1
            'log' => $this->parseLogFile($logFile, $formData),
74
        ));
75 1
    }
76
77 1
    private function parseLogFile($logFile, $formData)
78
    {
79 1
        $log = array();
80
81
        foreach (array_reverse(file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) as $line) {
82
            // 上限に達した場合、処理を抜ける
83
            if (count($log) >= $formData['line_max']) {
84 1
                break;
85
            }
86
87
            $log[] = $line;
88
        }
89 1
        return $log;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
90
    }
91
}
92