More over engineering.
TBH at this point I think I need a DI container.
This commit is contained in:
@@ -60,9 +60,4 @@ class Configuration
|
||||
{
|
||||
return $this->stateFile;
|
||||
}
|
||||
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return file_exists($this->stateFile);
|
||||
}
|
||||
}
|
||||
|
||||
13
src/ReadableState.php
Normal file
13
src/ReadableState.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace FooBar;
|
||||
|
||||
interface ReadableState
|
||||
{
|
||||
/**
|
||||
* Check whether the FooBar is open
|
||||
*
|
||||
* @return bool true if the FooBar is open.
|
||||
*/
|
||||
public function isOpen(): bool;
|
||||
}
|
||||
39
src/State.php
Normal file
39
src/State.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace FooBar;
|
||||
|
||||
class State implements ReadableState
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct(Configuration $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the FooBar is open
|
||||
*
|
||||
* @return bool true if the FooBar is open.
|
||||
*/
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return file_exists($this->config->stateFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the current state of the FooBar.
|
||||
*
|
||||
* @return bool the new state of the FooBar.
|
||||
*/
|
||||
public function toggle(): bool
|
||||
{
|
||||
if ($this->isOpen()) {
|
||||
unlink($this->config->stateFile());
|
||||
return false;
|
||||
} else {
|
||||
touch($this->config->stateFile());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user