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

GuardInvalidArgumentsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 25
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A guardInvalidArguments() 10 10 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
 * Trait with method to validate arguments of ::mapField
4
 * from Iptc\*Mapper classes
5
 *
6
 * @link        http://github.com/PHPExif/php-exif-native for the canonical source repository
7
 * @copyright   Copyright (c) 2016 Tom Van Herreweghe <[email protected]>
8
 * @license     http://github.com/PHPExif/php-exif-native/blob/master/LICENSE MIT License
9
 * @category    PHPExif
10
 * @package     Native
11
 */
12
13
namespace PHPExif\Adapter\Native\Reader\Mapper\Iptc;
14
15
use PHPExif\Common\Data\IptcInterface;
16
use PHPExif\Common\Exception\Mapper\UnsupportedFieldException;
17
use PHPExif\Common\Exception\Mapper\UnsupportedOutputException;
18
19
/**
20
 * Common method to check the arguments of an Iptc\* mapper
21
 *
22
 * @category    PHPExif
23
 * @package     Native
24
 */
25 View Code Duplication
trait GuardInvalidArgumentsTrait
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
    /**
28
     * Guard function for invalid arguments
29
     *
30
     * @param string $field
31
     * @param array $input
32
     * @param object $output
33
     *
34
     * @throws UnsupportedFieldException when asked to map an unsupported field
35
     * @throws UnsupportedOutputException when asked to map data on an unsupported output object
36
     *
37
     * @return void
38
     */
39
    private function guardInvalidArguments($field, array $input, $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        if (!in_array($field, $this->getSupportedFields())) {
0 ignored issues
show
Bug introduced by
It seems like getSupportedFields() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
42
            throw UnsupportedFieldException::forField($field);
43
        }
44
45
        if (!($output instanceof IptcInterface)) {
46
            throw UnsupportedOutputException::forOutput($output);
47
        }
48
    }
49
}
50