More over engineering.

TBH at this point I think I need a DI container.
This commit is contained in:
2019-03-27 15:25:08 +01:00
parent 950193edee
commit 882214d6ea
3 changed files with 52 additions and 5 deletions

View File

@@ -60,9 +60,4 @@ class Configuration
{ {
return $this->stateFile; return $this->stateFile;
} }
public function isOpen(): bool
{
return file_exists($this->stateFile);
}
} }

13
src/ReadableState.php Normal file
View 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
View 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;
}
}
}