| Conditions | 9 |
| Paths | 1 |
| Total Lines | 113 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 25 | public function register(Application $app) |
||
| 26 | { |
||
| 27 | $app['arangodb.default_options'] = array( |
||
| 28 | // database name |
||
| 29 | ConnectionOptions::OPTION_DATABASE => '_system', |
||
| 30 | // server endpoint to connect to |
||
| 31 | ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529', |
||
| 32 | // authorization type to use (currently supported: 'Basic') |
||
| 33 | ConnectionOptions::OPTION_AUTH_TYPE => 'Basic', |
||
| 34 | // user for basic authorization |
||
| 35 | ConnectionOptions::OPTION_AUTH_USER => 'root', |
||
| 36 | // password for basic authorization |
||
| 37 | ConnectionOptions::OPTION_AUTH_PASSWD => '', |
||
| 38 | // connection persistence on server. can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections) |
||
| 39 | ConnectionOptions::OPTION_CONNECTION => 'Close', |
||
| 40 | // connect timeout in seconds |
||
| 41 | ConnectionOptions::OPTION_TIMEOUT => 3, |
||
| 42 | // whether or not to reconnect when a keep-alive connection has timed out on server |
||
| 43 | ConnectionOptions::OPTION_RECONNECT => true, |
||
| 44 | // optionally create new collections when inserting documents |
||
| 45 | ConnectionOptions::OPTION_CREATE => true, |
||
| 46 | // optionally create new collections when inserting documents |
||
| 47 | ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST, |
||
| 48 | ); |
||
| 49 | |||
| 50 | $app['arangodbs.options.initializer'] = $app->protect( |
||
| 51 | function () use ($app) { |
||
| 52 | static $initialized = false; |
||
| 53 | |||
| 54 | if ($initialized) { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | $initialized = true; |
||
| 59 | |||
| 60 | if (!isset($app['arangodbs.options'])) { |
||
| 61 | $app['arangodbs.options'] = array( |
||
| 62 | 'default' => isset($app['arangodb.options']) ? $app['arangodb.options'] : array() |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | $tmp = $app['arangodbs.options']; |
||
| 67 | foreach ($tmp as $name => &$options) { |
||
| 68 | $options = array_replace_recursive($app['arangodb.default_options'], $options); |
||
| 69 | |||
| 70 | if (!isset($app['arangodbs.default'])) { |
||
| 71 | $app['arangodbs.default'] = $name; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $app['arangodbs.options'] = $tmp; |
||
| 76 | } |
||
| 77 | ); |
||
| 78 | |||
| 79 | $app['arangodbs'] = $app->share( |
||
| 80 | function ($app) { |
||
| 81 | $app['arangodbs.options.initializer'](); |
||
| 82 | |||
| 83 | $dbs = new \Pimple(); |
||
| 84 | foreach (array_keys($app['arangodbs.options']) as $name) { |
||
| 85 | if ($app['arangodbs.default'] === $name) { |
||
| 86 | // we use shortcuts here in case the default has been overridden |
||
| 87 | $config = $app['arangodb.config']; |
||
| 88 | } else { |
||
| 89 | $config = $app['arangodbs.config'][$name]; |
||
| 90 | } |
||
| 91 | |||
| 92 | $dbs[$name] = $dbs->share( |
||
| 93 | function () use ($config) { |
||
| 94 | return new Connection($config->getAll()); |
||
| 95 | } |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | return $dbs; |
||
| 100 | } |
||
| 101 | ); |
||
| 102 | |||
| 103 | $app['arangodb'] = $app->share( |
||
| 104 | function ($app) { |
||
| 105 | $dbs = $app['arangodbs']; |
||
| 106 | |||
| 107 | return $dbs[$app['arangodbs.default']]; |
||
| 108 | } |
||
| 109 | ); |
||
| 110 | |||
| 111 | $app['arangodbs.config'] = $app->share( |
||
| 112 | function ($app) { |
||
| 113 | $app['arangodbs.options.initializer'](); |
||
| 114 | |||
| 115 | $configs = new \Pimple(); |
||
| 116 | foreach ($app['arangodbs.options'] as $name => $options) { |
||
| 117 | $configs[$name] = new ConnectionOptions($options); |
||
| 118 | } |
||
| 119 | |||
| 120 | return $configs; |
||
| 121 | } |
||
| 122 | ); |
||
| 123 | |||
| 124 | $app['arangodb.config'] = $app->share( |
||
| 125 | function ($app) { |
||
| 126 | $dbs = $app['arangodbs.config']; |
||
| 127 | |||
| 128 | return $dbs[$app['arangodbs.default']]; |
||
| 129 | } |
||
| 130 | ); |
||
| 131 | |||
| 132 | $this->collectionManagement($app); |
||
| 133 | $this->documentManagement($app); |
||
| 134 | $this->edgeManagement($app); |
||
| 135 | $this->graphManagement($app); |
||
| 136 | $this->statementManagement($app); |
||
| 137 | } |
||
| 138 | |||
| 307 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.