Skip to content

Commit a6756cc

Browse files
committed
Merge branch 'php8-migration' into organisation
2 parents b4dbb50 + 4af9c1c commit a6756cc

File tree

16 files changed

+430
-118
lines changed

16 files changed

+430
-118
lines changed

src/Api/Campaigns.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class Campaigns
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/Skill.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class Skill
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/SkillSet.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131

3232
class SkillSet
3333
{
34-
/**
35-
* @var Settings
36-
*/
37-
protected $settings;
34+
protected Settings $settings;
3835

39-
/**
40-
* @var Client
41-
*/
42-
protected $client;
36+
protected Client $client;
4337

4438
public function __construct(
4539
Settings $settings,

src/Api/SkillSetProgress.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SkillDisplay\PHPToolKit\Api;
6+
7+
/*
8+
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 2
13+
* of the License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301, USA.
24+
*/
25+
26+
use GuzzleHttp\Client;
27+
use GuzzleHttp\Exception\ClientException;
28+
use GuzzleHttp\Psr7\Request;
29+
use SkillDisplay\PHPToolKit\Configuration\Settings;
30+
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity;
31+
32+
class SkillSetProgress
33+
{
34+
protected Settings $settings;
35+
protected Client $client;
36+
37+
public function __construct(
38+
Settings $settings,
39+
Client $client
40+
) {
41+
$this->settings = $settings;
42+
$this->client = $client;
43+
}
44+
45+
public function getById(int $id): Entity
46+
{
47+
if ($id <= 0) {
48+
throw new \Exception('ID of SkillSet has to be a positive integer.', 1688639724754);
49+
}
50+
51+
$url = $this->settings->getAPIUrl() . '/api/v1/skillset/' . $id . '/progress';
52+
try {
53+
$result = $this->client->send(new Request(
54+
'GET',
55+
$url,
56+
[
57+
'Content-Type' => 'application/json',
58+
'x-api-key' => $this->settings->getApiKey()
59+
]
60+
));
61+
} catch (ClientException $e) {
62+
if ($e->getCode() === 404) {
63+
throw new \InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718);
64+
}
65+
throw $e;
66+
}
67+
68+
if ($result->getStatusCode() !== 200) {
69+
throw new \Exception('Did not get proper response for SkillSetProgress.', 1688639840720);
70+
}
71+
72+
$body = (string) $result->getBody();
73+
74+
if (strpos($body, 'Oops, an error occurred') !== false) {
75+
throw new \Exception('Did not get proper response for SkillSetProgress. SkillSet with id "' . $id . '" does probably not exist.', 1688639873065);
76+
}
77+
78+
return Entity::createFromJson($body, $this->settings);
79+
}
80+
}

src/Configuration/Settings.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,15 @@
66

77
class Settings
88
{
9-
/**
10-
* @var string
11-
*/
12-
private $user_secret = '';
9+
private string $user_secret = '';
1310

14-
/**
15-
* @var string
16-
*/
17-
private $apiKey = '';
11+
private string $apiKey = '';
1812

19-
/**
20-
* @var int
21-
*/
22-
private $verifierID = 0;
13+
private int $verifierID = 0;
2314

24-
/**
25-
* @var string
26-
*/
27-
private $APIUrl = '';
15+
private string $APIUrl = '';
2816

29-
/**
30-
* @var string
31-
*/
32-
private $mySkillDisplayUrl = '';
17+
private string $mySkillDisplayUrl = '';
3318

3419
public function getVerifierID(): int
3520
{

src/Entity/Brand.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@
2727

2828
class Brand
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

4034
private function __construct(array $data, Settings $settings)
4135
{

src/Entity/Campaign.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@
2727

2828
class Campaign
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

4034
public function __construct(array $data, Settings $settings)
4135
{

src/Entity/Skill.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,11 @@
2727

2828
class Skill
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

40-
/**
41-
* @var array
42-
*/
43-
private $brands = [];
34+
private array $brands = [];
4435

4536
private function __construct(array $data, Settings $settings)
4637
{

src/Entity/SkillSet.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,13 @@
2727

2828
class SkillSet
2929
{
30-
/**
31-
* @var array
32-
*/
33-
private $data;
30+
private array $data;
3431

35-
/**
36-
* @var Settings
37-
*/
38-
private $settings;
32+
private Settings $settings;
3933

40-
/**
41-
* @var array
42-
*/
43-
private $skills = [];
34+
private array $skills = [];
4435

45-
/**
46-
* @var Brand|null
47-
*/
48-
private $brand = null;
36+
private ?Brand $brand = null;
4937

5038
private function __construct(array $data, Settings $settings)
5139
{
@@ -68,6 +56,11 @@ public function getDescription(): string
6856
return $this->data['description'] ?? '';
6957
}
7058

59+
public function getProgressPercentage(): SkillSetProgress
60+
{
61+
return SkillSetProgress::createFromJson(json_encode($this->data['progressPercentage']), $this->settings);
62+
}
63+
7164
public function getBrand(): Brand
7265
{
7366
if ($this->brand instanceof Brand) {

src/Entity/SkillSetProgress.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SkillDisplay\PHPToolKit\Entity;
6+
7+
/*
8+
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 2
13+
* of the License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301, USA.
24+
*/
25+
26+
use SkillDisplay\PHPToolKit\Configuration\Settings;
27+
28+
class SkillSetProgress
29+
{
30+
private array $data;
31+
32+
private Settings $settings;
33+
34+
private function __construct(array $data, Settings $settings)
35+
{
36+
$this->data = $data;
37+
$this->settings = $settings;
38+
}
39+
40+
public function getTier1(): float
41+
{
42+
return $this->data['tier1'] ?? 0;
43+
}
44+
45+
public function getTier2(): float
46+
{
47+
return $this->data['tier2'] ?? 0;
48+
}
49+
50+
public function getTier3(): float
51+
{
52+
return $this->data['tier3'] ?? 0;
53+
}
54+
55+
public function getTier4(): float
56+
{
57+
return $this->data['tier4'] ?? 0;
58+
}
59+
60+
public static function createFromJson(string $json, Settings $settings): SkillSetProgress
61+
{
62+
return new SkillSetProgress(json_decode($json, true), $settings);
63+
}
64+
}

src/Example/FullSettingsRequired/AutoGrantBusinessVerification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
// In order to grant an Educational Verification you just need to exchange the constant to VERIFICATION_EDUCATIONAL
1515
// (your Verifier Account needs the according permissions)
1616
$myVerificationTool = new Issuer($mySettings);
17-
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_BUSINESS, 567));
17+
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(175, '--skilldisplay-user-email--', VERIFICATION_BUSINESS, false, 567, true));

src/Verification/Issuer.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@
1010

1111
class Issuer
1212
{
13-
/**
14-
* @var Settings
15-
*/
16-
private $settings;
13+
private Settings $settings;
1714

18-
/**
19-
* @var string
20-
*/
21-
private $apislug = '/api/v1/verification/create';
15+
private string $apislug = '/api/v1/verification/create';
2216

2317
/**
2418
* @param int $ID ID of the Skill or SkillSet
2519
* @param string $useremail E-Mail of the User who should receive the verification
2620
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
2721
* @param bool $isSkillSet
2822
* @param int $campaignId
29-
*
23+
* @param bool $autoConfirm
3024
* @return array
3125
*/
3226
private function generateSignedRequestData(

src/Verification/Link.php

Lines changed: 5 additions & 20 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)