Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 40 |
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 |
||
33 | public function testProcess() |
||
34 | { |
||
35 | if (!class_exists(TransactionMiddleware::class)) { |
||
36 | $this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
||
37 | } |
||
38 | |||
39 | $this->container->shouldReceive('hasParameter') |
||
|
|||
40 | ->with('doctrine.entity_managers') |
||
41 | ->once() |
||
42 | ->andReturn(true); |
||
43 | |||
44 | $this->container->shouldReceive('getParameter') |
||
45 | ->with('doctrine.entity_managers') |
||
46 | ->once() |
||
47 | ->andReturn([ |
||
48 | 'default' => 'doctrine.orm.default_entity_manager', |
||
49 | 'second' => 'doctrine.orm.second_entity_manager', |
||
50 | ]); |
||
51 | |||
52 | $this->container->shouldReceive('getParameter') |
||
53 | ->with('doctrine.default_entity_manager') |
||
54 | ->once() |
||
55 | ->andReturn('default'); |
||
56 | |||
57 | $this->container->shouldReceive('setDefinition') |
||
58 | ->andReturnUsing(function($name, Definition $def) { |
||
59 | $this->assertEquals('tactician.middleware.doctrine.default', $name); |
||
60 | |||
61 | $this->assertEquals(TransactionMiddleware::class, $def->getClass()); |
||
62 | $this->assertCount(1, $def->getArguments()); |
||
63 | $this->assertInstanceOf(Reference::class, $def->getArgument(0)); |
||
64 | $this->assertEquals('doctrine.orm.default_entity_manager', (string)$def->getArgument(0)); |
||
65 | }) |
||
66 | ->once(); |
||
67 | |||
68 | $this->container->shouldReceive('setDefinition') |
||
69 | ->andReturnUsing(function($name, Definition $def) { |
||
70 | $this->assertEquals('tactician.middleware.doctrine.second', $name); |
||
71 | |||
72 | $this->assertEquals(TransactionMiddleware::class, $def->getClass()); |
||
73 | $this->assertCount(1, $def->getArguments()); |
||
74 | $this->assertInstanceOf(Reference::class, $def->getArgument(0)); |
||
75 | $this->assertEquals('doctrine.orm.second_entity_manager', (string)$def->getArgument(0)); |
||
76 | }) |
||
77 | ->once(); |
||
78 | |||
79 | $this->container->shouldReceive('setDefinition') |
||
80 | ->with('tactician.middleware.doctrine.second') |
||
81 | ->once(); |
||
82 | |||
83 | $this->container->shouldReceive('setAlias') |
||
84 | ->once() |
||
85 | ->with('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default'); |
||
86 | |||
87 | $this->compiler->process($this->container); |
||
88 | } |
||
89 | |||
135 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: