From bf1e66609149902a7fa668c4229455cd3a2cbbbb Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 10 Sep 2020 09:47:22 +0200 Subject: [PATCH 1/8] Make skill ID optional when creating link instance Link looks more like a service. When dealing with dependency injection it would make sense to create a single instance with settings. Following calls can then ask to create a button or link with all necessary information. --- src/Verification/Link.php | 18 ++++++++++++------ tests/Unit/Verification/LinkTest.php | 10 ++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Verification/Link.php b/src/Verification/Link.php index 82baec7..4e946b5 100644 --- a/src/Verification/Link.php +++ b/src/Verification/Link.php @@ -12,7 +12,7 @@ use SkillDisplay\PHPToolKit\Configuration\Settings; */ class Link { - private int $skillID; + private ?int $skillID; private Settings $settings; /* SVG Definitions */ @@ -48,7 +48,7 @@ class Link '; - public function __construct(Settings $settings, int $skillID) + public function __construct(Settings $settings, ?int $skillID = null) { $this->settings = $settings; $this->skillID = $skillID; @@ -58,9 +58,15 @@ class Link * @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION * @return string URL to a Verification that a user can click, he/she will see the Verification interface and can choose a verifier */ - public function getVerificationLink(string $vtype): string + public function getVerificationLink(string $vtype, ?int $skillID = null) : string { - $link = $this->settings->getMySkillDisplayUrl() . '/skillup/skill/' . $this->skillID . '/0/'; + $skillID = $skillID ?? $this->skillID; + + if ($skillID === null) { + throw new \InvalidArgumentException('No skill ID provided.', 1599723825); + } + + $link = $this->settings->getMySkillDisplayUrl() . '/skillup/skill/' . $skillID . '/0/'; switch ($vtype) { case VERIFICATION_EDUCATIONAL: $link .= '2'; @@ -83,7 +89,7 @@ class Link * @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION * @return string SVG Button to a Verification that a user can click, he/she will see the Verification interface and can choose a verifier */ - public function getVerificationButton(string $vtype): string + public function getVerificationButton(string $vtype, ?int $skillID = null) : string { switch ($vtype) { case VERIFICATION_EDUCATIONAL: @@ -100,7 +106,7 @@ class Link break; } return <<