| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 35 |
| 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 |
||
| 36 | public function setUp() |
||
|
|
|||
| 37 | { |
||
| 38 | $vootClient = $this->getMockBuilder('\fkooman\OAuth\Client\Http\HttpClientInterface')->getMock(); |
||
| 39 | $vootClient->method('send')->will( |
||
| 40 | $this->onConsecutiveCalls( |
||
| 41 | new Response(200, file_get_contents(sprintf('%s/data/response.json', __DIR__)), ['Content-Type' => 'application/json']), |
||
| 42 | new Response(401, file_get_contents(sprintf('%s/data/response_invalid_token.json', __DIR__)), ['Content-Type' => 'application/json']) |
||
| 43 | ) |
||
| 44 | ); |
||
| 45 | |||
| 46 | $storage = new Storage( |
||
| 47 | new PDO( |
||
| 48 | $GLOBALS['DB_DSN'], |
||
| 49 | $GLOBALS['DB_USER'], |
||
| 50 | $GLOBALS['DB_PASSWD'] |
||
| 51 | ), |
||
| 52 | new DateTime() |
||
| 53 | ); |
||
| 54 | $storage->init(); |
||
| 55 | // $storage->setAccessToken('foo', 'voot', new AccessToken('AT', 'bearer', 'groups', 'RT', new DateTime('2016-01-02'))); |
||
| 56 | $storage->setAccessToken( |
||
| 57 | 'foo', |
||
| 58 | 'voot', |
||
| 59 | AccessToken::fromStorage( |
||
| 60 | json_encode([ |
||
| 61 | 'access_token' => 'AT', |
||
| 62 | 'token_type' => 'bearer', |
||
| 63 | 'scope' => 'groups', |
||
| 64 | 'refresh_token' => 'RT', |
||
| 65 | 'expires_in' => 3600, |
||
| 66 | 'issued_at' => '2016-01-02 00:00:00', |
||
| 67 | ]) |
||
| 68 | ) |
||
| 69 | ); |
||
| 70 | |||
| 71 | $random = $this->getMockBuilder('fkooman\OAuth\Client\RandomInterface')->getMock(); |
||
| 72 | $random->method('get')->will($this->onConsecutiveCalls('random_1', 'random_2')); |
||
| 73 | |||
| 74 | $oauthClient = new OAuthClient( |
||
| 75 | $storage, |
||
| 76 | $vootClient |
||
| 77 | ); |
||
| 78 | $oauthClient->addProvider('voot', new Provider('a', 'b', 'c', 'd')); |
||
| 79 | $oauthClient->setRandom($random); |
||
| 80 | $oauthClient->setDateTime(new DateTime('2016-01-01')); |
||
| 81 | |||
| 82 | $this->vootProvider = new VootProvider( |
||
| 83 | $oauthClient, |
||
| 84 | 'https://voot.surfconext.nl/me/groups' |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 133 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: