Skip to content

Commit ad69e2a

Browse files
committed
Merge branch 'release/2.8.0'
2 parents 1246acb + 4281905 commit ad69e2a

11 files changed

+67
-114
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.0
1+
2.8.0

composer.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=7.2",
25-
"ext-json": "*",
24+
"php": ">=8.1",
2625
"cviebrock/discourse-php": "^0.9.3",
27-
"guzzlehttp/guzzle": "^6.4|^7.0.1|^7.2",
28-
"illuminate/auth": "~5.5|~6|~7|~8|~9",
29-
"illuminate/routing": "~5.5|~6|~7|~8|~9",
30-
"illuminate/support": "~5.5|~6|~7|~8|~9"
26+
"guzzlehttp/guzzle": "^7.4.5",
27+
"illuminate/auth": "~8|~9|~10",
28+
"illuminate/routing": "~8|~9|~10",
29+
"illuminate/support": "~8|~9|~10"
3130
},
3231
"require-dev": {
33-
"mockery/mockery": "^1.3.1",
34-
"phpunit/phpunit": "^8.4|^9.0",
35-
"psy/psysh": "^0.10",
36-
"symfony/thanks": "^1.1",
37-
"symfony/var-dumper": "~3.0|^4.2|^6"
32+
"laravel/sail": "^1.21",
33+
"mockery/mockery": "^1.5.1",
34+
"phpunit/phpunit": "^9.6.5",
35+
"psy/psysh": "^0.11.1",
36+
"symfony/var-dumper": "^6.2"
3837
},
3938
"autoload": {
4039
"psr-4": {

nitpick.json

-5
This file was deleted.

pint.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"no_superfluous_phpdoc_tags": true
5+
}
6+
}

src/Controllers/SsoController.php

