From 87573ea09916ed3b5d5dd7c212fc09de91cf7459 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 10 Nov 2024 11:06:54 +0100 Subject: [PATCH] Add zodiac sing compatibility calculation --- src/AbstractZodiac.php | 10 ++ src/Compatibility.php | 208 +++++++++++++++++++++++++++++ src/Interfaces/ZodiacInterface.php | 11 ++ tests/CompatibilityTest.php | 60 +++++++++ 4 files changed, 289 insertions(+) create mode 100644 src/Compatibility.php create mode 100644 tests/CompatibilityTest.php diff --git a/src/AbstractZodiac.php b/src/AbstractZodiac.php index ca9d15d..7264ea0 100644 --- a/src/AbstractZodiac.php +++ b/src/AbstractZodiac.php @@ -90,6 +90,16 @@ public function html(): string return $this->html; } + /** + * {@inheritdoc} + * + * @see ZodiacInterface::compatibility() + */ + public function compatibility(ZodiacInterface $zodiac): int + { + return call_user_func(new Compatibility(), $this, $zodiac); + } + /** * {@inheritdoc} * diff --git a/src/Compatibility.php b/src/Compatibility.php new file mode 100644 index 0000000..c3d6626 --- /dev/null +++ b/src/Compatibility.php @@ -0,0 +1,208 @@ +> $factors + */ + protected array $factors = [ + Aquarius::class => [ + Aquarius::class => 9, + Aries::class => 9, + Cancer::class => 4, + Capricorn::class => 4, + Gemini::class => 10, + Leo::class => 8, + Libra::class => 7, + Pisces::class => 6, + Sagittarius::class => 8, + Scorpio::class => 4, + Taurus::class => 5, + Virgo::class => 7, + ], + Aries::class => [ + Aquarius::class => 9, + Aries::class => 10, + Cancer::class => 7, + Capricorn::class => 5, + Gemini::class => 9, + Leo::class => 9, + Libra::class => 9, + Pisces::class => 7, + Sagittarius::class => 10, + Scorpio::class => 6, + Taurus::class => 6, + Virgo::class => 7, + ], + Cancer::class => [ + Aquarius::class => 4, + Aries::class => 7, + Cancer::class => 10, + Capricorn::class => 8, + Gemini::class => 6, + Leo::class => 8, + Libra::class => 7, + Pisces::class => 10, + Sagittarius::class => 5, + Scorpio::class => 8, + Taurus::class => 9, + Virgo::class => 8, + ], + Capricorn::class => [ + Aquarius::class => 4, + Aries::class => 6, + Cancer::class => 9, + Capricorn::class => 9, + Gemini::class => 4, + Leo::class => 5, + Libra::class => 5, + Pisces::class => 8, + Sagittarius::class => 5, + Scorpio::class => 9, + Taurus::class => 9, + Virgo::class => 10, + ], + Gemini::class => [ + Aquarius::class => 10, + Aries::class => 8, + Cancer::class => 5, + Capricorn::class => 5, + Gemini::class => 6, + Leo::class => 8, + Libra::class => 8, + Pisces::class => 9, + Sagittarius::class => 7, + Scorpio::class => 4, + Taurus::class => 5, + Virgo::class => 7, + ], + Leo::class => [ + Aquarius::class => 9, + Aries::class => 9, + Cancer::class => 5, + Capricorn::class => 4, + Gemini::class => 8, + Leo::class => 7, + Libra::class => 8, + Pisces::class => 7, + Sagittarius::class => 5, + Scorpio::class => 7, + Taurus::class => 7, + Virgo::class => 8, + ], + Libra::class => [ + Aquarius::class => 7, + Aries::class => 9, + Cancer::class => 5, + Capricorn::class => 7, + Gemini::class => 9, + Leo::class => 8, + Libra::class => 9, + Pisces::class => 5, + Sagittarius::class => 8, + Scorpio::class => 5, + Taurus::class => 5, + Virgo::class => 7, + ], + Pisces::class => [ + Aquarius::class => 9, + Aries::class => 5, + Cancer::class => 10, + Capricorn::class => 9, + Gemini::class => 9, + Leo::class => 5, + Libra::class => 5, + Pisces::class => 5, + Sagittarius::class => 5, + Scorpio::class => 8, + Taurus::class => 6, + Virgo::class => 8, + ], + Sagittarius::class => [ + Aquarius::class => 8, + Aries::class => 8, + Cancer::class => 5, + Capricorn::class => 4, + Gemini::class => 8, + Leo::class => 7, + Libra::class => 8, + Pisces::class => 6, + Sagittarius::class => 8, + Scorpio::class => 4, + Taurus::class => 5, + Virgo::class => 7, + ], + Scorpio::class => [ + Aquarius::class => 6, + Aries::class => 6, + Cancer::class => 9, + Capricorn::class => 9, + Gemini::class => 4, + Leo::class => 7, + Libra::class => 5, + Pisces::class => 8, + Sagittarius::class => 4, + Scorpio::class => 10, + Taurus::class => 9, + Virgo::class => 10, + ], + Taurus::class => [ + Aquarius::class => 6, + Aries::class => 6, + Cancer::class => 9, + Capricorn::class => 10, + Gemini::class => 5, + Leo::class => 6, + Libra::class => 6, + Pisces::class => 6, + Sagittarius::class => 5, + Scorpio::class => 9, + Taurus::class => 9, + Virgo::class => 9, + ], + Virgo::class => [ + Aquarius::class => 7, + Aries::class => 7, + Cancer::class => 8, + Capricorn::class => 9, + Gemini::class => 8, + Leo::class => 5, + Libra::class => 6, + Pisces::class => 9, + Sagittarius::class => 7, + Scorpio::class => 9, + Taurus::class => 9, + Virgo::class => 9, + ], + ]; + + /** + * Calculate zodiac sign compatibility between two signs + * + * @param ZodiacInterface $a + * @param ZodiacInterface $b + * @return int + */ + public function __invoke(ZodiacInterface $a, ZodiacInterface $b): int + { + return $this->factors[$a::class][$b::class]; + } +} diff --git a/src/Interfaces/ZodiacInterface.php b/src/Interfaces/ZodiacInterface.php index 276077a..d658fd6 100644 --- a/src/Interfaces/ZodiacInterface.php +++ b/src/Interfaces/ZodiacInterface.php @@ -46,6 +46,17 @@ public function html(): string; */ public function localized(?string $locale = null): ?string; + /** + * Calculate zodiac sign compatibility with any other sign in love & life + * where 0 means no match and a maximum of 10 is a total match. + * + * Completely made up :) Don't plan your life around it. + * + * @param ZodiacInterface $zodiac + * @return int + */ + public function compatibility(self $zodiac): int; + /** * Cast current object to string * diff --git a/tests/CompatibilityTest.php b/tests/CompatibilityTest.php new file mode 100644 index 0000000..06a3e31 --- /dev/null +++ b/tests/CompatibilityTest.php @@ -0,0 +1,60 @@ +assertIsInt($result); + $this->assertTrue(in_array($result, range(0, 10))); + } + + public static function factorDataProvider(): array + { + $data = []; + + $zodiacs = [ + Aquarius::class, + Aries::class, + Cancer::class, + Capricorn::class, + Gemini::class, + Leo::class, + Libra::class, + Pisces::class, + Sagittarius::class, + Scorpio::class, + Taurus::class, + Virgo::class, + ]; + + foreach ($zodiacs as $a) { + foreach ($zodiacs as $b) { + $data[] = [$a, $b]; + } + } + + return $data; + } +}