Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 |
||
38 | public function testCurrencyAlteration() |
||
39 | { |
||
40 | $client = \Mockery::mock(GuzzleClient::class); |
||
41 | $client |
||
42 | ->shouldReceive('request') |
||
43 | ->once() |
||
44 | ->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery()) |
||
45 | ->andReturn($this->getResponse(200, ' |
||
46 | { |
||
47 | "account": { |
||
48 | "id": 123, |
||
49 | "name": "myaccount", |
||
50 | "timezone": "UTC", |
||
51 | "currency_name": "US Dollar" |
||
52 | } |
||
53 | } |
||
54 | ')); |
||
55 | $baseCrm = new BaseCrm('', $client); |
||
56 | |||
57 | $account = $baseCrm->getAccount(); |
||
58 | |||
59 | $this->assertEquals(123, $account->id); |
||
60 | $this->assertEquals('myaccount', $account->name); |
||
61 | $this->assertEquals('UTC', $account->timezone); |
||
62 | $this->assertEquals(Currency::USD(), $account->currency); |
||
63 | |||
64 | $client |
||
65 | ->shouldReceive('request') |
||
66 | ->once() |
||
67 | ->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery([ |
||
68 | 'query' => [ |
||
69 | 'account' => [ |
||
70 | 'name' => 'newname', |
||
71 | 'currency_id' => Currency::PLN, |
||
72 | 'timezone' => 'new_timezone', |
||
73 | ] |
||
74 | ], |
||
75 | ])) |
||
76 | ->andReturn($this->getResponse(200, ' |
||
77 | { |
||
78 | "account": { |
||
79 | "id": 123, |
||
80 | "name": "newname", |
||
81 | "timezone": "new_timezone", |
||
82 | "currency_name": "Polish złoty" |
||
83 | } |
||
84 | } |
||
85 | ')); |
||
86 | |||
87 | $account->name = 'newname'; |
||
|
|||
88 | $account->timezone = 'new_timezone'; |
||
89 | $account->currency = Currency::PLN(); |
||
90 | $account->save(); |
||
91 | |||
92 | $this->assertEquals(123, $account->id); |
||
93 | $this->assertEquals('newname', $account->name); |
||
94 | $this->assertEquals('new_timezone', $account->timezone); |
||
95 | $this->assertEquals(Currency::PLN(), $account->currency); |
||
96 | } |
||
97 | } |
||
98 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.