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
Push — develop ( 2ad4a9...13b53f )
by Tom Van
25s
created

LineResolution::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 3
eloc 10
nc 3
nop 2
1
<?php
2
/**
3
 * PHP Exif LineResolution 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
 */
11
12
namespace PHPExif\Common\Data\ValueObject;
13
14
use \InvalidArgumentException;
15
use \RuntimeException;
16
17
/**
18
 * LineResolution class
19
 *
20
 * A value object to describe the LineResolution data
21
 *
22
 * @category    PHPExif
23
 * @package     Common
24
 */
25
class LineResolution extends MeasuredObject
26
{
27
    /**
28
     * @inheritDoc
29
     *
30
     * @throws InvalidArgumentException If given argument is not a string
31
     */
32 View Code Duplication
    public function __construct($value, Unit $unit)
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...
33
    {
34
        if (!is_string($value)) {
35
            throw new InvalidArgumentException('Given value is not a string');
36
        }
37
38
        if (!preg_match('#^([0-9]+)/([0-9]+)$#', $value, $matches)) {
39
            throw new RuntimeException('Given resolution is not in a valid format. Need: "<number>/<number>"');
40
        }
41
42
        $numerator = (int) $matches[1];
43
        $denominator = (int) $matches[2];
44
45
        // normalize:
46
        $numerator /= $denominator;
47
48
        $this->setValue($numerator);
49
        $this->setUnit($unit);
50
    }
51
52
    /**
53
     * Creates a new instance from given Resolution object
54
     *
55
     * @param LineResolution $resolution
56
     *
57
     * @return LineResolution
58
     */
59
    public static function fromLineResolution(LineResolution $resolution)
60
    {
61
        return new self(
62
            $resolution->getValue() . '/1',
63
            (clone $resolution->getUnit())
64
        );
65
    }
66
67
    /**
68
     * Creates a new instance with given value and a
69
     * Unit of "dpi"
70
     *
71
     * @param mixed $value
72
     *
73
     * @return LineResolution
74
     */
75
    public static function dpi($value)
76
    {
77
        return new self(
78
            $value,
79
            new Unit('dpi')
80
        );
81
    }
82
}
83