Skip to content

Commit 100fbab

Browse files
committed
PHP 8.2 related updates
1 parent 170deaf commit 100fbab

File tree

19 files changed

+206
-175
lines changed

19 files changed

+206
-175
lines changed

controller/main.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpbb\skeleton\controller;
1515

16+
use Exception;
1617
use phpbb\config\config;
1718
use phpbb\controller\helper;
1819
use phpbb\exception\http_exception;
@@ -23,35 +24,36 @@
2324
use phpbb\template\template;
2425
use phpbb\user;
2526
use Symfony\Component\HttpFoundation\Response;
27+
use Symfony\Component\HttpFoundation\StreamedResponse;
2628

2729
class main
2830
{
2931
/** @var array */
30-
protected $data;
32+
protected array $data;
3133

3234
/* @var config */
33-
protected $config;
35+
protected config $config;
3436

3537
/* @var helper */
36-
protected $helper;
38+
protected helper $helper;
3739

3840
/** @var language */
39-
protected $language;
41+
protected language $language;
4042

4143
/* @var request */
42-
protected $request;
44+
protected request $request;
4345

4446
/* @var packager */
45-
protected $packager;
47+
protected packager $packager;
4648

4749
/* @var validator */
48-
protected $validator;
50+
protected validator $validator;
4951

5052
/* @var template */
51-
protected $template;
53+
protected template $template;
5254

5355
/* @var user */
54-
protected $user;
56+
protected user $user;
5557

5658
/**
5759
* Constructor
@@ -83,11 +85,11 @@ public function __construct(config $config, helper $helper, language $language,
8385
* Controller for route /skeleton
8486
*
8587
* @throws http_exception
86-
* @throws \Exception
88+
* @throws Exception
8789
*
88-
* @return Response A Symfony Response object
90+
* @return Response|StreamedResponse A Symfony Response object
8991
*/
90-
public function handle()
92+
public function handle(): Response|StreamedResponse
9193
{
9294
if ($this->user->data['is_bot'])
9395
{
@@ -104,16 +106,16 @@ public function handle()
104106
$this->packager->create_extension($this->data);
105107
$filename = $this->packager->create_zip($this->data);
106108

107-
$response = new Response($filename);
109+
$response = new StreamedResponse(function() use ($filename) {
110+
readfile($filename);
111+
});
108112
$response->headers->set('Content-type', 'application/octet-stream');
109113
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '";');
110114
$response->headers->set('Content-length', filesize($filename));
111-
$response->sendHeaders();
112-
$response->setContent(readfile($filename));
113115

114116
return $response;
115117
}
116-
catch (\Exception $e)
118+
catch (Exception $e)
117119
{
118120
$this->template->assign_var('ERROR', $e->getMessage());
119121
}
@@ -145,7 +147,7 @@ public function handle()
145147
'NAME' => $value,
146148
'DESC' => $this->language->lang('SKELETON_QUESTION_' . strtoupper($value) . '_UI'),
147149
'DESC_EXPLAIN' => $this->language->is_set('SKELETON_QUESTION_' . strtoupper($value) . '_EXPLAIN') ? $this->language->lang('SKELETON_QUESTION_' . strtoupper($value) . '_EXPLAIN') : '',
148-
'VALUE' => isset($author_values[$value][$i]) ? $author_values[$value][$i] : '',
150+
'VALUE' => $author_values[$value][$i] ?? '',
149151
]);
150152
}
151153
}
@@ -189,7 +191,7 @@ public function handle()
189191
/**
190192
* Get composer data
191193
*/
192-
protected function get_composer_data()
194+
protected function get_composer_data(): void
193195
{
194196
$dialog_questions = $this->packager->get_composer_dialog_values();
195197
foreach ($dialog_questions['extension'] as $value => $default)
@@ -215,7 +217,7 @@ protected function get_composer_data()
215217
/**
216218
* Get components data
217219
*/
218-
protected function get_component_data()
220+
protected function get_component_data(): void
219221
{
220222
$components = $this->packager->get_component_dialog_values();
221223
foreach ($components as $component => $details)
@@ -236,13 +238,13 @@ protected function get_component_data()
236238
/**
237239
* Get user input values
238240
*
239-
* @param string $value
241+
* @param string $value
240242
* @param mixed $default
241-
* @param null|int $array_key for multi user support
243+
* @param int|null $array_key for multi user support
242244
*
243-
* @return mixed|string
245+
* @return mixed
244246
*/
245-
protected function get_user_input($value, $default, $array_key = null)
247+
protected function get_user_input(string $value, mixed $default, int $array_key = null): mixed
246248
{
247249
$return_value = $this->get_request_variable($value, $default, $array_key);
248250

@@ -257,20 +259,20 @@ protected function get_user_input($value, $default, $array_key = null)
257259
/**
258260
* Get request variables
259261
*
260-
* @param string $value
261-
* @param mixed $default
262-
* @param null|int $array_key for multi user support
262+
* @param string $value
263+
* @param mixed $default
264+
* @param int|null $array_key for multi user support
263265
*
264-
* @return mixed|string
266+
* @return mixed
265267
*/
266-
protected function get_request_variable($value, $default, $array_key = null)
268+
protected function get_request_variable(string $value, mixed $default, int $array_key = null): mixed
267269
{
268270
if (is_bool($default))
269271
{
270272
if ($array_key !== null)
271273
{
272274
$return_value = $this->request->variable($value, [$default]);
273-
return isset($return_value[$array_key]) ? $return_value[$array_key] : $default;
275+
return $return_value[$array_key] ?? $default;
274276
}
275277

276278
return $this->request->variable($value, $default);

event/main_listener.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,38 @@
1616
/**
1717
* @ignore
1818
*/
19+
20+
use phpbb\controller\helper;
21+
use phpbb\event\data;
22+
use phpbb\template\template;
1923
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2024

2125
/**
2226
* Event listener
2327
*/
2428
class main_listener implements EventSubscriberInterface
2529
{
26-
public static function getSubscribedEvents()
30+
public static function getSubscribedEvents(): array
2731
{
2832
return [
2933
'core.user_setup' => 'load_language_on_setup',
3034
'core.page_header' => 'add_page_header_link',
3135
];
3236
}
3337

34-
/* @var \phpbb\controller\helper */
35-
protected $helper;
38+
/* @var helper */
39+
protected helper $helper;
3640

37-
/* @var \phpbb\template\template */
38-
protected $template;
41+
/* @var template */
42+
protected template $template;
3943

4044
/**
4145
* Constructor
4246
*
43-
* @param \phpbb\controller\helper $helper Controller helper object
44-
* @param \phpbb\template\template $template Template object
47+
* @param helper $helper Controller helper object
48+
* @param template $template Template object
4549
*/
46-
public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template)
50+
public function __construct(helper $helper, template $template)
4751
{
4852
$this->helper = $helper;
4953
$this->template = $template;
@@ -52,9 +56,9 @@ public function __construct(\phpbb\controller\helper $helper, \phpbb\template\te
5256
/**
5357
* Load language files
5458
*
55-
* @param \phpbb\event\data $event
59+
* @param data $event
5660
*/
57-
public function load_language_on_setup($event)
61+
public function load_language_on_setup(data $event): void
5862
{
5963
$lang_set_ext = $event['lang_set_ext'];
6064
$lang_set_ext[] = [
@@ -67,7 +71,7 @@ public function load_language_on_setup($event)
6771
/**
6872
* Add the page header link
6973
*/
70-
public function add_page_header_link()
74+
public function add_page_header_link(): void
7175
{
7276
$this->template->assign_var('U_PHPBB_SKELETON_EXT', $this->helper->route('phpbb_skeleton_controller'));
7377
}

ext.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace phpbb\skeleton;
1515

16-
class ext extends \phpbb\extension\base
16+
use phpbb\extension\base;
17+
18+
class ext extends base
1719
{
1820
public const DEFAULT_SKELETON_PHP = '7.1.3';
1921
public const DEFAULT_SKELETON_PHPBB_MIN = '3.3.0';
@@ -25,14 +27,14 @@ class ext extends \phpbb\extension\base
2527
/**
2628
* @var array An array of installation error messages
2729
*/
28-
protected $errors = [];
30+
protected array $errors = [];
2931

3032
/**
3133
* Check whether the extension can be enabled.
3234
*
33-
* @return bool|array True if it can be enabled. False if not, or an array of error messages in phpBB 3.3.
35+
* @return array|bool True if it can be enabled. False if not, or an array of error messages in phpBB 3.3.
3436
*/
35-
public function is_enableable()
37+
public function is_enableable(): array|bool
3638
{
3739
// Check requirements
3840
$this->phpbb_requirement();
@@ -48,7 +50,7 @@ public function is_enableable()
4850
* @param string $phpBB_version
4951
* @return void
5052
*/
51-
protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
53+
protected function phpbb_requirement(string $phpBB_version = PHPBB_VERSION): void
5254
{
5355
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
5456
{
@@ -62,7 +64,7 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
6264
* @param int $php_version
6365
* @return void
6466
*/
65-
protected function php_requirement($php_version = PHP_VERSION_ID)
67+
protected function php_requirement(int $php_version = PHP_VERSION_ID): void
6668
{
6769
if ($php_version < self::MIN_PHP_ALLOWED)
6870
{
@@ -76,7 +78,7 @@ protected function php_requirement($php_version = PHP_VERSION_ID)
7678
* @param string $zip_class
7779
* @return void
7880
*/
79-
protected function ziparchive_exists($zip_class = 'ZipArchive')
81+
protected function ziparchive_exists(string $zip_class = 'ZipArchive'): void
8082
{
8183
if (!class_exists($zip_class, false))
8284
{
@@ -90,7 +92,7 @@ protected function ziparchive_exists($zip_class = 'ZipArchive')
9092
*
9193
* @return array|bool
9294
*/
93-
protected function enable_failed()
95+
protected function enable_failed(): array|bool
9496
{
9597
if (phpbb_version_compare(PHPBB_VERSION, '3.3.0-b1', '>='))
9698
{

0 commit comments

Comments
 (0)