-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLinearEquation.php
More file actions
47 lines (40 loc) · 940 Bytes
/
Copy pathLinearEquation.php
File metadata and controls
47 lines (40 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace DesignPatterns\Structural\Bridge\Equation;
use DesignPatterns\Structural\Bridge\Math\MathImplInterface;
/**
* Linear equation `a * x + b = 0` that corresponds to `RefinedAbstraction` in the Bridge pattern.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class LinearEquation extends Equation
{
/**
* @var mixed
*/
private $a;
/**
* @var mixed
*/
private $b;
/**
* @param mixed $a
* @param mixed $b
*/
public function __construct($a, $b)
{
$this->a = $a;
$this->b = $b;
}
/**
* @throws \LogicException
*
* @return mixed
*/
public function solve()
{
if (!$this->mathImpl instanceof MathImplInterface) {
throw new \LogicException("Math engine should be set via setMathImpl method");
}
return $this->mathImpl->div($this->mathImpl->neg($this->b), $this->a);
}
}