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