55use PHPExif \Exif ;
66use InvalidArgumentException ;
77use PHPExif \Mapper \Exiftool as MapperExiftool ;
8- use RuntimeException ;
8+ use PHPExif \ Reader \ PhpExifReaderException ;
99use Safe \Exceptions \ExecException ;
1010
11+ use Safe \Exceptions \JsonException ;
12+
1113use function Safe \exec ;
1214use function Safe \json_decode ;
1315use function Safe \stream_get_contents ;
2325 */
2426class Exiftool extends AbstractAdapter
2527{
26- const TOOL_NAME = 'exiftool ' ;
28+ public const TOOL_NAME = 'exiftool ' ;
2729
2830 /**
2931 * Path to the exiftool binary
@@ -40,7 +42,7 @@ class Exiftool extends AbstractAdapter
4042 * @return \PHPExif\Adapter\Exiftool Current instance
4143 * @throws \InvalidArgumentException When path is invalid
4244 */
43- public function setToolPath (string $ path ) : Exiftool
45+ public function setToolPath (string $ path ): Exiftool
4446 {
4547 if (!file_exists ($ path )) {
4648 throw new InvalidArgumentException (
@@ -59,7 +61,7 @@ public function setToolPath(string $path) : Exiftool
5961 /**
6062 * @param boolean $numeric
6163 */
62- public function setNumeric (bool $ numeric ) : void
64+ public function setNumeric (bool $ numeric ): void
6365 {
6466 $ this ->numeric = $ numeric ;
6567 }
@@ -68,7 +70,7 @@ public function setNumeric(bool $numeric) : void
6870 * @see http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10
6971 * @param array $encodings encoding parameters in an array eg. ["exif" => "UTF-8"]
7072 */
71- public function setEncoding (array $ encodings ) : void
73+ public function setEncoding (array $ encodings ): void
7274 {
7375 $ possible_keys = array ("exif " , "iptc " , "id3 " , "photoshop " , "quicktime " ,);
7476 $ possible_values = array ("UTF8 " , "cp65001 " , "UTF-8 " , "Thai " , "cp874 " , "Latin " , "cp1252 " ,
@@ -90,7 +92,7 @@ public function setEncoding(array $encodings) : void
9092 *
9193 * @return string
9294 */
93- public function getToolPath () : string
95+ public function getToolPath (): string
9496 {
9597 if ($ this ->toolPath === '' ) {
9698 try {
@@ -109,10 +111,10 @@ public function getToolPath() : string
109111 * Reads & parses the EXIF data from given file
110112 *
111113 * @param string $file
112- * @return \PHPExif\ Exif Instance of Exif object with data
113- * @throws \RuntimeException If the EXIF data could not be read
114+ * @return Exif Instance of Exif object with data
115+ * @throws PhpExifReaderException If the EXIF data could not be read
114116 */
115- public function getExifFromFile (string $ file ) : Exif
117+ public function getExifFromFile (string $ file ): Exif
116118 {
117119 $ encoding = '' ;
118120 if (count ($ this ->encoding ) > 0 ) {
@@ -136,14 +138,20 @@ public function getExifFromFile(string $file) : Exif
136138 );
137139
138140 /**
139- * @var string
141+ * @var string $result
140142 */
141143 $ result = $ this ->convertToUTF8 ($ result );
142144
143- $ data = json_decode ($ result , true );
145+ try {
146+ $ data = json_decode ($ result , true );
147+ } catch (JsonException $ e ) {
148+ // @codeCoverageIgnoreStart
149+ $ data = false ;
150+ // @codeCoverageIgnoreStart
151+ }
144152 if (!is_array ($ data )) {
145153 // @codeCoverageIgnoreStart
146- throw new RuntimeException (
154+ throw new PhpExifReaderException (
147155 'Could not decode exiftool output '
148156 );
149157 // @codeCoverageIgnoreEnd
@@ -171,9 +179,9 @@ public function getExifFromFile(string $file) : Exif
171179 *
172180 * @param string $command
173181 * @return string|false
174- * @throws RuntimeException If the command can't be executed
182+ * @throws PhpExifReaderException If the command can't be executed
175183 */
176- protected function getCliOutput (string $ command ) : string |false
184+ protected function getCliOutput (string $ command ): string |false
177185 {
178186 $ descriptorspec = array (
179187 0 => array ('pipe ' , 'r ' ),
@@ -184,7 +192,7 @@ protected function getCliOutput(string $command) : string|false
184192 $ process = proc_open ($ command , $ descriptorspec , $ pipes );
185193
186194 if (!is_resource ($ process )) {
187- throw new RuntimeException (
195+ throw new PhpExifReaderException (
188196 'Could not open a resource to the exiftool binary '
189197 );
190198 }
0 commit comments