Failed Conditions
Pull Request — 4.0 (#4844)
by chihiro
04:55
created

StatusController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 36 4
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\Order;
15
16
use Eccube\Controller\AbstractController;
17
use Eccube\Form\Type\Admin\OrderStatusType;
18
use Eccube\Repository\Master\OrderStatusColorRepository;
19
use Eccube\Repository\Master\OrderStatusRepository;
20
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
21
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\Routing\Annotation\Route;
24
25
class StatusController extends AbstractController
26
{
27
    /**
28
     * @var OrderStatusRepository
29
     */
30
    protected $orderStatusRepository;
31
32
33
    /**
34
     * @var OrderStatusColorRepository
35
     */
36
    protected $orderStatusColorRepository;
37
38
    public function __construct(
39
        OrderStatusRepository $orderStatusRepository,
40
        OrderStatusColorRepository $orderStatusColorRepository
41
    ) {
42
        $this->orderStatusRepository = $orderStatusRepository;
43
        $this->orderStatusColorRepository = $orderStatusColorRepository;
44
    }
45
46
    /**
47
     * 受注ステータス編集画面.
48
     *
49
     * @Route("/%eccube_admin_route%/order/status", name="admin_order_status")
50
     * @Template("@admin/Order/status.twig")
51
     */
52
    public function index(Request $request)
53
    {
54
        $OrderStatuses = $this->orderStatusRepository->findBy([], ['sort_no' => 'ASC']);
55
        $builder = $this->formFactory->createBuilder();
56
        $builder
57
            ->add(
58
                'OrderStatuses',
59
                CollectionType::class,
60
                [
61
                    'entry_type' => OrderStatusType::class,
62
                    'data' => $OrderStatuses,
63
                ]
64
            );
65
        $form = $builder->getForm();
66
        $form->handleRequest($request);
67
68
        if ($form->isSubmitted() && $form->isValid()) {
69
            foreach ($form['OrderStatuses'] as $child) {
70
                $OrderStatus = $child->getData();
71
                $this->entityManager->persist($OrderStatus);
72
73
                $OrderStatusColor = $this->orderStatusColorRepository->find($OrderStatus->getId());
74
                $OrderStatusColor->setName($child['color']->getData());
75
                $this->entityManager->persist($OrderStatusColor);
0 ignored issues
show
Bug introduced by
It seems like $OrderStatusColor defined by $this->orderStatusColorR...($OrderStatus->getId()) on line 73 can also be of type null; however, Doctrine\Common\Persiste...bjectManager::persist() does only seem to accept object, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
            }
77
            $this->entityManager->flush();
78
79
            $this->addSuccess('admin.common.save_complete', 'admin');
80
81
            return $this->redirectToRoute('admin_order_status');
82
        }
83
84
        return [
85
            'form' => $form->createView(),
86
        ];
87
    }
88
}
89