Refactored main class, improved a few things here and there. Looks polished enough

This commit is contained in:
Netkas 2023-06-18 17:17:13 -04:00
parent 75c6062a3e
commit 411898af2a
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
14 changed files with 351 additions and 300 deletions

View file

@ -3,57 +3,44 @@
class ExampleClass
{
/**
* @var array
* Sleeps for the given number of seconds, plus a random number of seconds between 0 and 100.
*
* @param int $seconds
* @return int
* @throws Exception
*/
private $data;
/**
* ExampleClass constructor.
*/
public function __construct()
public function sleep(int $seconds=1): int
{
$this->data = [];
sleep($seconds);
return random_int(0, 100) + $seconds;
}
/**
* Sets a value in the data array
* 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.
*
* @param string $key
* @param mixed $value
* @return void
* @throws Exception
*/
public function set(string $key, mixed $value): void
public function throwException(): void
{
$this->data[$key] = $value;
}
/**
* Gets a value from the data array
*
* @param string $key
* @return mixed
*/
public function get(string $key): mixed
{
return $this->data[$key];
}
/**
* Checks if a key exists in the data array
*
* @param string $key
* @return bool
*/
public function exists(string $key): bool
{
return isset($this->data[$key]);
}
/**
* @return void
*/
public function clear(): void
{
$this->data = [];
throw new Exception('This is an exception.');
}
}