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.

DefaultOperation::execute()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 6
nop 2
dl 0
loc 21
rs 9.0777
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChumakovAnton\Calculator;
6
7
use ChumakovAnton\Calculator\Exception\DivisionByZeroException;
8
9
/**
10
 * Class DefaultOperation
11
 * @package ChumakovAnton\Calculator
12
 */
13
class DefaultOperation implements Operation
14
{
15
    protected const OPERATION_PRIORITIES = [
16
        0 => ['+', '-'],
17
        1 => ['*', '/'],
18
    ];
19
20
    protected $operation;
21
22
    public function __construct(string $operation)
23
    {
24
        $this->operation = $operation;
25
    }
26
27
    /**
28
     * @param float $leftOperand
29
     * @param float $rightOperand
30
     * @return float|int
31
     * @throws DivisionByZeroException
32
     */
33
    public function execute(float $leftOperand, float $rightOperand)
34
    {
35
        $result = 0;
36
        switch ($this->operation) {
37
            case '+':
38
                $result = $leftOperand + $rightOperand;
39
                break;
40
            case '-':
41
                $result = $leftOperand - $rightOperand;
42
                break;
43
            case '*':
44
                $result = $leftOperand * $rightOperand;
45
                break;
46
            case '/':
47
                if (empty($rightOperand)) {
48
                    throw new DivisionByZeroException('Division by zero');
49
                }
50
                $result = $leftOperand / $rightOperand;
51
                break;
52
        }
53
        return $result;
54
    }
55
56
    public function getPriority(): int
57
    {
58
        foreach (self::OPERATION_PRIORITIES as $priority => $operations) {
59
            if (in_array($this->operation, $operations, true)) {
60
                return $priority;
61
            }
62
        }
63
        return 0;
64
    }
65
}
66