Completed
Pull Request — master (#1391)
by Kentaro
18:00
created

MypageController::order()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5
Metric Value
dl 0
loc 30
ccs 6
cts 6
cp 1
rs 8.439
cc 5
eloc 17
nc 7
nop 3
crap 5
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Controller\Mypage;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Controller\AbstractController;
30
use Eccube\Exception\CartException;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
33
34
class MypageController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
35
{
36 2
    public function login(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
39
            return $app->redirect($app->url('mypage'));
40
        }
41
42
        /* @var $form \Symfony\Component\Form\FormInterface */
43
        $builder = $app['form.factory']
44
            ->createNamedBuilder('', 'customer_login');
45
46 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
47
            $Customer = $app->user();
48
            if ($Customer) {
49
                $builder->get('login_email')->setData($Customer->getEmail());
50
            }
51
        }
52
53
        $form = $builder->getForm();
54
55 1
        return $app->render('Mypage/login.twig', array(
56
            'error' => $app['security.last_error']($request),
57 1
            'form' => $form->createView(),
58
        ));
59 2
    }
60
61
    /**
62
     * @param Application $app
63
     * @param Request     $request
64
     *
65
     * @return string
66
     */
67 1
    public function index(Application $app, Request $request)
68
    {
69
        $Customer = $app['user'];
70
71
        $app['orm.em']
72
            ->getFilters()
73
            ->enable('incomplete_order_status_hidden');
74
75
        // paginator
76
        $qb = $app['eccube.repository.order']->getQueryBuilderByCustomer($Customer);
77
        $pagination = $app['paginator']()->paginate(
78
            $qb,
79 1
            $request->get('pageno', 1),
80 1
            $app['config']['search_pmax']
81
        );
82
83 1
        return $app->render('Mypage/index.twig', array(
84
            'pagination' => $pagination,
85
        ));
86 1
    }
87
88
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
89
     * @param Application $app
90
     * @param Request     $request
91
     *
92
     * @return string
93
     */
94 2
    public function history(Application $app, Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
97
        /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */
98
        $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete');
99
        $softDeleteFilter->setExcludes(array(
100
            'Eccube\Entity\ProductClass',
101
        ));
102
103
        $Order = $app['eccube.repository.order']->findOneBy(array(
104
            'id' => $id,
105 2
            'Customer' => $app->user(),
106
        ));
107 2
        if (!$Order) {
108
            throw new NotFoundHttpException();
109
        }
110
111 1
        return $app->render('Mypage/history.twig', array(
112
            'Order' => $Order,
113
        ));
114 2
    }
115
116
    /**
117
     * @param Application $app
118
     * @param Request     $request
119
     * @param id     $id
0 ignored issues
show
introduced by
Expected 10 spaces after parameter type; 5 found
Loading history...
120
     *
121
     * @return string
122
     */
123 1
    public function order(Application $app, Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    {
125
126
        $this->isTokenValid($app);
127
128
        $Customer = $app->user();
129
130
        /* @var $Order \Eccube\Entity\Order */
131
        $Order = $app['eccube.repository.order']->findOneBy(array(
132
            'id' => $id,
133
            'Customer' => $Customer,
134
        ));
135 1
        if (!$Order) {
136
            throw new NotFoundHttpException();
137
        }
138
139 1
        foreach ($Order->getOrderDetails() as $OrderDetail) {
140
            try {
141
                if ($OrderDetail->getProduct()) {
142
                    $app['eccube.service.cart']->addProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getQuantity())->save();
143
                } else {
144
                    $app->addRequestError('cart.product.delete');
145 1
                }
146
            } catch (CartException $e) {
147
                $app->addRequestError($e->getMessage());
148 1
            }
149
        }
150
151
        return $app->redirect($app->url('cart'));
152 1
    }
153
154
    /**
155
     * @param Application $app
156
     * @param Request     $request
157
     *
158
     * @return string
159
     */
160 1
    public function favorite(Application $app, Request $request)
161
    {
162
        $BaseInfo = $app['eccube.repository.base_info']->get();
163
164
        if ($BaseInfo->getOptionFavoriteProduct() == Constant::ENABLED) {
165
            $Customer = $app->user();
166
167
            // paginator
168
            $qb = $app['eccube.repository.product']->getFavoriteProductQueryBuilderByCustomer($Customer);
169
            $pagination = $app['paginator']()->paginate(
170
                $qb,
171 1
                $request->get('pageno', 1),
172 1
                $app['config']['search_pmax']
173
            );
174
175 1
            return $app->render('Mypage/favorite.twig', array(
176
                'pagination' => $pagination,
177
            ));
178
        } else {
179
            throw new NotFoundHttpException();
180
        }
181 1
    }
182
183
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
184
     * @param Application $app
185
     * @param Request     $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
introduced by
Doc comment for parameter $request does not match actual variable name $id
Loading history...
186
     *
187
     * @return string
188
     */
189 1
    public function delete(Application $app, $id)
190
    {
191
        $this->isTokenValid($app);
192
193
        $Customer = $app->user();
194
195
        $Product = $app['eccube.repository.product']->find($id);
196 1
        if ($Product) {
197
            $app['eccube.repository.customer_favorite_product']->deleteFavorite($Customer, $Product);
198
        }
199
200
        return $app->redirect($app->url('mypage_favorite'));
201 1
    }
202
}
203