Skip to content

Commit fb3645d

Browse files
Refactored duplicated code to parent class
1 parent 086876b commit fb3645d

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/Backup/Cli/Binary.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use phpbu\App\Backup\Compressor;
55
use phpbu\App\Backup\Target;
6+
use phpbu\App\Util\Cli;
67

78
/**
89
* Execute Binary
@@ -45,6 +46,16 @@ abstract class Binary
4546
'tar' => array(),
4647
);
4748

49+
/**
50+
* @param string $cmd
51+
* @param string $path
52+
* @return string
53+
*/
54+
protected function detectCommand($cmd, $path = null)
55+
{
56+
return Cli::detectCmdLocation($cmd, $path, self::getCommandLocations($cmd));
57+
}
58+
4859
/**
4960
* Executes the cli commands and handles compression
5061
*

src/Backup/Source/Mongodump.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ public function setup(array $conf = array())
148148
protected function setupMongodump(array $conf)
149149
{
150150
if (empty($this->binary)) {
151-
$this->binary = Util\Cli::detectCmdLocation(
152-
'mongodump',
153-
Util\Arr::getValue($conf, 'pathToMongodump'),
154-
Binary::getCommandLocations('mongodump')
155-
);
151+
$this->binary = $this->detectCommand('mongodump', Util\Arr::getValue($conf, 'pathToMongodump'));
156152
}
157153
}
158154

src/Backup/Source/Mysqldump.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ public function setup(array $conf = array())
145145
protected function setupMysqldump(array $conf)
146146
{
147147
if (empty($this->binary)) {
148-
$this->binary = Util\Cli::detectCmdLocation(
149-
'mysqldump',
150-
Util\Arr::getValue($conf, 'pathToMysqldump'),
151-
Binary::getCommandLocations('mysqldump')
152-
);
148+
$this->binary = $this->detectCommand('mysqldump', Util\Arr::getValue($conf, 'pathToMysqldump'));
153149
}
154150
}
155151

src/Backup/Source/Tar.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ public function setup(array $conf = array())
7171
protected function setupTar(array $conf)
7272
{
7373
if (empty($this->binary)) {
74-
$this->binary = Util\Cli::detectCmdLocation(
75-
'tar',
76-
Util\Arr::getValue($conf, 'pathToTar'),
77-
Binary::getCommandLocations('tar')
78-
);
74+
$this->binary = $this->detectCommand('tar', Util\Arr::getValue($conf, 'pathToTar'));
7975
}
8076
}
8177

0 commit comments

Comments
 (0)