Conditions | 15 |
Paths | 134 |
Total Lines | 41 |
Code Lines | 27 |
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 |
||
61 | protected function getCommand() |
||
62 | { |
||
63 | $to = $this->get('to'); |
||
64 | $from = $this->get('from'); |
||
65 | |||
66 | $toNode = $this->getNodeFromPath($to); |
||
67 | $fromNode = $this->getNodeFromPath($from); |
||
68 | $node = $toNode ?: $fromNode; |
||
69 | |||
70 | if (!$node) { |
||
71 | throw new Exception('This task is intended to be used with nodes - use shell task for other sources/targets'); |
||
72 | } elseif ($toNode === $fromNode) { |
||
73 | throw new Exception('Transfer on same node not supported'); |
||
74 | } elseif ($toNode && $fromNode && $toNode !== $fromNode) { |
||
75 | throw new Exception('Transfer between nodes not (yet) supported'); |
||
76 | } |
||
77 | |||
78 | $cwd = $this->expand($this->cwd); |
||
79 | $cwdCmd = $cwd ? 'cd ' . escapeshellarg($cwd) . '; ' : null; |
||
80 | $toDirParent = dirname(array_pop(explode(':', $to, 2))); |
||
|
|||
81 | if ($toDirParent !== '/') { |
||
82 | $prepareDirCmd = 'mkdir -p ' . escapeshellarg($toDirParent); |
||
83 | if ($toNode) { |
||
84 | $prepareDirCmd = $this->getSshCommand($prepareDirCmd, $toNode); |
||
85 | } elseif ($cwd && $toDirParent[0] !== '/') { |
||
86 | $prepareDirCmd = $cwdCmd . $prepareDirCmd; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | $scpCommand = $this->getScpCommand($node) . ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to); |
||
91 | |||
92 | if ($node) { |
||
93 | $this->addExpect($scpCommand, $node); |
||
94 | } |
||
95 | |||
96 | if ($cwdCmd) { |
||
97 | $scpCommand = $cwdCmd . $scpCommand; |
||
98 | } |
||
99 | |||
100 | return isset($prepareDirCmd) ? array($prepareDirCmd, $scpCommand) : $scpCommand; |
||
101 | } |
||
102 | |||
138 |