Skip to content

Commit b47351b

Browse files
committed
Improved test suite and fixed bugs
1 parent 11ce9b0 commit b47351b

File tree

111 files changed

+499
-842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+499
-842
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"require-dev": {
2929
"raulfraile/ladybug": "~1.0",
30-
"mockery/mockery": "0.9.1"
30+
"mockery/mockery": "0.9.1",
31+
"symfony/finder": "~2.4"
3132
},
3233
"suggest": {
3334
"ext-zip": "Allows to uncompress zip files using ZipArchive",

src/Chooser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,22 @@ public function setFiles($files)
124124
/**
125125
* Adds a new file.
126126
* @param string $filename File name
127-
* @param FormatInterface|null $format Format
127+
* @param FormatInterface|null $formatChain Format
128128
*
129129
* @throws Exception\FormatGuesserRequiredException
130130
* @return Chooser
131131
*/
132-
public function addFile($filename, FormatInterface $format = null)
132+
public function addFile($filename, FormatInterface $formatChain = null)
133133
{
134-
if (null === $format) {
134+
if (null === $formatChain) {
135135
if (null === $this->formatGuesser) {
136136
throw new FormatGuesserRequiredException();
137137
}
138138

139-
$format = $this->formatGuesser->guess($filename);
139+
$formatChain = $this->formatGuesser->guess($filename);
140140
}
141141

142-
$this->files[] = new File($filename, $format);
142+
$this->files[] = new File($filename, $formatChain);
143143

144144
return $this;
145145
}

src/File.php

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

1212
namespace Distill;
1313

14-
use Distill\Format\FormatInterface;
14+
use Distill\Format\FormatChainInterface;
1515

1616
class File implements FileInterface
1717
{
@@ -23,16 +23,16 @@ class File implements FileInterface
2323

2424
/**
2525
* File format.
26-
* @var FormatInterface
26+
* @var FormatChainInterface
2727
*/
2828
protected $format;
2929

3030
/**
3131
* Constructor.
3232
* @param string $path File path
33-
* @param FormatInterface $format File format
33+
* @param FormatChainInterface $format File format
3434
*/
35-
public function __construct($path, FormatInterface $format)
35+
public function __construct($path, FormatChainInterface $format)
3636
{
3737
$this->path = $path;
3838
$this->format = $format;
@@ -67,7 +67,7 @@ public function getPath()
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function setFormat(FormatInterface $format)
70+
public function setFormatChain(FormatChainInterface $format)
7171
{
7272
$this->format = $format;
7373

@@ -77,7 +77,7 @@ public function setFormat(FormatInterface $format)
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function getFormat()
80+
public function getFormatChain()
8181
{
8282
return $this->format;
8383
}

src/FileInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Distill;
1313

14-
use Distill\Format\FormatInterface;
14+
use Distill\Format\FormatChainInterface;
1515

1616
interface FileInterface
1717
{
@@ -39,16 +39,16 @@ public function getPath();
3939

4040
/**
4141
* Sets the file format.
42-
* @param FormatInterface $format File format
42+
* @param FormatChainInterface $format File format
4343
*
4444
* @return FileInterface
4545
*/
46-
public function setFormat(FormatInterface $format);
46+
public function setFormatChain(FormatChainInterface $format);
4747

4848
/**
4949
* Gets the file format.
5050
*
51-
* @return FormatInterface File format
51+
* @return FormatChainInterface File format
5252
*/
53-
public function getFormat();
53+
public function getFormatChain();
5454
}

src/Format/FormatChain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FormatChain implements FormatChainInterface, \Countable, \ArrayAccess, \It
1616
/** @var FormatInterface[] $formats */
1717
protected $formats;
1818

19-
public function __construct($formats = [])
19+
public function __construct(array $formats = [])
2020
{
2121
$this->formats = $formats;
2222
}

src/Format/FormatChainInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ interface FormatChainInterface// extends FormatInterface
1616
public function getChainFormats();
1717

1818
public function isEmpty();
19+
20+
/**
21+
* Gets the compression ratio level for the whole chain.
22+
*
23+
* @return integer Compression ratio level (0: low, 10: high)
24+
*/
25+
public function getCompressionRatioLevel();
1926
}

src/Method/Command/Ar.php

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

1212
namespace Distill\Method\Command;
1313

14+
use Distill\Exception\IO\Input\FileCorruptedException;
1415
use Distill\Format;
1516

1617
/**
@@ -32,6 +33,10 @@ public function extract($file, $target, Format\FormatInterface $format)
3233
$command = sprintf("cd %s && ar -x %s", escapeshellarg($target), escapeshellarg($file));
3334
$exitCode = $this->executeCommand($command);
3435

36+
if ($exitCode > 0) {
37+
throw new FileCorruptedException($file);
38+
}
39+
3540
return $this->isExitCodeSuccessful($exitCode);
3641
}
3742

src/Method/Command/Bzip2.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Distill\Method\Command;
1313

14+
use Distill\Exception\IO\Input\FileCorruptedException;
1415
use Distill\Format;
1516

1617
/**
@@ -29,11 +30,16 @@ public function extract($file, $target, Format\FormatInterface $format)
2930

3031
$this->getFilesystem()->mkdir($target);
3132

32-
$outputPath = sprintf('%s/%s', $target, pathinfo($file, PATHINFO_FILENAME));
33+
$copiedFile = $target . DIRECTORY_SEPARATOR . basename($file);
34+
$this->getFilesystem()->copy($file, $copiedFile);
3335

34-
$command = sprintf("bzip2 -k -d -c %s >> %s", escapeshellarg($file), escapeshellarg($outputPath));
36+
$command = sprintf("bzip2 -d %s", escapeshellarg($copiedFile));
3537
$exitCode = $this->executeCommand($command);
3638

39+
if (2 === $exitCode) {
40+
throw new FileCorruptedException($file);
41+
}
42+
3743
return $this->isExitCodeSuccessful($exitCode);
3844
}
3945

src/Method/Command/Cabextract.php

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

1212
namespace Distill\Method\Command;
1313

14+
use Distill\Exception\IO\Input\FileCorruptedException;
1415
use Distill\Format;
1516

1617
/**
@@ -32,6 +33,10 @@ public function extract($file, $target, Format\FormatInterface $format)
3233

3334
$exitCode = $this->executeCommand($command);
3435

36+
if ($exitCode > 0) {
37+
throw new FileCorruptedException($file);
38+
}
39+
3540
return $this->isExitCodeSuccessful($exitCode);
3641
}
3742

src/Method/Command/Cpio.php

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

1212
namespace Distill\Method\Command;
1313

14+
use Distill\Exception\IO\Input\FileCorruptedException;
1415
use Distill\Format;
1516

1617
/**
@@ -32,6 +33,10 @@ public function extract($file, $target, Format\FormatInterface $format)
3233
$command = sprintf("cd %s && cpio -idv -F %s", escapeshellarg($target), escapeshellarg($file));
3334
$exitCode = $this->executeCommand($command);
3435

36+
if ($exitCode > 0) {
37+
throw new FileCorruptedException($file);
38+
}
39+
3540
return $this->isExitCodeSuccessful($exitCode);
3641
}
3742

0 commit comments

Comments
 (0)