Skip to content

Commit 10b6a9a

Browse files
Moved 'compress' method to base class
1 parent ac59026 commit 10b6a9a

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/Backup/Compressor/Abstraction.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use phpbu\App\Backup\Cli;
55
use phpbu\App\Backup\Target;
6-
use phpbu\App\Cli\Executable\Compressor;
76
use phpbu\App\Exception;
87
use phpbu\App\Result;
98

@@ -53,6 +52,27 @@ public function __construct($path, $pathToCommand = null)
5352
$this->pathToCommand = $pathToCommand;
5453
}
5554

55+
/**
56+
* Compress the configured directory.
57+
*
58+
* @param \phpbu\App\Backup\Target $target
59+
* @param \phpbu\App\Result $result
60+
* @throws \phpbu\App\Exception
61+
*/
62+
public function compress(Target $target, Result $result)
63+
{
64+
if (!$target->shouldBeCompressed()) {
65+
throw new Exception('target should not be compressed');
66+
}
67+
68+
$res = $this->execute($target);
69+
$result->debug($res->getCmd());
70+
71+
if (0 !== $res->getCode()) {
72+
throw new Exception('Failed to \'compress\' file: ' . $this->path);
73+
}
74+
}
75+
5676
/**
5777
* Validate path.
5878
*

src/Backup/Compressor/Directory.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,8 @@ public function isPathValid($path)
3939
*/
4040
public function compress(Target $target, Result $result)
4141
{
42-
if (!$target->shouldBeCompressed()) {
43-
throw new Exception('target should not be compressed');
44-
}
4542
$target->setMimeType('application/x-tar');
46-
47-
$res = $this->execute($target);
48-
$result->debug($res->getCmd());
49-
50-
if (0 !== $res->getCode()) {
51-
throw new Exception('Failed to \'tar\' directory: ' . $this->path);
52-
}
43+
parent::compress($target, $result);
5344
}
5445

5546
/**

src/Backup/Compressor/File.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,6 @@ public function isPathValid($path)
3131
return is_file($path);
3232
}
3333

34-
/**
35-
* Compress the configured directory.
36-
*
37-
* @param \phpbu\App\Backup\Target $target
38-
* @param \phpbu\App\Result $result
39-
* @throws \phpbu\App\Exception
40-
*/
41-
public function compress(Target $target, Result $result)
42-
{
43-
if (!$target->shouldBeCompressed()) {
44-
throw new Exception('target should not be compressed');
45-
}
46-
47-
$res = $this->execute($target);
48-
$result->debug($res->getCmd());
49-
50-
if (0 !== $res->getCode()) {
51-
throw new Exception('Failed to ' . $target->getCompressor()->getCommand() . ' \'compress\' file: ' . $this->path);
52-
}
53-
}
54-
5534
/**
5635
* Returns the executable for this action.
5736
*

0 commit comments

Comments
 (0)