Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 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 |
||
44 | public function testProcess(): void |
||
45 | { |
||
46 | $user = $this->createMock(User::class); |
||
47 | $user->expects(self::once()) |
||
48 | ->method('getId') |
||
49 | ->willReturn(123); |
||
50 | |||
51 | $user->expects(self::once()) |
||
52 | ->method('getLogin') |
||
53 | ->willReturn('my login'); |
||
54 | |||
55 | CurrentUser::set($user); |
||
56 | putenv('REMOTE_ADDR=127.0.0.1'); |
||
57 | $_REQUEST = [ |
||
58 | 'password' => 'sensitive', |
||
59 | 'variables' => [ |
||
60 | 'other' => [ |
||
61 | 'password' => 'sensitive', |
||
62 | 'passwordConfirmation' => 'sensitive', |
||
63 | 'foo' => 123, |
||
64 | ], |
||
65 | ], |
||
66 | ]; |
||
67 | |||
68 | $completed = new RecordCompleter('https://example.com'); |
||
69 | $completedRecord = $completed->__invoke( |
||
70 | new LogRecord( |
||
71 | new DateTimeImmutable(), |
||
72 | '', |
||
73 | Level::Error, |
||
74 | 'some message', |
||
75 | [ |
||
76 | 'errno' => 1, |
||
77 | 'password' => 'sensitive', |
||
78 | ] |
||
79 | ) |
||
80 | ); |
||
81 | $actual = $completedRecord->extra; |
||
82 | |||
83 | self::assertSame([ |
||
84 | 'errno' => 1, |
||
85 | 'password' => '***REDACTED***', |
||
86 | ], $completedRecord->context); |
||
87 | self::assertSame(123, $actual['creator_id']); |
||
88 | self::assertSame('my login', $actual['login']); |
||
89 | self::assertIsString($actual['url']); |
||
90 | self::assertIsString($actual['referer']); |
||
91 | self::assertSame([ |
||
92 | 'password' => '***REDACTED***', |
||
93 | 'variables' => [ |
||
94 | 'other' => [ |
||
95 | 'password' => '***REDACTED***', |
||
96 | 'passwordConfirmation' => '***REDACTED***', |
||
97 | 'foo' => 123, |
||
98 | ], |
||
99 | ], |
||
100 | ], json_decode($actual['request'], true)); |
||
101 | self::assertSame('127.0.0.1', $actual['ip']); |
||
102 | } |
||
104 |