Failed Conditions
Pull Request — experimental/3.1 (#2486)
by
unknown
68:04 queued 25:47
created

ApplicationTrait::addRequestError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Eccube\Application;
4
5
use Eccube\Event\TemplateEvent;
6
use Monolog\Logger;
7
use Symfony\Component\Form\FormBuilder;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpFoundation\StreamedResponse;
11
use Symfony\Component\HttpKernel\HttpKernelInterface;
12
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
13
use Symfony\Component\Security\Core\User\UserInterface;
14
15
trait ApplicationTrait
16
{
17
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$message" missing
Loading history...
introduced by
Doc comment for parameter "$namespace" missing
Loading history...
18
     * Application Shortcut Methods
19
     */
20 82
    public function addSuccess($message, $namespace = 'front')
21
    {
22 82
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.success', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
23
    }
24
25 8
    public function addError($message, $namespace = 'front')
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
26
    {
27 8
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.error', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
28
    }
29
30
    public function addDanger($message, $namespace = 'front')
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
31
    {
32
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.danger', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
33
    }
34
35 4
    public function addWarning($message, $namespace = 'front')
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
36
    {
37 4
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.warning', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
38
    }
39
40 1
    public function addInfo($message, $namespace = 'front')
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
41
    {
42 1
        $this['session']->getFlashBag()->add('eccube.' . $namespace . '.info', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
43
    }
44
45
    public function addRequestError($message, $namespace = 'front')
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
46
    {
47
        $this['session']->getFlashBag()->set('eccube.' . $namespace . '.request.error', $message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
48
    }
49
50
    public function clearMessage()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
51
    {
52
        $this['session']->getFlashBag()->clear();
53
    }
54
55
    public function deleteMessage()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
56
    {
57
        $this->clearMessage();
58
        $this->addWarning('admin.delete.warning', 'admin');
59
    }
60
61
    public function setLoginTargetPath($targetPath, $namespace = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
62
    {
63
        if (is_null($namespace)) {
64
            $this['session']->getFlashBag()->set('eccube.login.target.path', $targetPath);
65
        } else {
66
            $this['session']->getFlashBag()->set('eccube.' . $namespace . '.login.target.path', $targetPath);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
67
        }
68
    }
69
70 329
    public function isAdminRequest()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
71
    {
72 329
        return isset($this['admin']) ? $this['admin'] : null;
73
    }
74
75 327
    public function isFrontRequest()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
76
    {
77 327
        return isset($this['front']) ? $this['front'] : null;
78
    }
79
80
    /**
81
     * 他のコントローラにリクエストをフォワードします.
82
     *
83
     * @param string $path フォワード先のパス
0 ignored issues
show
introduced by
Expected 14 spaces after parameter name; 1 found
Loading history...
84
     * @param array $requestParameters
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
85
     * @return Response
86
     */
87 17
    public function forward($path, array $requestParameters = [])
88
    {
89 17
        $request = $this['request_stack']->getCurrentRequest();
90
91 17
        $subRequest = Request::create(
92 17
            $path,
93 17
            $request->getMethod(),
94 17
            $requestParameters,
95 17
            $request->cookies->all(),
96 17
            [],
97 17
            $request->server->all()
98
        );
99 17
        if ($request->getSession()) {
100 17
            $subRequest->setSession($request->getSession());
101
        }
102
103 17
        return $this->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
0 ignored issues
show
Bug introduced by
It seems like handle() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
104
    }
105
106
    /**
107
     * フォワードをチェーンでつなげます.
108
     *
109
     * @param string $path フォワード先のパス
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 14 spaces after parameter name; 1 found
Loading history...
110
     * @param array $requestParameters
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
111
     * @param Response $response
112
     * @return Application
113
     */
114
    public function forwardChain($path, array $requestParameters = [], Response &$response = null)
115
    {
116
        $response = $this->forward($path, $requestParameters);
117
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
118
    }
119
120
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$key" missing
Loading history...
introduced by
Doc comment for parameter "$service" missing
Loading history...
121
     * コンテナに登録済のサービスを上書きする.
122
     * Pimple標準では再登録を行うと, `RuntimeException: Cannot override frozen service`が投げられるため,一度unsetしてから再登録を行う.
123
     * config系の変更程度に利用はとどめること
124
     *
125
     * @param $key
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
126
     * @param $service
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
127
     * @throws \InvalidArgumentException keyが存在しない場合.
128
     */
129 40
    public function overwrite($key, $service)
130
    {
131 40
        if (!$this->offsetExists($key)) {
0 ignored issues
show
Bug introduced by
It seems like offsetExists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
132
            throw new \InvalidArgumentException();
133
        }
134 40
        $this->offsetUnset($key);
0 ignored issues
show
Bug introduced by
It seems like offsetUnset() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
135 40
        $this[$key] = $service;
136
    }
137
}
138