diff --git a/src/ColorPair.php b/src/ColorPair.php index 3800c03..76a0ffb 100644 --- a/src/ColorPair.php +++ b/src/ColorPair.php @@ -17,7 +17,7 @@ public function __construct(float $ratio = null, string $color1 = null, string $ /** * '000' => '#000000' - * '000000' => '#000000' + * '000000' => '#000000'. */ // protected function normalize($color) // { diff --git a/src/HexColor.php b/src/HexColor.php index f60ee33..0dd7084 100644 --- a/src/HexColor.php +++ b/src/HexColor.php @@ -25,22 +25,22 @@ public static function random(): self /** * '#abc' or 'abc' => '#aabbcc' - * '#abcdef' or 'abcdef' => '#abcdef' + * '#abcdef' or 'abcdef' => '#abcdef'. */ protected function normalize(string $hexColor) { // '#abcdef' or 'abcdef' if (preg_match('/^\s*#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})\s*$/i', $hexColor, $matches)) { - return sprintf("#%s%s%s", $matches[1], $matches[2], $matches[3]); + return sprintf('#%s%s%s', $matches[1], $matches[2], $matches[3]); } // '#abc' or 'abc' if (preg_match('/^\s*#?([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i', $hexColor, $matches)) { - return sprintf("#%s%s%s", str_repeat($matches[1], 2), str_repeat($matches[2], 2), + return sprintf('#%s%s%s', str_repeat($matches[1], 2), str_repeat($matches[2], 2), str_repeat($matches[3], 2)); } - return null; // TODO throw + // TODO throw } /** @@ -48,7 +48,7 @@ protected function normalize(string $hexColor) */ protected static function randomColor() { - return static::randomColorPart() . static::randomColorPart() . static::randomColorPart(); + return static::randomColorPart().static::randomColorPart().static::randomColorPart(); } protected static function randomColorPart() diff --git a/src/HexColorPair.php b/src/HexColorPair.php index ed22be3..dca71ee 100644 --- a/src/HexColorPair.php +++ b/src/HexColorPair.php @@ -79,8 +79,8 @@ public function getSibling(string $hexValue): HexColor protected static function calculateRatio(HexColor $fg = null, HexColor $bg = null) { - if (!$fg || !$bg) { - return null; + if (! $fg || ! $bg) { + return; } $fgLuminance = static::luminance($fg); @@ -108,11 +108,11 @@ protected static function luminance(HexColor $color) $g = ($gSrgb <= 0.03928) ? $gSrgb / 12.92 : pow((($gSrgb + 0.055) / 1.055), 2.4); $b = ($bSrgb <= 0.03928) ? $bSrgb / 12.92 : pow((($bSrgb + 0.055) / 1.055), 2.4); - return (0.2126 * $r + 0.7152 * $g + 0.0722 * $b); + return 0.2126 * $r + 0.7152 * $g + 0.0722 * $b; } /** - * '#abcdef' => ['ab', 'cd', 'ef'] + * '#abcdef' => ['ab', 'cd', 'ef']. */ protected static function rgbHexChannels(HexColor $hexColor): array { diff --git a/src/TailwindColor.php b/src/TailwindColor.php index b2fbdf9..4cc59b9 100644 --- a/src/TailwindColor.php +++ b/src/TailwindColor.php @@ -16,7 +16,7 @@ public function __construct() } /** - * Returns all the default Tailwind colors + * Returns all the default Tailwind colors. */ public static function colors(): array { @@ -29,7 +29,7 @@ public function getColors(): array } /** - * Returns a random Tailwind color + * Returns a random Tailwind color. */ public static function random(): HexColor { @@ -69,7 +69,7 @@ public static function merge(array $customPalette): self } /** - * Returns a random pair of accessible (min. contrast 3:1) Tailwind colors + * Returns a random pair of accessible (min. contrast 3:1) Tailwind colors. */ public static function randomPair(): HexColorPair { @@ -122,6 +122,6 @@ protected function flatten(array $twColorsArr): Collection protected function parseDefaultTailwindColors() { - return json_decode(file_get_contents(__DIR__ . '/../stubs/twcolors.json'), true); + return json_decode(file_get_contents(__DIR__.'/../stubs/twcolors.json'), true); } } diff --git a/tests/HexColorPairTest.php b/tests/HexColorPairTest.php index 2e196a1..de1de29 100644 --- a/tests/HexColorPairTest.php +++ b/tests/HexColorPairTest.php @@ -70,23 +70,23 @@ public function provideContrastData() { yield 'maximum contrast' => [ 21, - ['000', 'fff',], + ['000', 'fff'], ]; yield 'no contrast - black on black' => [ 1, - ['000', '000',], + ['000', '000'], ]; yield 'no contrast - white on white' => [ 1, - ['fff', 'fff',], + ['fff', 'fff'], ]; yield 'high contrast' => [ 18.4, - ['300', 'fff',], + ['300', 'fff'], ]; yield 'low contrast' => [ 1.1, - ['300', '000',], + ['300', '000'], ]; } } diff --git a/tests/HexColorTest.php b/tests/HexColorTest.php index ca97d5a..d8102f8 100644 --- a/tests/HexColorTest.php +++ b/tests/HexColorTest.php @@ -3,7 +3,6 @@ namespace Breadthe\PhpContrast\Tests; use Breadthe\PhpContrast\HexColor; -use Breadthe\PhpContrast\HexColorPair; use PHPUnit\Framework\TestCase; class HexColorTest extends TestCase diff --git a/tests/TailwindTest.php b/tests/TailwindTest.php index 7791d6b..49fb480 100644 --- a/tests/TailwindTest.php +++ b/tests/TailwindTest.php @@ -6,7 +6,6 @@ use Breadthe\PhpContrast\HexColorPair; use Breadthe\PhpContrast\TailwindColor; use PHPUnit\Framework\TestCase; -use Tightenco\Collect\Support\Collection; class TailwindTest extends TestCase { @@ -47,7 +46,7 @@ public function it_returns_random_color_pairs_of_minimum_3_to_1_ratio() /** @test */ public function it_can_merge_default_and_custom_colors() { - $customPalette = json_decode(file_get_contents(__DIR__ . '/../stubs/custom-palette.json'), true); + $customPalette = json_decode(file_get_contents(__DIR__.'/../stubs/custom-palette.json'), true); $colors = TailwindColor::merge($customPalette)->getColors(); $customPalette = collect($customPalette)