Conditions | 14 |
Paths | 1153 |
Total Lines | 58 |
Code Lines | 39 |
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 |
||
78 | public function getConnection() { |
||
79 | if (!is_null($this->connection)) { |
||
80 | return $this->connection; |
||
81 | } |
||
82 | |||
83 | $scheme = (isset($this->params['use_ssl']) && $this->params['use_ssl'] === false) ? 'http' : 'https'; |
||
84 | $base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/'; |
||
85 | |||
86 | $options = [ |
||
87 | 'version' => isset($this->params['version']) ? $this->params['version'] : 'latest', |
||
88 | 'credentials' => [ |
||
89 | 'key' => $this->params['key'], |
||
90 | 'secret' => $this->params['secret'], |
||
91 | ], |
||
92 | 'endpoint' => $base_url, |
||
93 | 'region' => $this->params['region'], |
||
94 | 'use_path_style_endpoint' => isset($this->params['use_path_style']) ? $this->params['use_path_style'] : false, |
||
95 | 'signature_provider' => \Aws\or_chain([self::class, 'legacySignatureProvider'], ClientResolver::_default_signature_provider()) |
||
96 | ]; |
||
97 | if (isset($this->params['proxy'])) { |
||
98 | $options['request.options'] = ['proxy' => $this->params['proxy']]; |
||
99 | } |
||
100 | if (isset($this->params['legacy_auth']) && $this->params['legacy_auth']) { |
||
101 | $options['signature_version'] = 'v2'; |
||
102 | } |
||
103 | $this->connection = new S3Client($options); |
||
104 | |||
105 | if (!$this->connection->isBucketDnsCompatible($this->bucket)) { |
||
106 | $logger = \OC::$server->getLogger(); |
||
107 | $logger->debug('Bucket "' . $this->bucket . '" This bucket name is not dns compatible, it may contain invalid characters.', |
||
108 | ['app' => 'objectstore']); |
||
109 | } |
||
110 | |||
111 | if (!$this->connection->doesBucketExist($this->bucket)) { |
||
112 | $logger = \OC::$server->getLogger(); |
||
113 | try { |
||
114 | $logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']); |
||
115 | if (!$this->connection->isBucketDnsCompatible($this->bucket)) { |
||
116 | throw new \Exception("The bucket will not be created because the name is not dns compatible, please correct it: " . $this->bucket); |
||
117 | } |
||
118 | $this->connection->createBucket(array('Bucket' => $this->bucket)); |
||
119 | $this->testTimeout(); |
||
120 | } catch (S3Exception $e) { |
||
121 | $logger->logException($e, [ |
||
122 | 'message' => 'Invalid remote storage.', |
||
123 | 'level' => ILogger::DEBUG, |
||
124 | 'app' => 'objectstore', |
||
125 | ]); |
||
126 | throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage()); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | // google cloud's s3 compatibility doesn't like the EncodingType parameter |
||
131 | if (strpos($base_url, 'storage.googleapis.com')) { |
||
132 | $this->connection->getHandlerList()->remove('s3.auto_encode'); |
||
133 | } |
||
134 | |||
135 | return $this->connection; |
||
136 | } |
||
157 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.