Skip to content

Commit 1459e38

Browse files
author
Stephan Wentz
committed
remove assert dependency, fix file headers, use prophecy for mocks
1 parent eb975e1 commit 1459e38

Some content is hidden

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

43 files changed

+383
-266
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
language: php
22

33
php:
4-
- 5.4
54
- 5.5
5+
- 5.6
6+
- 7.0
67

7-
before_script: composer install --prefer-source
8+
before_script: composer install
89

910
script: phpunit -c tests

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
1+
Copyright (c) 2012-2016 brainbits GmbH (http://www.brainbits.net)
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
THE SOFTWARE.
19+
THE SOFTWARE.

composer.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
{
1313
"name": "Phillip Look",
1414
"email": "[email protected]"
15+
},
16+
{
17+
"name": "Stephan Wentz",
18+
"email": "[email protected]"
1519
}
1620
],
1721
"require": {
18-
"php": ">=5.3.0",
19-
"beberlei/assert": "1.*",
20-
"symfony/http-kernel": "2.3.*",
21-
"symfony/process": "2.3.*"
22+
"php": ">=5.5.0",
23+
"psr/log": "~1.0",
24+
"symfony/process": "~2.3"
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "~4.5"
2228
},
2329
"autoload": {
24-
"psr-0": { "Brainbits": "src/" }
30+
"psr-4": { "Brainbits\\Transcoder\\": "src/" }
2531
},
2632
"minimum-stability": "stable"
2733
}

src/Brainbits/Transcoder/Tests/TranscoderTestHelper.php

-80
This file was deleted.

src/Brainbits/Transcoder/Decoder/Bzip2Decoder.php renamed to src/Decoder/Bzip2Decoder.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

1112
namespace Brainbits\Transcoder\Decoder;
1213

13-
use Assert\Assertion;
14+
use Brainbits\Transcoder\Exception\DecodeFailedException;
1415

1516
/**
1617
* Bzip2 decoder
@@ -27,7 +28,11 @@ class Bzip2Decoder implements DecoderInterface
2728
public function decode($data)
2829
{
2930
$data = bzdecompress($data);
30-
Assertion::minLength($data, 1, 'bzdecompress returned no data');
31+
32+
if ($this->isErrorCode($data)) {
33+
throw new DecodeFailedException("bzdecompress failed.");
34+
}
35+
3136
return $data;
3237
}
3338

@@ -38,4 +43,15 @@ public function supports($type)
3843
{
3944
return self::TYPE === $type;
4045
}
46+
47+
/**
48+
* @param mixed $result
49+
*
50+
* @return bool
51+
*/
52+
private function isErrorCode($result)
53+
{
54+
return $result === -1 || $result === -2 || $result === -3 || $result === -5 || $result === -6 ||
55+
$result === -7 || $result === -8 || $result === -9;
56+
}
4157
}

src/Brainbits/Transcoder/Decoder/DecoderInterface.php renamed to src/Decoder/DecoderInterface.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.

src/Brainbits/Transcoder/Decoder/DecoderResolver.php renamed to src/Decoder/DecoderResolver.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.

src/Brainbits/Transcoder/Decoder/DecoderResolverInterface.php renamed to src/Decoder/DecoderResolverInterface.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.

src/Brainbits/Transcoder/Decoder/DeflateDecoder.php renamed to src/Decoder/DeflateDecoder.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

1112
namespace Brainbits\Transcoder\Decoder;
1213

13-
use Assert\Assertion;
14+
use Brainbits\Transcoder\Exception\DecodeFailedException;
1415

