Conditions | 9 |
Paths | 3 |
Total Lines | 75 |
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 |
||
42 | public function testProcess($force, array $services): void |
||
43 | { |
||
44 | $container = $this->createMock(ContainerBuilder::class); |
||
45 | |||
46 | $container |
||
47 | ->expects($this->any()) |
||
48 | ->method('hasDefinition') |
||
49 | ->willReturnCallback(static function ($id) { |
||
50 | if ('simplethings_entityaudit.config' === $id) { |
||
51 | return true; |
||
52 | } |
||
53 | }) |
||
54 | ; |
||
55 | |||
56 | $container |
||
57 | ->expects($this->any()) |
||
58 | ->method('getParameter') |
||
59 | ->willReturnCallback(static function ($id) use ($force) { |
||
60 | if ('sonata_doctrine_orm_admin.audit.force' === $id) { |
||
61 | return $force; |
||
62 | } |
||
63 | |||
64 | if ('simplethings.entityaudit.audited_entities' === $id) { |
||
65 | return []; |
||
66 | } |
||
67 | }) |
||
68 | ; |
||
69 | |||
70 | $container |
||
71 | ->expects($this->any()) |
||
72 | ->method('findTaggedServiceIds') |
||
73 | ->willReturnCallback(static function ($id) use ($services) { |
||
74 | if ('sonata.admin' === $id) { |
||
75 | $tags = []; |
||
76 | |||
77 | foreach ($services as $id => $service) { |
||
78 | $attributes = ['manager_type' => 'orm']; |
||
79 | |||
80 | if (null !== $audit = $service['audit']) { |
||
81 | $attributes['audit'] = $audit; |
||
82 | } |
||
83 | |||
84 | $tags[$id] = [0 => $attributes]; |
||
85 | } |
||
86 | |||
87 | return $tags; |
||
88 | } |
||
89 | }) |
||
90 | ; |
||
91 | |||
92 | $container |
||
93 | ->expects($this->any()) |
||
94 | ->method('getDefinition') |
||
95 | ->willReturnCallback(static function ($id) { |
||
96 | return new Definition(null, [null, $id]); |
||
97 | }) |
||
98 | ; |
||
99 | |||
100 | $expectedAuditedEntities = []; |
||
101 | |||
102 | foreach ($services as $id => $service) { |
||
103 | if ($service['audited']) { |
||
104 | $expectedAuditedEntities[] = $id; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | $container |
||
109 | ->expects($this->once()) |
||
110 | ->method('setParameter') |
||
111 | ->with('simplethings.entityaudit.audited_entities', $expectedAuditedEntities) |
||
112 | ; |
||
113 | |||
114 | $compilerPass = new AddAuditEntityCompilerPass(); |
||
115 | $compilerPass->process($container); |
||
116 | } |
||
117 | } |
||
118 |