+7-35
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,26 @@
1616
* Controller to process the Discourse SSO request. There is a good bit of logic in here that almost feels like too
1717
* much for a controller, but given that this is the only thing that this controller is doing, I am not going to break
1818
* it out into a service class.
19-
*
20-
* @package Spinen\Discourse\Controllers
2119
*/
2220
class SsoController extends Controller
2321
{
2422
/**
2523
* Package configuration
26-
*
27-
* @var Collection
2824
*/
29-
protected $config;
25+
protected Collection $config;
3026

3127
/**
3228
* SSOHelper Instance
33-
*
34-
* @var SSOHelper
3529
*/
36-
protected $sso;
30+
protected SSOHelper $sso;
3731

3832
/**
3933
* Authenticated user
40-
*
41-
* @var User
4234
*/
43-
protected $user;
35+
protected User $user;
4436

4537
/**
4638
* SsoController constructor.
47-
*
48-
* @param Config $config
49-
* @param SSOHelper $sso
5039
*/
5140
public function __construct(Config $config, SSOHelper $sso)
5241
{
@@ -57,10 +46,8 @@ public function __construct(Config $config, SSOHelper $sso)
5746

5847
/**
5948
* Build out the extra parameters to send to Discourse
60-
*
61-
* @return array
6249
*/
63-
protected function buildExtraParameters()
50+
protected function buildExtraParameters(): array
6451
{
6552
return $this->config->get('user')
6653
->except(['access', 'email', 'external_id'])
@@ -75,12 +62,8 @@ protected function buildExtraParameters()
7562
*
7663
* The Discourse SSO API does not accept 0 or 1 for false or true. You must send
7764
* "false" or "true", so convert any boolean property to the string version.
78-
*
79-
* @param $property
80-
*
81-
* @return string
8265
*/
83-
public function castBooleansToString($property)
66+
public function castBooleansToString(string|bool $property): string
8467
{
8568
if (! is_bool($property)) {
8669
return $property;
@@ -93,10 +76,8 @@ public function castBooleansToString($property)
9376
* Cache the configs on the object as a collection
9477
*
9578
* The 'user' property will be an array, so go ahead and convert it to a collection
96-
*
97-
* @param Config $config
9879
*/
99-
protected function loadConfigs(Config $config)
80+
protected function loadConfigs(Config $config): void
10081
{
10182
$this->config = collect($config->get('services.discourse'));
10283
$this->config->put('user', collect($this->config->get('user')));
@@ -105,9 +86,6 @@ protected function loadConfigs(Config $config)
10586
/**
10687
* Process the SSO login request from Discourse
10788
*
108-
* @param Request $request
109-
*
110-
* @return mixed
11189
* @throws 403
11290
*/
11391
public function login(Request $request)
@@ -138,11 +116,8 @@ public function login(Request $request)
138116

139117
/**
140118
* Check to see if property is null
141-
*
142-
* @param string $property
143-
* @return bool
144119
*/
145-
public function nullProperty($property)
120+
public function nullProperty(?string $property): bool
146121
{
147122
return is_null($property);
148123
}
@@ -151,9 +126,6 @@ public function nullProperty($property)
151126
* Get the property from the user
152127
*
153128
* If a string is passed in, then get it from the user object, otherwise, return what was given
154-
*
155-
* @param mixed $property
156-
* @return mixed
157129
*/
158130
public function parseUserValue($property)
159131
{

src/Listeners/LogoutDiscourseUser.php

+10-18
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,33 @@
66
use GuzzleHttp\Exception\BadResponseException;
77
use Illuminate\Contracts\Config\Repository;
88
use Illuminate\Contracts\Queue\ShouldQueue;
9-
use Illuminate\Support\Facades\Log;
109
use Symfony\Component\HttpKernel\Log\Logger;
1110

1211
/**
1312
* Class LogoutDiscourseUser
1413
*
1514
* Send a Logout request to Discourse for the corresponding Laravel User.
16-
*
17-
* @package Spinen\Discourse\Listeners
1815
*/
1916
class LogoutDiscourseUser implements ShouldQueue
2017
{
2118
/**
22-
* @var Client
19+
* The client instance
2320
*/
24-
public $client;
21+
public Client $client;
2522

2623
/**
27-
* @var Repository
24+
* @The repository instance
2825
*/
29-
public $config_repository;
26+
public Repository $config_repository;
3027

3128
/**
32-
* @var Logger
29+
* The logger instance
3330
*/
34-
public $logger;
31+
public Logger $logger;
3532

3633
/**
3734
* Create the event listener.
3835
*
39-
* @param Client $client
40-
* @param Repository $config_repository
41-
* @param Logger $logger
42-
*
4336
* @return void
4437
*/
4538
public function __construct(Client $client, Repository $config_repository, Logger $logger)
@@ -52,20 +45,18 @@ public function __construct(Client $client, Repository $config_repository, Logge
5245
/**
5346
* Handle the event.
5447
*
55-
* @param mixed $event
56-
*
5748
* @return void
5849
*/
5950
public function handle($event)
6051
{
61-
if (!$event->user) {
52+
if (! $event->user) {
6253
return;
6354
}
6455

6556
$configs = [
6657
'base_uri' => $this->config_repository->get('services.discourse.url'),
67-
'headers' => [
68-
'Api-Key' => $this->config_repository->get('services.discourse.api.key'),
58+
'headers' => [
59+
'Api-Key' => $this->config_repository->get('services.discourse.api.key'),
6960
'Api-Username' => $this->config_repository->get('services.discourse.api.user'),
7061
],
7162
];
@@ -82,6 +73,7 @@ public function handle($event)
8273
"When getting user {$event->user->id} Discourse returned status code {$response->getStatusCode()}",
8374
['reason' => $response->getReasonPhrase()]
8475
);
76+
8577
return;
8678
}
8779

src/SsoServiceProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* Class SsoServiceProvider
10-
*
11-
* @package Spinen\Discourse
1210
*/
1311
class SsoServiceProvider extends ServiceProvider
1412
{
@@ -25,7 +23,7 @@ function (Router $router) {
2523
$router->get(
2624
$this->app['config']->get('services.discourse.route'),
2725
[
28-
'as' => 'sso.login',
26+
'as' => 'sso.login',
2927
'domain' => $this->app['config']->get('services.discourse.domain', null),
3028
'uses' => 'Spinen\Discourse\Controllers\SsoController@login',
3129
]

tests/Controllers/SsoControllerTest.php

+12-15
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
/**
1414
* Class SsoControllerTest
15-
*
16-
* @package Spinen\Discourse\Controllers
1715
*/
1816
class SsoControllerTest extends TestCase
1917
{
@@ -89,7 +87,7 @@ public function it_aborts_if_the_payload_is_invalid()
8987
->with('services.discourse')
9088
->andReturn([
9189
'secret' => 'secret',
92-
'user' => [
90+
'user' => [
9391
'access' => null,
9492
],
9593
]);
@@ -151,7 +149,6 @@ public function it_is_backwards_compatible_with_config_that_does_not_have_access
151149
$controller = new SsoController($this->config_mock, $this->sso_helper_mock);
152150

153151
$controller->login($this->request_mock);
154-
155152
}
156153

157154
/**
@@ -167,7 +164,7 @@ public function it_aborts_if_the_user_does_not_have_access()
167164
->with('services.discourse')
168165
->andReturn([
169166
'secret' => 'secret',
170-
'user' => [
167+
'user' => [
171168
'access' => 'forum_access',
172169
],
173170
]);
@@ -195,14 +192,14 @@ public function it_builds_the_correct_payload()
195192
->andReturn([
196193
'secret' => 'secret',
197194
// Expect the '/' on the end to not double up
198-
'url' => 'http://discourse/',
199-
'user' => [
200-
'external_id' => 'id',
201-
'email' => 'email',
195+
'url' => 'http://discourse/',
196+
'user' => [
197+
'external_id' => 'id',
198+
'email' => 'email',
202199
// Expect this null_value to not be passed on
203-
'null_value' => null,
204-
'false_value' => false,
205-
'true_value' => true,
200+
'null_value' => null,
201+
'false_value' => false,
202+
'true_value' => true,
206203
'string_value' => 'string',
207204
],
208205
]);
@@ -243,8 +240,8 @@ public function it_builds_the_correct_payload()
243240
1,
244241
245242
[
246-
'false_value' => 'false',
247-
'true_value' => 'true',
243+
'false_value' => 'false',
244+
'true_value' => 'true',
248245
'string_value' => 'string_property',
249246
],
250247
])
@@ -258,7 +255,7 @@ public function it_builds_the_correct_payload()
258255

259256
function abort($code)
260257
{
261-
throw new Exception("Some error message", $code);
258+
throw new Exception('Some error message', $code);
262259
}
263260

264261
function redirect($path)

tests/Listeners/LogoutDiscourseUserTest.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
use Illuminate\Contracts\Config\Repository as Config;
1111
use Illuminate\Http\Request;
1212
use Mockery;
13-
use Psr\Http\Message\ResponseInterface;
14-
use Ramsey\Collection\AbstractArray;
1513
use Spinen\Discourse\TestCase;
1614
use Symfony\Component\HttpKernel\Log\Logger;
1715

1816
/**
1917
* Class LogoutDiscourseUserTest
20-
*
21-
* @package Spinen\Discourse\Listeners
2218
*/
2319
class LogoutDiscourseUserTest extends TestCase
2420
{
@@ -106,8 +102,8 @@ public function it_logs_out_the_discourse_user_when_triggered()
106102

107103
$configs = [
108104
'base_uri' => 'http://discourse.example.com',
109-
'headers' => [
110-
'Api-Key' => 'testkey',
105+
'headers' => [
106+
'Api-Key' => 'testkey',
111107
'Api-Username' => 'testuser',
112108
],
113109
];
@@ -173,8 +169,8 @@ public function on_getting_user_if_discourse_response_code_is_not_200_log_an_err
173169

174170
$configs = [
175171
'base_uri' => 'http://discourse.example.com',
176-
'headers' => [
177-
'Api-Key' => 'testkey',
172+
'headers' => [
173+
'Api-Key' => 'testkey',
178174
'Api-Username' => 'testuser',
179175
],
180176
];
@@ -226,8 +222,8 @@ public function on_user_logout_if_discourse_response_code_is_not_200_log_a_notic
226222

227223
$configs = [
228224
'base_uri' => 'http://discourse.example.com',
229-
'headers' => [
230-
'Api-Key' => 'testkey',
225+
'headers' => [
226+
'Api-Key' => 'testkey',
231227
'Api-Username' => 'testuser',
232228
],
233229
];

0 commit comments

Comments
 (0)