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 ( e263f3...74da5c )
by Tom Van
23s
created

Aperture   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 117
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A setFNumber() 0 4 1
A getFNumber() 0 4 1
A fromFocalLength() 0 20 4
A fromAperture() 0 6 1
A jsonSerialize() 0 4 1
A __toString() 0 7 1
1
<?php
2
/**
3
 * PHP Exif Aperture 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 \InvalidArgumentException;
16
use \JsonSerializable;
17
use \RuntimeException;
18
19
/**
20
 * Aperture class
21
 *
22
 * A value object to describe the Aperture f-number
23
 *
24
 * @category    PHPExif
25
 * @package     Common
26
 */
27
class Aperture implements JsonSerializable
28
{
29
    /**
30
     * The f-number
31
     *
32
     * @see https://en.wikipedia.org/wiki/F-number
33
     *
34
     * @var float
35
     */
36
    private $fNumber;
37
38
    /**
39
     * @param float $fNumber
40
     *
41
     * @throws InvalidArgumentException If given f-number is not a float
42
     */
43
    public function __construct($fNumber)
44
    {
45
        if (!is_float($fNumber) && !is_int($fNumber)) {
46
            throw new InvalidArgumentException('fNumber must be an integer or float');
47
        }
48
49
        $this->setFNumber($fNumber);
50
    }
51
52
    /**
53
     * Sets the fNumber
54
     *
55
     * @param float|int $fNumber
56
     *
57
     * @return void
58
     */
59
    private function setFNumber($fNumber)
60
    {
61
        $this->fNumber = $fNumber;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fNumber can also be of type integer. However, the property $fNumber is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
62
    }
63
64
    /**
65
     * Getter for fNumber
66
     *
67
     * @return float|int
68
     */
69
    public function getFNumber()
70
    {
71
        return $this->fNumber;
72
    }
73
74
    /**
75
     * Creates new instance from given Focal Length format
76
     *
77
     * Format:
78
     *          f/<f-number>
79
     *
80
     * @param string $focalLength
81
     *
82
     * @throws \InvalidArgumentException If focalLength is not a string
83
     *
84
     * @return Aperture
85
     */
86
    public static function fromFocalLength($focalLength)
87
    {
88
        if (!is_string($focalLength)) {
89
            throw new InvalidArgumentException('focalLength must be a string');
90
        }
91
92
        if (!preg_match('#^f/([0-9]*\.[0-9]+|[0-9]*)$#', $focalLength, $matches)) {
93
            throw new RuntimeException('Given focalLength is not in a valid format. Need: "f/<number>"');
94
        }
95
96
        $fNumber = $matches[1];
97
98
        if (($filtered = filter_var($fNumber, FILTER_VALIDATE_INT)) !== false) {
99
            $fNumber = $filtered;
100
        } else {
101
            $fNumber = (float) $fNumber;
102
        }
103
104
        return new self($fNumber);
105
    }
106
107
    /**
108
     * Creates a new instance from given Aperture object
109
     *
110
     * @param Aperture $aperture
111
     *
112
     * @return Aperture
113
     */
114
    public static function fromAperture(Aperture $aperture)
115
    {
116
        return new self(
117
            $aperture->getFNumber()
118
        );
119
    }
120
121
    /**
122
     * @inheritDoc
123
     *
124
     * @return string
125
     */
126
    public function jsonSerialize()
127
    {
128
        return (string) $this;
129
    }
130
131
    /**
132
     * Returns string representation
133
     *
134
     * @return string
135
     */
136
    public function __toString()
137
    {
138
        return sprintf(
139
            'f/%1$s',
140
            $this->getFNumber()
141
        );
142
    }
143
}
144