Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Improved main system implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelandrieu committed Jul 30, 2019
1 parent 4dd5226 commit 6be2cbc
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/Systems/MainSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Resiliency\Places\HalfOpened;

/**
* Implement the system described by the documentation.
* The main system is built with 4 places:
* - A Closed place
* - A Half Opened Place
Expand Down Expand Up @@ -74,14 +73,12 @@ public function getPlaces(): array
* @param array $settings the settings for the Places
*
* @return self
*
* @throws InvalidSystem
*/
public static function createFromArray(array $settings, Client $client): self
{
if (array_key_exists('failures', $settings)
&& array_key_exists('timeout', $settings)
&& array_key_exists('stripped_timeout', $settings)
&& array_key_exists('threshold', $settings)
) {
if (self::validate($settings)) {
return new self(
$client,
(int) $settings['failures'],
Expand All @@ -93,4 +90,20 @@ public static function createFromArray(array $settings, Client $client): self

throw InvalidSystem::missingSettings($settings);
}

/**
* Ensure the system is valid.
*
* @param array $settings the system settings
*
* @return bool
*/
private static function validate(array $settings)
{
return array_key_exists('failures', $settings)
&& array_key_exists('timeout', $settings)
&& array_key_exists('stripped_timeout', $settings)
&& array_key_exists('threshold', $settings)
;
}
}

0 comments on commit 6be2cbc

Please sign in to comment.