| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 13 | public function testChangingToken() |
||
| 14 | { |
||
| 15 | $accountResponse = ' |
||
| 16 | { |
||
| 17 | "account": { |
||
| 18 | "id": 123, |
||
| 19 | "name": "myaccount", |
||
| 20 | "timezone": "UTC", |
||
| 21 | "currency_name": "US Dollar" |
||
| 22 | } |
||
| 23 | } |
||
| 24 | '; |
||
| 25 | |||
| 26 | $client = \Mockery::mock(GuzzleClient::class); |
||
| 27 | $client |
||
| 28 | ->shouldReceive('request') |
||
| 29 | ->once() |
||
| 30 | ->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [ |
||
| 31 | 'headers' => [ |
||
| 32 | Transport::TOKEN_PIPEJUMP_NAME => '', |
||
| 33 | Transport::TOKEN_FUTUERSIMPLE_NAME => '', |
||
| 34 | ], |
||
| 35 | ]) |
||
| 36 | ->andReturn($this->getResponse(200, $accountResponse)); |
||
| 37 | $baseCrm = new BaseCrm('', $client); |
||
| 38 | |||
| 39 | $baseCrm->getAccount()->get(); |
||
| 40 | |||
| 41 | $client |
||
| 42 | ->shouldReceive('request') |
||
| 43 | ->once() |
||
| 44 | ->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [ |
||
| 45 | 'headers' => [ |
||
| 46 | Transport::TOKEN_PIPEJUMP_NAME => 'astalavista', |
||
| 47 | Transport::TOKEN_FUTUERSIMPLE_NAME => 'astalavista', |
||
| 48 | ], |
||
| 49 | ]) |
||
| 50 | ->andReturn($this->getResponse(200, $accountResponse)); |
||
| 51 | |||
| 52 | $baseCrm->setToken('astalavista'); |
||
| 53 | $this->assertEquals('astalavista', $baseCrm->getToken()); |
||
| 54 | $account = $baseCrm->getAccount()->get(); |
||
| 55 | |||
| 56 | $client |
||
| 57 | ->shouldReceive('request') |
||
| 58 | ->once() |
||
| 59 | ->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [ |
||
| 60 | 'headers' => [ |
||
| 61 | Transport::TOKEN_PIPEJUMP_NAME => 'baby', |
||
| 62 | Transport::TOKEN_FUTUERSIMPLE_NAME => 'baby', |
||
| 63 | ], |
||
| 64 | 'query' => [ |
||
| 65 | 'account' => [ |
||
| 66 | 'name' => 'new_name', |
||
| 67 | ], |
||
| 68 | ], |
||
| 69 | ]) |
||
| 70 | ->andReturn($this->getResponse(200, $accountResponse)); |
||
| 71 | |||
| 72 | $account->name = 'new_name'; |
||
| 73 | $account->getTransport()->setToken('baby'); |
||
| 74 | $this->assertEquals('baby', $account->getTransport()->getToken()); |
||
| 75 | $account->save(['name']); |
||
| 76 | } |
||
| 77 | } |
||
| 78 |