Use latest fix
This commit is contained in:
parent
92121bb804
commit
0736141e16
3 changed files with 22 additions and 33 deletions
|
|
@ -37,18 +37,14 @@ abstract class AbstractData implements \Countable
|
||||||
* Returns the property value given its name.
|
* Returns the property value given its name.
|
||||||
*
|
*
|
||||||
* @param string $property
|
* @param string $property
|
||||||
* @param mixed $default [optional]
|
* @param mixed $default
|
||||||
* @return mixed
|
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException In case the data does not have the property
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get($property, $default = null)
|
public function get($property, $default = null)
|
||||||
{
|
{
|
||||||
if (!isset($this->properties[$property])) {
|
if (!isset($this->properties[$property])) {
|
||||||
if(!is_null($default)){
|
return $default;
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
throw new InvalidArgumentException(sprintf('Invalid property `%s`.', $property));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->properties[$property];
|
return $this->properties[$property];
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Stream extends AbstractData
|
||||||
*/
|
*/
|
||||||
public function isAudio()
|
public function isAudio()
|
||||||
{
|
{
|
||||||
return $this->has('codec_type') ? 'audio' === $this->get('codec_type') : false;
|
return $this->get('codec_type') === 'audio';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,7 +34,7 @@ class Stream extends AbstractData
|
||||||
*/
|
*/
|
||||||
public function isVideo()
|
public function isVideo()
|
||||||
{
|
{
|
||||||
return $this->has('codec_type') ? 'video' === $this->get('codec_type') : false;
|
return $this->get('codec_type') === 'video';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,14 +51,11 @@ class Stream extends AbstractData
|
||||||
throw new LogicException('Dimensions can only be retrieved from video streams.');
|
throw new LogicException('Dimensions can only be retrieved from video streams.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = $height = $sampleRatio = $displayRatio = null;
|
$sampleRatio = $displayRatio = null;
|
||||||
|
|
||||||
|
$width = $this->get('width');
|
||||||
|
$height = $this->get('height');
|
||||||
|
|
||||||
if ($this->has('width')) {
|
|
||||||
$width = $this->get('width');
|
|
||||||
}
|
|
||||||
if ($this->has('height')) {
|
|
||||||
$height = $this->get('height');
|
|
||||||
}
|
|
||||||
if (null !== $ratio = $this->extractRatio($this, 'sample_aspect_ratio')) {
|
if (null !== $ratio = $this->extractRatio($this, 'sample_aspect_ratio')) {
|
||||||
$sampleRatio = $ratio;
|
$sampleRatio = $ratio;
|
||||||
}
|
}
|
||||||
|
|
@ -93,18 +90,18 @@ class Stream extends AbstractData
|
||||||
*/
|
*/
|
||||||
private function extractRatio(Stream $stream, $name)
|
private function extractRatio(Stream $stream, $name)
|
||||||
{
|
{
|
||||||
if ($stream->has($name)) {
|
if (!$stream->has($name)) {
|
||||||
$ratio = $stream->get($name);
|
return;
|
||||||
if (preg_match('/\d+:\d+/', $ratio)) {
|
|
||||||
$data = array_filter(explode(':', $ratio), function ($int) {
|
|
||||||
return $int > 0;
|
|
||||||
});
|
|
||||||
if (2 === count($data)) {
|
|
||||||
return array_map(function ($int) { return (int) $int; }, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
$ratio = $stream->get($name);
|
||||||
|
if (preg_match('/\d+:\d+/', $ratio)) {
|
||||||
|
$data = array_filter(explode(':', $ratio), function ($int) {
|
||||||
|
return $int > 0;
|
||||||
|
});
|
||||||
|
if (2 === count($data)) {
|
||||||
|
return array_map(function ($int) { return (int) $int; }, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,10 @@ class AbstractDataTest extends TestCase
|
||||||
$this->assertEquals('value2', $imp->get('key2'));
|
$this->assertEquals('value2', $imp->get('key2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testGetDefault()
|
||||||
* @expectedException FFMpeg\Exception\InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function testGetInvalid()
|
|
||||||
{
|
{
|
||||||
$imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2'));
|
$imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2'));
|
||||||
|
$this->assertSame('yololo', $imp->get('key3', 'yololo'));
|
||||||
$imp->get('key3');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testKeys()
|
public function testKeys()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue