1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mapper for mapping data between raw input and a datetime object |
4
|
|
|
* |
5
|
|
|
* @category PHPExif |
6
|
|
|
* @copyright Copyright (c) 2016 Tom Van Herreweghe <[email protected]> |
7
|
|
|
* @license http://github.com/PHPExif/php-exif-exiftool/blob/master/LICENSE MIT License |
8
|
|
|
* @link http://github.com/PHPExif/php-exif-exiftool for the canonical source repository |
9
|
|
|
* @package Exiftool |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PHPExif\Adapter\Exiftool\Reader\Mapper\Exif; |
13
|
|
|
|
14
|
|
|
use PHPExif\Common\Data\ExifInterface; |
15
|
|
|
use PHPExif\Common\Mapper\FieldMapper; |
16
|
|
|
use PHPExif\Common\Mapper\GuardInvalidArgumentsForExifTrait; |
17
|
|
|
use \DateTimeImmutable; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Mapper |
21
|
|
|
* |
22
|
|
|
* @category PHPExif |
23
|
|
|
* @package Common |
24
|
|
|
*/ |
25
|
|
|
class DateTimeFieldMapper implements FieldMapper |
26
|
|
|
{ |
27
|
|
|
use GuardInvalidArgumentsForExifTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $validKeys = [ |
33
|
|
|
'system:filemodifydate', |
34
|
|
|
'composite:subsecdatetimeoriginal', |
35
|
|
|
'composite:subsecmodifydate', |
36
|
|
|
'exififd:datetimeoriginal', |
37
|
|
|
'exififd:createdate', |
38
|
|
|
'ifd0:modifydate', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Getter for validKeys |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function getValidKeys() |
47
|
|
|
{ |
48
|
|
|
return $this->validKeys; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Setter for validKeys |
53
|
|
|
* |
54
|
|
|
* @param array $validKeys |
55
|
|
|
*/ |
56
|
|
|
public function setValidKeys(array $validKeys) |
57
|
|
|
{ |
58
|
|
|
$this->validKeys = $validKeys; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
|
|
public function getSupportedFields() |
65
|
|
|
{ |
66
|
|
|
return array( |
67
|
|
|
DateTimeImmutable::class, |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritDoc} |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function mapField($field, array $input, &$output) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$this->guardInvalidArguments($field, $input, $output); |
77
|
|
|
|
78
|
|
|
foreach ($this->validKeys as $key) { |
79
|
|
|
if (!array_key_exists($key, $input)) { |
80
|
|
|
continue; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$datetimeOriginal = new DateTimeImmutable($input[$key]); |
84
|
|
|
$output = $output->withCreationDate($datetimeOriginal); |
85
|
|
|
break; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.