Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
47 | public function testAddlogAddsALogToTheLogger(): void |
||
48 | { |
||
49 | ($fullyLoadedRequestLoggerMock = $this->createLoggerMock()) |
||
50 | ->expects($this->once()) |
||
51 | ->method('log') |
||
52 | ->with(LogLevel::WARNING, 'The request looks suspicious.', [ |
||
53 | 'host_name' => gethostname(), |
||
54 | 'request_method' => 'GET', |
||
55 | 'uri' => 'http://foo.com/?bar=baz&qux=quux', |
||
56 | 'user_agent' => 'garply', |
||
57 | 'referer' => 'grault', |
||
58 | ]) |
||
59 | ; |
||
60 | |||
61 | /** @var LoggerInterface $fullyLoadedRequestLoggerMock */ |
||
62 | |||
63 | $fullyLoadedRequest = new Request([], [], [], [], [], [ |
||
64 | 'HTTP_HOST' => 'foo.com', |
||
65 | 'REQUEST_METHOD' => 'GET', |
||
66 | 'QUERY_STRING' => 'bar=baz&qux=quux', |
||
67 | 'HTTP_USER_AGENT' => 'garply', |
||
68 | 'HTTP_REFERER' => 'grault', |
||
69 | ]); |
||
70 | |||
71 | (new Envelope($fullyLoadedRequest, $fullyLoadedRequestLoggerMock)) |
||
72 | ->addLogEntry(LogLevel::WARNING, 'The request looks suspicious.') |
||
73 | ; |
||
74 | |||
75 | ($minimalRequestLoggerMock = $this->createLoggerMock()) |
||
76 | ->expects($this->once()) |
||
77 | ->method('log') |
||
78 | ->with(LogLevel::EMERGENCY, 'The request looks suspicious.', [ |
||
79 | 'host_name' => gethostname(), |
||
80 | 'request_method' => 'GET', |
||
81 | 'uri' => 'http://foo.com/?bar=baz&qux=quux', |
||
82 | ]) |
||
83 | ; |
||
84 | |||
85 | /** @var LoggerInterface $minimalRequestLoggerMock */ |
||
86 | |||
87 | $minimalRequest = new Request([], [], [], [], [], [ |
||
88 | 'HTTP_HOST' => 'foo.com', |
||
89 | 'REQUEST_METHOD' => 'GET', |
||
90 | 'QUERY_STRING' => 'bar=baz&qux=quux', |
||
91 | ]); |
||
92 | |||
93 | (new Envelope($minimalRequest, $minimalRequestLoggerMock)) |
||
94 | ->addLogEntry(LogLevel::EMERGENCY, 'The request looks suspicious.') |
||
95 | ; |
||
96 | |||
97 | ($postRequestLoggerMock = $this->createLoggerMock()) |
||
98 | ->expects($this->once()) |
||
99 | ->method('log') |
||
100 | ->with(LogLevel::EMERGENCY, 'The request looks suspicious.', [ |
||
101 | 'host_name' => gethostname(), |
||
102 | 'request_method' => 'POST', |
||
103 | 'uri' => 'http://foo.com/', |
||
104 | 'parameters' => [ |
||
105 | 'foo' => 'bar', |
||
106 | 'baz' => 'qux', |
||
107 | ], |
||
108 | ]) |
||
109 | ; |
||
110 | |||
111 | /** @var LoggerInterface $postRequestLoggerMock */ |
||
112 | |||
113 | $postRequest = new Request([], [ |
||
114 | 'foo' => 'bar', |
||
115 | 'baz' => 'qux', |
||
116 | ], [], [], [], [ |
||
117 | 'HTTP_HOST' => 'foo.com', |
||
118 | 'REQUEST_METHOD' => 'POST', |
||
119 | ]); |
||
120 | |||
121 | (new Envelope($postRequest, $postRequestLoggerMock)) |
||
122 | ->addLogEntry(LogLevel::EMERGENCY, 'The request looks suspicious.') |
||
123 | ; |
||
126 |