Completed
Pull Request — develop (#2)
by Tom Van
03:35
created

ApertureFieldMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 41
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedFields() 6 6 1
A mapField() 13 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Mapper for mapping data between raw input and an Aperture VO
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\Data\ValueObject\Aperture;
16
use PHPExif\Common\Mapper\FieldMapper;
17
use PHPExif\Common\Mapper\GuardInvalidArgumentsForExifTrait;
18
19
/**
20
 * Mapper
21
 *
22
 * @category    PHPExif
23
 * @package     Exiftool
24
 */
25 View Code Duplication
class ApertureFieldMapper implements FieldMapper
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
26
{
27
    use GuardInvalidArgumentsForExifTrait;
28
    use ValidKeysTrait;
29
30
    /**
31
     * @var array
32
     */
33
    private $validKeys = [
34
        'composite:aperture',
35
        'exififd:fnumber',
36
        'exififd:aperturevalue',
37
    ];
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function getSupportedFields()
43
    {
44
        return array(
45
            Aperture::class,
46
        );
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function mapField($field, array $input, &$output)
53
    {
54
        $this->guardInvalidArguments($field, $input, $output);
55
56
        foreach ($this->validKeys as $key) {
57
            if (!array_key_exists($key, $input)) {
58
                continue;
59
            }
60
61
            $aperture = new Aperture($input[$key]);
62
            $output = $output->withAperture($aperture);
63
        }
64
    }
65
}
66