Skip to content

Commit cf6ae1b

Browse files
committed
add typeHinting for CultureFeed_Exception
1 parent edb473c commit cf6ae1b

14 files changed

+140
-137
lines changed
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
<?php
22

3-
class CultureFeed_Exception extends Exception {
4-
public $error_code;
3+
class CultureFeed_Exception extends Exception
4+
{
5+
private string $error_code;
56

6-
/**
7-
* @var string
8-
*/
9-
protected $userFriendlyMessage;
7+
private string $userFriendlyMessage;
108

11-
function __construct($message, $error_code, $code = 0) {
12-
parent::__construct($message, $code);
13-
$this->error_code = $error_code;
14-
}
9+
function __construct($message, $error_code, $code = 0)
10+
{
11+
parent::__construct($message, $code);
12+
$this->error_code = $error_code;
13+
}
1514

16-
/**
17-
* @return string|null
18-
*/
19-
public function getUserFriendlyMessage() {
20-
return $this->userFriendlyMessage;
21-
}
15+
public function getUserFriendlyMessage(): ?string
16+
{
17+
return $this->userFriendlyMessage;
18+
}
2219

23-
public function setUserFriendlyMessage(string $message): void {
24-
$this->userFriendlyMessage = $message;
25-
}
20+
public function setUserFriendlyMessage(string $message): void
21+
{
22+
$this->userFriendlyMessage = $message;
23+
}
24+
25+
public function getErrorCode(): string
26+
{
27+
return $this->error_code;
28+
}
2629
}

CultureFeed/bin/getactivationlink.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* - date of birth, formatted yyyy-mm-dd
1414
*/
1515

16-
date_default_timezone_set('Europe/Brussels');
17-
18-
// require the third-party oauth library which is not properly structured to be autoloaded
19-
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
20-
21-
function culturefeed_autoload($class) {
22-
$file = str_replace('_', '/', $class) . '.php';
23-
require_once $file;
24-
}
25-
16+
date_default_timezone_set('Europe/Brussels');
17+
18+
// require the third-party oauth library which is not properly structured to be autoloaded
19+
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
20+
21+
function culturefeed_autoload($class) {
22+
$file = str_replace('_', '/', $class) . '.php';
23+
require_once $file;
24+
}
25+
2626
spl_autoload_register('culturefeed_autoload');
2727

2828
try {
@@ -48,7 +48,7 @@ function culturefeed_autoload($class) {
4848
print "An exception of type {$type} was thrown." . PHP_EOL;
4949
print "Code: {$e->getCode()}" . PHP_EOL;
5050
if ($e instanceof CultureFeed_Exception) {
51-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
51+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
5252
}
5353
print "Message: {$e->getMessage()}" . PHP_EOL;
5454
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getcounters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function culturefeed_autoload($class) {
4444
print "An exception of type {$type} was thrown." . PHP_EOL;
4545
print "Code: {$e->getCode()}" . PHP_EOL;
4646
if ($e instanceof CultureFeed_Exception) {
47-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
47+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
4848
}
4949
print "Message: {$e->getMessage()}" . PHP_EOL;
5050
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getdistributionkeysfororganizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function culturefeed_autoload($class) {
6060
print "An exception of type {$type} was thrown." . PHP_EOL;
6161
print "Code: {$e->getCode()}" . PHP_EOL;
6262
if ($e instanceof CultureFeed_Exception) {
63-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
63+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
6464
}
6565
print "Message: {$e->getMessage()}" . PHP_EOL;
6666
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getpassholder.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ function culturefeed_autoload($class) {
3838
$oc->setEndpoint($endpoint);
3939
$c = new CultureFeed($oc);
4040

41-
$token = $c->getRequestToken($callback_url);
42-
43-
print "Requested oauth_token: {$token['oauth_token']}" . PHP_EOL;
44-
45-
// Save the token and secret in the session.
46-
//$_SESSION['oauth_token'] = $token['oauth_token'];
47-
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
48-
49-
// Fetch the authorisation url...
50-
$auth_url = $c->getUrlAuthorize($token, $callback_url, CultureFeed::AUTHORIZE_TYPE_REGULAR);
51-
52-
print "Now open the following URL in your browser: {$auth_url}" . PHP_EOL;
53-
print "After logging in with your UiTID you should inspect your RequestBin and find there the last request with an oauth_token and oauth_verifier." . PHP_EOL;
54-
print "Make sure the you have identified the right request, containing the oauth token: {$token['oauth_token']}" . PHP_EOL;
55-
print "Give me the oauth_verifier value now: ";
56-
$oauth_verifier = fgets(STDIN);
57-
$oauth_verifier = trim($oauth_verifier);
58-
59-
$user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
60-
$user_oauth_client->setEndpoint($endpoint);
61-
$user_c = new CultureFeed($user_oauth_client);
62-
$new_token = $user_c->getAccessToken($oauth_verifier);
63-
64-
$new_user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $new_token['oauth_token'], $new_token['oauth_token_secret']);
65-
$new_user_oauth_client->setEndpoint($endpoint);
41+
$token = $c->getRequestToken($callback_url);
42+
43+
print "Requested oauth_token: {$token['oauth_token']}" . PHP_EOL;
44+
45+
// Save the token and secret in the session.
46+
//$_SESSION['oauth_token'] = $token['oauth_token'];
47+
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
48+
49+
// Fetch the authorisation url...
50+
$auth_url = $c->getUrlAuthorize($token, $callback_url, CultureFeed::AUTHORIZE_TYPE_REGULAR);
51+
52+
print "Now open the following URL in your browser: {$auth_url}" . PHP_EOL;
53+
print "After logging in with your UiTID you should inspect your RequestBin and find there the last request with an oauth_token and oauth_verifier." . PHP_EOL;
54+
print "Make sure the you have identified the right request, containing the oauth token: {$token['oauth_token']}" . PHP_EOL;
55+
print "Give me the oauth_verifier value now: ";
56+
$oauth_verifier = fgets(STDIN);
57+
$oauth_verifier = trim($oauth_verifier);
58+
59+
$user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
60+
$user_oauth_client->setEndpoint($endpoint);
61+
$user_c = new CultureFeed($user_oauth_client);
62+
$new_token = $user_c->getAccessToken($oauth_verifier);
63+
64+
$new_user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $new_token['oauth_token'], $new_token['oauth_token_secret']);
65+
$new_user_oauth_client->setEndpoint($endpoint);
6666
$c = new CultureFeed($new_user_oauth_client);
6767

6868
$passholder = $c->uitpas()->getPassholderByUitpasNumber($uitpas_number, $counter_consumer_key);
@@ -75,7 +75,7 @@ function culturefeed_autoload($class) {
7575
print "An exception of type {$type} was thrown." . PHP_EOL;
7676
print "Code: {$e->getCode()}" . PHP_EOL;
7777
if ($e instanceof CultureFeed_Exception) {
78-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
78+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
7979
}
8080
print "Message: {$e->getMessage()}" . PHP_EOL;
8181
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getpointspromotion.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
* - points promotion ID
1313
*/
1414

15-
date_default_timezone_set('Europe/Brussels');
16-
17-
// require the third-party oauth library which is not properly structured to be autoloaded
18-
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19-
20-
function culturefeed_autoload($class) {
21-
$file = str_replace('_', '/', $class) . '.php';
22-
require_once $file;
23-
}
24-
15+
date_default_timezone_set('Europe/Brussels');
16+
17+
// require the third-party oauth library which is not properly structured to be autoloaded
18+
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19+
20+
function culturefeed_autoload($class) {
21+
$file = str_replace('_', '/', $class) . '.php';
22+
require_once $file;
23+
}
24+
2525
spl_autoload_register('culturefeed_autoload');
2626

2727
try {
@@ -52,7 +52,7 @@ function culturefeed_autoload($class) {
5252
print "An exception of type {$type} was thrown." . PHP_EOL;
5353
print "Code: {$e->getCode()}" . PHP_EOL;
5454
if ($e instanceof CultureFeed_Exception) {
55-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
55+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
5656
}
5757
print "Message: {$e->getMessage()}" . PHP_EOL;
5858
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getpointspromotions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function culturefeed_autoload($class) {
4444
print "An exception of type {$type} was thrown." . PHP_EOL;
4545
print "Code: {$e->getCode()}" . PHP_EOL;
4646
if ($e instanceof CultureFeed_Exception) {
47-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
47+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
4848
}
4949
print "Message: {$e->getMessage()}" . PHP_EOL;
5050
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getuser.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
* - user uuid
1313
*/
1414

15-
date_default_timezone_set('Europe/Brussels');
16-
17-
// require the third-party oauth library which is not properly structured to be autoloaded
18-
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19-
20-
function culturefeed_autoload($class) {
21-
$file = str_replace('_', '/', $class) . '.php';
22-
require_once $file;
23-
}
24-
15+
date_default_timezone_set('Europe/Brussels');
16+
17+
// require the third-party oauth library which is not properly structured to be autoloaded
18+
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19+
20+
function culturefeed_autoload($class) {
21+
$file = str_replace('_', '/', $class) . '.php';
22+
require_once $file;
23+
}
24+
2525
spl_autoload_register('culturefeed_autoload');
2626

2727
try {
@@ -44,7 +44,7 @@ function culturefeed_autoload($class) {
4444
print "An exception of type {$type} was thrown." . PHP_EOL;
4545
print "Code: {$e->getCode()}" . PHP_EOL;
4646
if ($e instanceof CultureFeed_Exception) {
47-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
47+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
4848
}
4949
print "Message: {$e->getMessage()}" . PHP_EOL;
5050
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getuserpreferences.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ function culturefeed_autoload($class) {
3232

3333
$oc = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret);
3434
$oc->setEndpoint($endpoint);
35-
$c = new CultureFeed($oc);
36-
35+
$c = new CultureFeed($oc);
36+
3737
$token = $c->getRequestToken($callback_url);
3838

39-
print "Requested oauth_token: {$token['oauth_token']}" . PHP_EOL;
40-
41-
// Save the token and secret in the session.
42-
//$_SESSION['oauth_token'] = $token['oauth_token'];
43-
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
44-
45-
// Fetch the authorisation url...
39+
print "Requested oauth_token: {$token['oauth_token']}" . PHP_EOL;
40+
41+
// Save the token and secret in the session.
42+
//$_SESSION['oauth_token'] = $token['oauth_token'];
43+
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
44+
45+
// Fetch the authorisation url...
4646
$auth_url = $c->getUrlAuthorize($token, $callback_url, CultureFeed::AUTHORIZE_TYPE_REGULAR);
4747

4848
print "Now open the following URL in your browser: {$auth_url}" . PHP_EOL;
@@ -55,8 +55,8 @@ function culturefeed_autoload($class) {
5555
$user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
5656
$user_oauth_client->setEndpoint($endpoint);
5757
$user_c = new CultureFeed($user_oauth_client);
58-
$new_token = $user_c->getAccessToken($oauth_verifier);
59-
58+
$new_token = $user_c->getAccessToken($oauth_verifier);
59+
6060
$new_user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $new_token['oauth_token'], $new_token['oauth_token_secret']);
6161
$new_user_oauth_client->setEndpoint($endpoint);
6262
$new_user_c = new CultureFeed($new_user_oauth_client);
@@ -71,15 +71,15 @@ function culturefeed_autoload($class) {
7171

7272
$preferences = $new_user_c->setUserPreferences($account->id, $preferences);
7373

74-
if (count($preferences->activityPrivacyPreferences) == 0) {
75-
print "No user preferences found" . PHP_EOL;
76-
}
77-
else {
78-
print "User preferences:" . PHP_EOL;
79-
foreach ($preferences->activityPrivacyPreferences as $preference) {
80-
$private = $preference->private ? "private" : "public";
81-
print "{$preference->activityType}: {$private}" . PHP_EOL;
82-
}
74+
if (count($preferences->activityPrivacyPreferences) == 0) {
75+
print "No user preferences found" . PHP_EOL;
76+
}
77+
else {
78+
print "User preferences:" . PHP_EOL;
79+
foreach ($preferences->activityPrivacyPreferences as $preference) {
80+
$private = $preference->private ? "private" : "public";
81+
print "{$preference->activityType}: {$private}" . PHP_EOL;
82+
}
8383
}
8484

8585
print "Getting user preferences" . PHP_EOL;
@@ -103,7 +103,7 @@ function culturefeed_autoload($class) {
103103
print "An exception of type {$type} was thrown." . PHP_EOL;
104104
print "Code: {$e->getCode()}" . PHP_EOL;
105105
if ($e instanceof CultureFeed_Exception) {
106-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
106+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
107107
}
108108
print "Message: {$e->getMessage()}" . PHP_EOL;
109109
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

CultureFeed/bin/getwelcomeadvantage.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
* - welcome advantage ID
1313
*/
1414

15-
date_default_timezone_set('Europe/Brussels');
16-
17-
// require the third-party oauth library which is not properly structured to be autoloaded
18-
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19-
20-
function culturefeed_autoload($class) {
21-
$file = str_replace('_', '/', $class) . '.php';
22-
require_once $file;
23-
}
24-
15+
date_default_timezone_set('Europe/Brussels');
16+
17+
// require the third-party oauth library which is not properly structured to be autoloaded
18+
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
19+
20+
function culturefeed_autoload($class) {
21+
$file = str_replace('_', '/', $class) . '.php';
22+
require_once $file;
23+
}
24+
2525
spl_autoload_register('culturefeed_autoload');
2626

2727
try {
@@ -44,7 +44,7 @@ function culturefeed_autoload($class) {
4444
print "An exception of type {$type} was thrown." . PHP_EOL;
4545
print "Code: {$e->getCode()}" . PHP_EOL;
4646
if ($e instanceof CultureFeed_Exception) {
47-
print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
47+
print "CultureFeed error code: {$e->getErrorCode()}" . PHP_EOL;
4848
}
4949
print "Message: {$e->getMessage()}" . PHP_EOL;
5050
print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;

0 commit comments

Comments
 (0)