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 ( 830558...a16a6e )
by Tom Van
45s
created

FocalLength::fromFocalLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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