1516
/**
1617
* Deflate decoder
@@ -27,7 +28,11 @@ class DeflateDecoder implements DecoderInterface
2728
public function decode($data)
2829
{
2930
$data = gzinflate($data);
30-
Assertion::minLength($data, 1, 'gzinflate returned no data');
31+
32+
if (!$data) {
33+
throw new DecodeFailedException("gzinflate returned no data.");
34+
}
35+
3136
return $data;
3237
}
3338

src/Brainbits/Transcoder/Decoder/GzipDecoder.php renamed to src/Decoder/GzipDecoder.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

1112
namespace Brainbits\Transcoder\Decoder;
1213

13-
use Assert\Assertion;
14+
use Brainbits\Transcoder\Exception\DecodeFailedException;
1415

1516
/**
1617
* Gzip decoder
@@ -27,7 +28,11 @@ class GzipDecoder implements DecoderInterface
2728
public function decode($data)
2829
{
2930
$data = gzdecode($data);
30-
Assertion::minLength($data, 1, 'gzdecode returned no data');
31+
32+
if (!$data) {
33+
throw new DecodeFailedException("gzinflate returned no data.");
34+
}
35+
3136
return $data;
3237
}
3338

src/Brainbits/Transcoder/Decoder/NullDecoder.php renamed to src/Decoder/NullDecoder.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.

src/Brainbits/Transcoder/Decoder/SevenzDecoder.php renamed to src/Decoder/SevenzDecoder.php

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

1112
namespace Brainbits\Transcoder\Decoder;
1213

14+
use Brainbits\Transcoder\Exception\DecodeFailedException;
15+
use Symfony\Component\Process\Process;
1316
use Symfony\Component\Process\ProcessBuilder;
1417

1518
/**
@@ -39,18 +42,6 @@ public function __construct($executable = '7z')
3942
$this->executable = $executable;
4043
}
4144

42-
/**
43-
* @return \Symfony\Component\Process\Process
44-
*/
45-
public function getProcess()
46-
{
47-
$processBuilder = new ProcessBuilder(
48-
[$this->executable, 'e', '-si', '-so', '-an', '-txz', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m']
49-
);
50-
$processBuilder->setInput($this->data);
51-
return $processBuilder->getProcess();
52-
}
53-
5445
/**
5546
* Return executable
5647
*
@@ -74,7 +65,7 @@ public function decode($data)
7465
if ($process->isSuccessful()) {
7566
$data = $process->getOutput();
7667
} else {
77-
throw new \Exception('7z failure: '.$process->getOutput().$process->getErrorOutput());
68+
throw new DecodeFailedException('7z failure: '.$process->getOutput().$process->getErrorOutput());
7869
}
7970

8071
return $data;
@@ -87,4 +78,16 @@ public function supports($type)
8778
{
8879
return self::TYPE === $type;
8980
}
81+
82+
/**
83+
* @return Process
84+
*/
85+
private function getProcess()
86+
{
87+
$processBuilder = new ProcessBuilder(
88+
[$this->executable, 'e', '-si', '-so', '-an', '-txz', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m']
89+
);
90+
$processBuilder->setInput($this->data);
91+
return $processBuilder->getProcess();
92+
}
9093
}

src/Brainbits/Transcoder/Encoder/Bzip2Encoder.php renamed to src/Encoder/Bzip2Encoder.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
2-
/**
2+
3+
/*
34
* This file is part of the brainbits transcoder package.
45
*
5-
* (c) 2012-2013 brainbits GmbH (http://www.brainbits.net)
6+
* (c) brainbits GmbH
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
910
*/
1011

1112
namespace Brainbits\Transcoder\Encoder;
1213

13-
use Assert\Assertion;
14+
use Brainbits\Transcoder\Exception\EncodeFailedException;
1415

1516
/**
1617
* bzip2 encoder
@@ -28,7 +29,9 @@ public function encode($data)
2829
{
2930
$data = bzcompress($data, 9);
3031

31-
Assertion::minLength($data, 1, 'bzcompress returned no data');
32+
if (!$data) {
33+
throw new EncodeFailedException("bzcompress returned no data.");
34+
}
3235

3336
return $data;
3437
}

0 commit comments

Comments
 (0)