CalcFunc   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A calculate() 0 17 2
A __construct() 0 2 1
1
<?php
2
3
namespace App\Calculator;
4
5
use Exception;
6
use Jaxon\App\Dialog\DialogTrait;
7
use Jaxon\App\FuncComponent;
8
use Service\Calculator\CalculatorService;
9
10
class CalcFunc extends FuncComponent
11
{
12
    use DialogTrait;
0 ignored issues
show
Bug introduced by
The trait Jaxon\App\Dialog\DialogTrait requires the property $dialog which is not provided by App\Calculator\CalcFunc.
Loading history...
13
14
    /**
15
     * @param CalculatorService $calculator
16
     */
17
    public function __construct(private CalculatorService $calculator)
18
    {}
19
20
    /**
21
     * @param string $operator
22
     * @param string $operandA
23
     * @param string $operandB
24
     *
25
     * @return void
26
     */
27
    public function calculate(string $operator, string $operandA, string $operandB): void
28
    {
29
        $operator = trim($operator);
30
        $operandA = trim($operandA);
31
        $operandB = trim($operandB);
32
        try
33
        {
34
            $result = $this->calculator->calculate($operator, $operandA, $operandB);
35
            // Share the result value with the other components.
36
            $this->stash()->set('calculator.operator', $operator);
37
            $this->stash()->set('calculator.result', $result);
38
            // Render the result component.
39
            $this->cl(Result::class)->render();
40
        }
41
        catch(Exception $e)
42
        {
43
            $this->alert()->title('Error!!!')->error($e->getMessage());
44
        }
45
    }
46
}
47