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.

ExposureTime   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 46.34 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 19 19 3
A fromExposureTime() 0 6 1

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
 * PHP Exif ExposureTime ValueObject
4
 *
5
 * @link        http://github.com/PHPExif/php-exif-common for the canonical source repository
6
 * @copyright   Copyright (c) 2016 Tom Van Herreweghe <[email protected]>
7
 * @license     http://github.com/PHPExif/php-exif-common/blob/master/LICENSE MIT License
8
 * @category    PHPExif
9
 * @package     Common
10
 * @codeCoverageIgnore
11
 */
12
13
namespace PHPExif\Common\Data\ValueObject;
14
15
use PHPExif\Common\Data\ValueObject\StringObject;
16
use \InvalidArgumentException;
17
use \RuntimeException;
18
19
/**
20
 * ExposureTime class
21
 *
22
 * A value object to describe the ExposureTime data
23
 *
24
 * @category    PHPExif
25
 * @package     Common
26
 */
27
class ExposureTime extends StringObject
28
{
29
    /**
30
     * @param string $stringData
31
     *
32
     * @throws InvalidArgumentException If given argument is not a string
33
     */
34 View Code Duplication
    public function __construct($stringData)
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...
35
    {
36
        if (!is_string($stringData)) {
37
            throw new InvalidArgumentException('Given data is not a string');
38
        }
39
40
        if (!preg_match('#^([0-9]+)/([0-9]+)s?$#', $stringData, $matches)) {
41
            throw new RuntimeException('Given exposure time is not in a valid format. 
42
                Need: "1/<number>" or "1/<number>s"');
43
        }
44
45
        $numerator = (int) $matches[1];
46
        $denominator = (int) $matches[2];
47
48
        // normalize:
49
        $denominator /= $numerator;
50
51
        $this->setStringData("1/{$denominator}");
52
    }
53
54
    /**
55
     * Creates a new instance from given ExposureTime object
56
     *
57
     * @param ExposureTime $exposureTime
58
     *
59
     * @return ExposureTime
60
     */
61
    public static function fromExposureTime(ExposureTime $exposureTime)
62
    {
63
        return new self(
64
            (string) $exposureTime
65
        );
66
    }
67
}
68