46 lines
No EOL
1.1 KiB
PHP
46 lines
No EOL
1.1 KiB
PHP
<?php
|
|
|
|
class ExampleClass
|
|
{
|
|
/**
|
|
* Sleeps for the given number of seconds, plus a random number of seconds between 0 and 100.
|
|
*
|
|
* @param int $seconds
|
|
* @return int
|
|
* @throws Exception
|
|
*/
|
|
public function sleep(int $seconds=1): int
|
|
{
|
|
sleep($seconds);
|
|
return random_int(0, 100) + $seconds;
|
|
}
|
|
|
|
/**
|
|
* Calculates pi using the Leibniz formula.
|
|
*
|
|
* @param int $iterations
|
|
* @return float
|
|
*/
|
|
public function pi(int $iterations): float
|
|
{
|
|
$pi = 0;
|
|
$sign = 1;
|
|
for ($i = 0; $i < $iterations; $i++)
|
|
{
|
|
$pi += $sign / (2 * $i + 1);
|
|
$sign *= -1;
|
|
}
|
|
return $pi * 4;
|
|
}
|
|
|
|
/**
|
|
* Throws an exception.
|
|
*
|
|
* @return void
|
|
* @throws Exception
|
|
*/
|
|
public function throwException(): void
|
|
{
|
|
throw new Exception('This is an exception.');
|
|
}
|
|
} |