Conditions | 11 |
Paths | 1024 |
Total Lines | 73 |
Code Lines | 46 |
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 |
||
49 | protected function prepareDumpCommand(string $destinationPath): string |
||
50 | { |
||
51 | $options = [ |
||
52 | 'archive' => '', |
||
53 | 'database' => '', |
||
54 | 'username' => '', |
||
55 | 'password' => '', |
||
56 | 'host' => '', |
||
57 | 'port' => '', |
||
58 | 'collection' => '', |
||
59 | 'authenticationDatabase' => '', |
||
60 | ]; |
||
61 | // Database |
||
62 | if (!empty($this->dbName)) { |
||
63 | $options['database'] = "--db {$this->dbName}"; |
||
64 | } |
||
65 | // Username |
||
66 | if (!empty($this->username)) { |
||
67 | $options['username'] = "--username {$this->username}"; |
||
68 | } |
||
69 | //Password |
||
70 | if (!empty($this->password)) { |
||
71 | $options['password'] = "--password {$this->password}"; |
||
72 | } |
||
73 | // Host |
||
74 | if (!empty($this->host)) { |
||
75 | $options['host'] = "--host {$this->host}"; |
||
76 | } |
||
77 | // Port |
||
78 | if (!empty($this->port)) { |
||
79 | $options['port'] = "--port {$this->port}"; |
||
80 | } |
||
81 | // Collection |
||
82 | if (!empty($this->collection)) { |
||
83 | $options['collection'] = "--collection {$this->collection}"; |
||
84 | } |
||
85 | // Authentication Database |
||
86 | if (!empty($this->authenticationDatabase)) { |
||
87 | $options[] = "--authenticationDatabase {$this->authenticationDatabase}"; |
||
88 | } |
||
89 | // Archive |
||
90 | if ($this->isCompress) { |
||
91 | $options['archive'] = "--archive --gzip"; |
||
92 | } |
||
93 | // Dump Command |
||
94 | $dumpCommand = sprintf( |
||
95 | '%smongodump %s %s %s %s %s %s %s %s', |
||
96 | $this->dumpCommandPath, |
||
97 | $options['archive'], |
||
98 | $options['database'], |
||
99 | $options['username'], |
||
100 | $options['password'], |
||
101 | $options['host'], |
||
102 | $options['port'], |
||
103 | $options['collection'], |
||
104 | $options['authenticationDatabase'] |
||
105 | ); |
||
106 | // Generate dump command from uri |
||
107 | if ($this->uri) { |
||
108 | $dumpCommand = sprintf( |
||
109 | '%smongodump %s --uri %s %s', |
||
110 | $this->dumpCommandPath, |
||
111 | $options['archive'], |
||
112 | $this->uri, |
||
113 | $options['collection'] |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | if ($this->isCompress) { |
||
118 | return "{$dumpCommand} > {$destinationPath}{$this->compressExtension}"; |
||
119 | } |
||
120 | |||
121 | return "{$dumpCommand} --out {$destinationPath}"; |
||
122 | } |
||
167 |