diff --git a/src/FFMpeg/FFProbe/DataMapping/AbstractData.php b/src/FFMpeg/FFProbe/DataMapping/AbstractData.php index adfbd67..9e75483 100644 --- a/src/FFMpeg/FFProbe/DataMapping/AbstractData.php +++ b/src/FFMpeg/FFProbe/DataMapping/AbstractData.php @@ -37,18 +37,14 @@ abstract class AbstractData implements \Countable * Returns the property value given its name. * * @param string $property - * @param mixed $default [optional] - * @return mixed + * @param mixed $default * - * @throws InvalidArgumentException In case the data does not have the property + * @return mixed */ public function get($property, $default = null) { if (!isset($this->properties[$property])) { - if(!is_null($default)){ - return $default; - } - throw new InvalidArgumentException(sprintf('Invalid property `%s`.', $property)); + return $default; } return $this->properties[$property]; diff --git a/src/FFMpeg/FFProbe/DataMapping/Stream.php b/src/FFMpeg/FFProbe/DataMapping/Stream.php index 972c16d..3333453 100644 --- a/src/FFMpeg/FFProbe/DataMapping/Stream.php +++ b/src/FFMpeg/FFProbe/DataMapping/Stream.php @@ -24,7 +24,7 @@ class Stream extends AbstractData */ 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() { - 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.'); } - $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')) { $sampleRatio = $ratio; } @@ -93,18 +90,18 @@ class Stream extends AbstractData */ private function extractRatio(Stream $stream, $name) { - if ($stream->has($name)) { - $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); - } - } + if (!$stream->has($name)) { + return; } - 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); + } + } } } diff --git a/tests/FFMpeg/Tests/FFProbe/DataMapping/AbstractDataTest.php b/tests/FFMpeg/Tests/FFProbe/DataMapping/AbstractDataTest.php index d2a4d63..1e49c0f 100644 --- a/tests/FFMpeg/Tests/FFProbe/DataMapping/AbstractDataTest.php +++ b/tests/FFMpeg/Tests/FFProbe/DataMapping/AbstractDataTest.php @@ -25,14 +25,10 @@ class AbstractDataTest extends TestCase $this->assertEquals('value2', $imp->get('key2')); } - /** - * @expectedException FFMpeg\Exception\InvalidArgumentException - */ - public function testGetInvalid() + public function testGetDefault() { $imp = new Implementation(array('key1' => 'value1', 'key2' => 'value2')); - - $imp->get('key3'); + $this->assertSame('yololo', $imp->get('key3', 'yololo')); } public function testKeys()