Skip to content

Commit

Permalink
Filter for arithmetic operations laminas#28
Browse files Browse the repository at this point in the history
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
  • Loading branch information
fgsl committed Dec 2, 2021
1 parent 15298c7 commit a0f1c53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/FourOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(array $options)
if (!isset($options['operation']) || (!in_array($options['operation'],$operations))){
throw new InvalidArgumentException(sprintf(
'%s expects argument operation string with one of theses values: add, sub, mul or div; received "%s"',
__METHOD__, $options['operation']));
__METHOD__, (float) $options['operation']));
}
if (!isset($options['value'])){
throw new InvalidArgumentException(sprintf(
Expand All @@ -36,7 +36,8 @@ public function __construct(array $options)

public function filter($value)
{
$operand = $this->options['value'];
$value = (float) $value;
$operand = (float) $this->options['value'];
switch ($this->options['operation']){
case self::ADD:
return ($value + $operand);
Expand Down
2 changes: 1 addition & 1 deletion test/FourOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FourOperationsTest extends TestCase
{
public function testOperations()
public function testOperations(): void
{
$filter = new FourOperations(['operation'=>'add','value'=>4]);
$this->assertEquals(9, $filter->filter(5));
Expand Down

0 comments on commit a0f1c53

Please sign in to comment.