diff --git a/README.md b/README.md index 63638f0..e5a632e 100644 --- a/README.md +++ b/README.md @@ -14,24 +14,24 @@ use Sikofitt\GenerateMac\Mac; $mac = new Mac(); // default is ':' // or -$mac->setSeparator(':'); +$mac->setSeparator(Mac::SEPARATOR_COLON); $address = $mac->getAddress(); // ab:cd:ef:01:23:45 -$mac = new Mac('-'); +$mac = new Mac(Mac::SEPARATOR_DASH); // or -$mac->setSeparator('-'); +$mac->setSeparator(Mac::SEPARATOR_DASH); $address = $mac->getAddress(); // ab-cd-ef-01-23-45 -$mac = new Mac(''); +$mac = new Mac(Mac::SEPARATOR_NONE); // or -$mac->setSeparator(''); +$mac->setSeparator(Mac::SEPARATOR_NONE); $address = $mac->getAddress(); // abcdef012345 ``` If you don't care that it is unique you can remove the check for private mac prefixes. ```php -$mac = new Mac(':', false); +$mac = new Mac(Mac::SEPARATOR_COLON, false); // or $mac->setUnique(false); diff --git a/src/GenerateMac/Command/GenerateMacCommand.php b/src/GenerateMac/Command/GenerateMacCommand.php index 23a21eb..0d224ab 100644 --- a/src/GenerateMac/Command/GenerateMacCommand.php +++ b/src/GenerateMac/Command/GenerateMacCommand.php @@ -29,7 +29,6 @@ use Symfony\Component\Console\Input\{ InputInterface, InputOption }; -use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; diff --git a/src/GenerateMac/Mac.php b/src/GenerateMac/Mac.php index 56d6f0b..bb8f47c 100644 --- a/src/GenerateMac/Mac.php +++ b/src/GenerateMac/Mac.php @@ -21,6 +21,9 @@ namespace Sikofitt\GenerateMac; class Mac { + public const SEPARATOR_COLON = 0; + public const SEPARATOR_DASH = 1; + public const SEPARATOR_NONE = 2; /** * Private mac address prefixes that are used * internally or with virtual machines and containers. @@ -58,10 +61,6 @@ class Mac 'xexxxx', ]; - public const SEPARATOR_COLON = 0; - public const SEPARATOR_DASH = 1; - public const SEPARATOR_NONE = 2; - /** * @internal * @var bool For testing that we get a prefix that is not used. @@ -177,6 +176,24 @@ class Mac return $this->separator; } + /** + * Helper to get the separator in string format + * + * @return string + */ + public function getSeparatorAsString(): string + { + switch ($this->getSeparator()) { + default: + case self::SEPARATOR_COLON: + return ':'; + case self::SEPARATOR_DASH: + return '-'; + case self::SEPARATOR_NONE: + return ''; + } + } + /** * Test to see if we have a unique prefix. * @@ -219,19 +236,6 @@ class Mac return \current($prefixes); } - private function getSeparatorAsString(): string - { - switch($this->getSeparator()) { - default: - case self::SEPARATOR_COLON: - return ':'; - case self::SEPARATOR_DASH: - return '-'; - case self::SEPARATOR_NONE: - return ''; - } - } - /** * Inserts the chosen separator. * @@ -241,7 +245,6 @@ class Mac */ private function insertSeparator(string $macAddress): string { - return implode($this->getSeparatorAsString(), str_split($macAddress, 2)); } }