Skip to content

Commit

Permalink
Add usage section on README
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Mar 23, 2019
1 parent 207af37 commit c62f885
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Dependency Calculator


## Introduction
- This is the demonsration for SITCON 2019 talk.

## Usage
Here is some examples about how to calculate two numbers.

### Add two numbers
```php
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;

$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());

echo $gmpCalculator->add('123456789', '123456789000000'); // 123456912456789
echo $bcMathCalculator->add('123456789', '123456789000000'); // 123456912456789
```

### Minus two numbers
```php
use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;

$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());

echo $gmpCalculator->minus('123456789', '123456789000000'); // -123456665543211
echo $bcMathCalculator->minus('123456789', '123456789000000'); // -123456665543211
```

### Multiple two numbers
```php

use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;

$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());

echo $gmpCalculator->mul('123456789', '123456789000000'); // 15241578750190521000000
echo $bcMathCalculator->mul('123456789', '123456789000000'); // 15241578750190521000000
```

### Divide two numbers
```php

use Lee\Calculator\Calculator;
use Lee\Calculator\modules\GmpCalculator;
use Lee\Calculator\modules\BcMathCalculator;

$gmpCalculator = new Calculator(new GmpCalculator());
$bcMathCalculator = new Calculator(new BcMathCalculator());

echo $gmpCalculator->divide('123456789000000', '123456789'); // 1000000
echo $bcMathCalculator->divide('123456789000000', '123456789'); // 1000000
```
2 changes: 1 addition & 1 deletion src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lee\Calculator;

use Lee\Calculator\interfaces\CalculatorInterface;
use Lee\Calculator\interfaces\Calculator as CalculatorInterface;

class Calculator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lee\Calculator\interfaces;

interface CalculatorInterface
interface Calculator
{
public function add(string $num1, string $num2): string;
public function minus(string $num1, string $num2): string;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/BcMathCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Lee\Calculator\modules;

use Lee\Calculator\interfaces\CalculatorInterface;
use Lee\Calculator\interfaces\Calculator;

class BcMathCalculator implements CalculatorInterface
class BcMathCalculator implements Calculator
{
public function add(string $num1, string $num2): string
{
Expand All @@ -30,7 +30,7 @@ public function mul(string $num1, string $num2): string
public function divide(string $num1, string $num2): string
{
if ((int)$num2 === 0) {
throw \InvalidArgumentException('The zero operand not allowed!');
throw new \InvalidArgumentException('The zero operand not allowed!');
}

return \bcdiv($num1, $num2);
Expand Down
6 changes: 3 additions & 3 deletions src/modules/GmpCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Lee\Calculator\modules;

use Lee\Calculator\interfaces\CalculatorInterface;
use Lee\Calculator\interfaces\Calculator;

class GmpCalculator implements CalculatorInterface
class GmpCalculator implements Calculator
{
public function add(string $num1, string $num2): string
{
Expand All @@ -30,7 +30,7 @@ public function mul(string $num1, string $num2): string
public function divide(string $num1, string $num2): string
{
if ((int)$num2 === 0) {
throw \InvalidArgumentException('The zero operand not allowed!');
throw new \InvalidArgumentException('The zero operand not allowed!');
}

return \gmp_div($num1, $num2);
Expand Down

0 comments on commit c62f885

Please sign in to comment.