GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#4)
by Tom Van
03:38
created

MapperFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 57.14 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 48
loc 84
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapper() 0 15 1
B getExifMapper() 24 24 2
B getIptcMapper() 24 24 2

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
 * Factory for wiring all the different mappers
4
 *
5
 * @link        http://github.com/PHPExif/php-exif-native for the canonical source repository
6
 * @copyright   Copyright (c) 2016 Tom Van Herreweghe <[email protected]>
7
 * @license     http://github.com/PHPExif/php-exif-native/blob/master/LICENSE MIT License
8
 * @category    PHPExif
9
 * @package     Native
10
 */
11
12
namespace PHPExif\Adapter\Native\Reader;
13
14
use PHPExif\Adapter\Native\Reader\Mapper\ExifMapper;
15
use PHPExif\Adapter\Native\Reader\Mapper\IptcMapper;
16
17
/**
18
 * MapperFactory
19
 *
20
 * Registers all available mappers
21
 *
22
 * @category    PHPExif
23
 * @package     Native
24
 */
25
class MapperFactory
26
{
27
    /**
28
     * Returns a Mapper instance complete with all sub-mappers
29
     * registered
30
     *
31
     * @return Mapper
32
     */
33
    public static function getMapper()
34
    {
35
        $exifMapper = self::getExifMapper();
36
        $iptcMapper = self::getIptcMapper();
37
38
        $mapper = new Mapper();
39
        $mapper->registerFieldMapper(
40
            $exifMapper
41
        );
42
        $mapper->registerFieldMapper(
43
            $iptcMapper
44
        );
45
46
        return $mapper;
47
    }
48
49
    /**
50
     * Returns the mapper for Exif data
51
     *
52
     * @return ExifMapper
53
     */
54 View Code Duplication
    private static function getExifMapper()
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        $exifMapper = new ExifMapper();
57
58
        // find all classes
59
        $reflClass = new \ReflectionClass(ExifMapper::class);
60
        $namespace = $reflClass->getNamespaceName();
61
        $namespace .= '\\Exif';
62
63
        $path = realpath(__DIR__ . '/Mapper/Exif');
64
65
        foreach (glob($path . '/*Mapper.php') as $classPath) {
66
            $className = str_replace('.php', '', array_reverse(
67
                explode(DIRECTORY_SEPARATOR, $classPath)
68
            )[0]);
69
            $fqcn = $namespace . '\\' . $className;
70
71
            $fieldMapper = new $fqcn();
72
73
            $exifMapper->registerFieldMapper($fieldMapper);
74
        }
75
76
        return $exifMapper;
77
    }
78
79
    /**
80
     * Returns the mapper for Iptc data
81
     *
82
     * @return IptcMapper
83
     */
84 View Code Duplication
    private static function getIptcMapper()
0 ignored issues
show
Duplication introduced by
This method 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...
85
    {
86
        $iptcMapper = new IptcMapper();
87
88
        // find all classes
89
        $reflClass = new \ReflectionClass(IptcMapper::class);
90
        $namespace = $reflClass->getNamespaceName();
91
        $namespace .= '\\Iptc';
92
93
        $path = realpath(__DIR__ . '/Mapper/Iptc');
94
95
        foreach (glob($path . '/*Mapper.php') as $classPath) {
96
            $className = str_replace('.php', '', array_reverse(
97
                explode(DIRECTORY_SEPARATOR, $classPath)
98
            )[0]);
99
            $fqcn = $namespace . '\\' . $className;
100
101
            $fieldMapper = new $fqcn();
102
103
            $iptcMapper->registerFieldMapper($fieldMapper);
104
        }
105
106
        return $iptcMapper;
107
    }
108
}
109