| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Code Lines | 58 |
| 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 |
||
| 30 | public function register(Container $pimple) |
||
| 31 | { |
||
| 32 | $pimple['suite.ticket'] = function ($pimple) { |
||
| 33 | return new Ticket( |
||
| 34 | $pimple['config']['suite']['suite_id'], |
||
| 35 | $pimple['cache'] |
||
| 36 | ); |
||
| 37 | }; |
||
| 38 | |||
| 39 | $pimple['suite.access_token'] = function ($pimple) { |
||
| 40 | $accessToken = new AccessToken( |
||
| 41 | $pimple['config']['suite']['suite_id'], |
||
| 42 | $pimple['config']['suite']['secret'], |
||
| 43 | $pimple['cache'] |
||
| 44 | ); |
||
| 45 | $accessToken->setTicket($pimple['suite.ticket']); |
||
| 46 | |||
| 47 | return $accessToken; |
||
| 48 | }; |
||
| 49 | |||
| 50 | $pimple['suite.encryptor'] = function ($pimple) { |
||
| 51 | return new Encryptor( |
||
| 52 | $pimple['config']['suite']['suite_id'], |
||
| 53 | $pimple['config']['suite']['token'], |
||
| 54 | $pimple['config']['suite']['aes_key'] |
||
| 55 | ); |
||
| 56 | }; |
||
| 57 | |||
| 58 | $pimple['suite'] = function ($pimple) { |
||
| 59 | return new Suite($pimple); |
||
| 60 | }; |
||
| 61 | |||
| 62 | $pimple['suite.server'] = function ($pimple) { |
||
| 63 | $server = new Guard($pimple['config']['suite']['token']); |
||
| 64 | $server->debug($pimple['config']['debug']); |
||
| 65 | $server->setEncryptor($pimple['suite.encryptor']); |
||
| 66 | $server->setHandlers([ |
||
| 67 | Guard::EVENT_CREATE_AUTH => $pimple['suite.handlers.create_auth'], |
||
| 68 | Guard::EVENT_CANCEL_AUTH => $pimple['suite.handlers.cancel_auth'], |
||
| 69 | Guard::EVENT_CHANGE_AUTH => $pimple['suite.handlers.change_auth'], |
||
| 70 | Guard::EVENT_SUITE_TICKET => $pimple['suite.handlers.suite_ticket'], |
||
| 71 | ]); |
||
| 72 | |||
| 73 | return $server; |
||
| 74 | }; |
||
| 75 | |||
| 76 | $pimple['suite.pre_auth'] = $pimple['suite.pre_authorization'] = function ($pimple) { |
||
| 77 | return new PreAuthorization( |
||
| 78 | $pimple['suite.access_token'], |
||
| 79 | $pimple['request'] |
||
| 80 | ); |
||
| 81 | }; |
||
| 82 | |||
| 83 | $pimple['suite.api'] = function ($pimple) { |
||
| 84 | return new BaseApi( |
||
| 85 | $pimple['suite.access_token'], |
||
| 86 | $pimple['request'] |
||
| 87 | ); |
||
| 88 | }; |
||
| 89 | |||
| 90 | $pimple['suite.authorization'] = function ($pimple) { |
||
| 91 | return new Authorization( |
||
| 92 | $pimple['suite.api'], |
||
| 93 | $pimple['config']['suite']['corp_id'], |
||
| 94 | $pimple['cache'] |
||
| 95 | ); |
||
| 96 | }; |
||
| 97 | |||
| 98 | $pimple['suite.authorizer_access_token'] = function ($pimple) { |
||
| 99 | return new AuthorizerAccessToken( |
||
| 100 | $pimple['config']['suite']['corp_id'], |
||
| 101 | $pimple['suite.authorization'] |
||
| 102 | ); |
||
| 103 | }; |
||
| 104 | |||
| 105 | // Authorization events handlers. |
||
| 106 | $pimple['suite.handlers.suite_ticket'] = function ($pimple) { |
||
| 107 | return new EventHandlers\SuiteTicket($pimple['suite.ticket']); |
||
| 108 | }; |
||
| 109 | $pimple['suite.handlers.create_auth'] = function () { |
||
| 110 | return new EventHandlers\CreateAuth(); |
||
| 111 | }; |
||
| 112 | $pimple['suite.handlers.change_auth'] = function () { |
||
| 113 | return new EventHandlers\ChangeAuth(); |
||
| 114 | }; |
||
| 115 | $pimple['suite.handlers.cancel_auth'] = function () { |
||
| 116 | return new EventHandlers\CancelAuth(); |
||
| 117 | }; |
||
| 118 | |||
| 119 | $pimple['suite.app'] = function ($pimple) { |
||
| 120 | return new Application($pimple['config']->toArray()); |
||
| 121 | }; |
||
| 122 | |||
| 123 | // OAuth for Suite. |
||
| 124 | $pimple['suite.oauth'] = function ($pimple) { |
||
| 125 | return new App($pimple['suite.authorizer_access_token']->getToken()); |
||
| 126 | }; |
||
| 127 | } |
||
| 128 | |||
| 147 |