| 1 | <?php |
||
| 10 | class Pi extends BaseExample |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var float |
||
| 14 | */ |
||
| 15 | protected $estimation; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param int $throws |
||
| 19 | * |
||
| 20 | * @throws \Http\Client\Exception |
||
| 21 | * |
||
| 22 | * @return $this |
||
| 23 | * |
||
| 24 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 25 | */ |
||
| 26 | public function run($throws = 1000) |
||
| 27 | { |
||
| 28 | $provider = Provider::withResource('generateDecimalFractions') |
||
| 29 | ->withParameters(['n' => $throws * 2, 'decimalPlaces' => 6]); |
||
| 30 | |||
| 31 | $numbers = $this->getRandomOrgAPI()->getData($provider); |
||
| 32 | |||
| 33 | $inside = 0; |
||
| 34 | for ($i = 0; $i < $throws; $i++) { |
||
| 35 | $x = $numbers[$i]; |
||
|
|
|||
| 36 | $y = $numbers[$i+1]; |
||
| 37 | |||
| 38 | if (sqrt($x*$x + $y*$y) <= 1) { |
||
| 39 | $inside++; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->estimation = 4 * $inside/$throws; |
||
| 44 | |||
| 45 | return $this; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return float |
||
| 50 | */ |
||
| 51 | public function get() |
||
| 55 | } |
||
| 56 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.