Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplemented converter chain and introducd HEX to RGB Converter
- Loading branch information
Showing
2 changed files
with
48 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Artack\Color\Converter; | ||
|
||
use Artack\Color\Color\Color; | ||
use Artack\Color\Color\HEX; | ||
use Artack\Color\Color\RGB; | ||
use Webmozart\Assert\Assert; | ||
|
||
class HEXToRGBConverter implements Convertible | ||
{ | ||
public function convert(Color $color): Color | ||
{ | ||
/* @var HEX $color */ | ||
Assert::isInstanceOf($color, HEX::class, sprintf('color should be an instance of [%s]', HEX::class)); | ||
|
||
$red = hexdec($color->getRed()); | ||
$green = hexdec($color->getGreen()); | ||
$blue = hexdec($color->getBlue()); | ||
|
||
return new RGB($red, $green, $blue); | ||
} | ||
|
||
public static function supportsFrom(): string | ||
{ | ||
return HEX::class; | ||
} | ||
|
||
public static function supportsTo(): string | ||
{ | ||
return RGB::class; | ||
} | ||
} |