Conditions | 1 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
16 | public function testGetItems() |
||
17 | { |
||
18 | $user = \Phake::mock(User::clazz()); |
||
19 | \Phake::when($user) |
||
20 | ->getId() |
||
21 | ->thenReturn('foo-id') |
||
22 | ; |
||
23 | |||
24 | $token = \Phake::mock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'); |
||
25 | \Phake::when($token) |
||
26 | ->getUser() |
||
27 | ->thenReturn($user) |
||
28 | ; |
||
29 | |||
30 | $tokenStorage = \Phake::mock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'); |
||
31 | \Phake::when($tokenStorage) |
||
32 | ->getToken() |
||
33 | ->thenReturn($token) |
||
34 | ; |
||
35 | |||
36 | $configEntry = \Phake::mock('Modera\ConfigBundle\Config\ConfigurationEntryInterface'); |
||
37 | \Phake::when($configEntry) |
||
38 | ->getValue() |
||
39 | ->thenReturn('foo-value') |
||
40 | ; |
||
41 | |||
42 | $configEntriesManager = \Phake::mock('Modera\ConfigBundle\Config\ConfigurationEntriesManagerInterface'); |
||
43 | \Phake::when($configEntriesManager) |
||
44 | ->findOneByNameOrDie(ModeraBackendGoogleAnalyticsBundle::TRACKING_CODE_CONFIG_KEY) |
||
45 | ->thenReturn($configEntry) |
||
46 | ; |
||
47 | |||
48 | $provider = new ConfigMergersProvider($tokenStorage, $configEntriesManager, 'prod'); |
||
49 | |||
50 | $items = $provider->getItems(); |
||
51 | |||
52 | $this->assertTrue(is_array($items)); |
||
53 | $this->assertEquals(1, count($items)); |
||
54 | |||
55 | /* @var ConfigMergerInterface $merger */ |
||
56 | $merger = $items[0]; |
||
57 | |||
58 | $this->assertInstanceOf('Modera\MjrIntegrationBundle\Config\ConfigMergerInterface', $merger); |
||
59 | |||
60 | $config = $merger->merge(array()); |
||
61 | |||
62 | $this->assertArrayHasKey('modera_backend_google_analytics', $config); |
||
63 | $config = $config['modera_backend_google_analytics']; |
||
64 | $this->assertArrayHasKey('tracking_code', $config); |
||
65 | $this->assertEquals('foo-value', $config['tracking_code']); |
||
66 | $this->assertEquals('foo-id', $config['user_id']); |
||
67 | $this->assertArrayHasKey('user_id', $config); |
||
68 | $this->assertArrayHasKey('is_debug', $config); |
||
69 | $this->assertFalse($config['is_debug']); // because it's "prod" env now |
||
70 | $this->assertArrayHasKey('prefix', $config); |
||
71 | $this->assertEquals('/backend', $config['prefix']); |
||
72 | |||
73 | // --- env = dev |
||
74 | |||
75 | $provider = new ConfigMergersProvider($tokenStorage, $configEntriesManager, 'dev'); |
||
76 | |||
77 | $items = $provider->getItems(); |
||
78 | |||
79 | $this->assertTrue(is_array($items)); |
||
80 | $this->assertEquals(1, count($items)); |
||
81 | |||
82 | $config = $items[0]->merge(array()); |
||
83 | |||
84 | $this->assertTrue($config['modera_backend_google_analytics']['is_debug']); |
||
85 | } |
||
86 | } |
||
87 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: