Skip to content

Commit eb068eb

Browse files
committed
Catch exceptions
1 parent 8c5a6b5 commit eb068eb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

helper/helper.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpbb\pwakit\storage\storage;
1818
use phpbb\storage\exception\storage_exception;
1919
use phpbb\storage\helper as storage_helper;
20+
use RuntimeException;
2021

2122
class helper
2223
{
@@ -65,11 +66,18 @@ public function __construct(ext_manager $extension_manager, FastImageSize $image
6566
*/
6667
public function is_storage_local(): bool
6768
{
68-
$current_provider = $this->provider_collection->get_by_class(
69-
$this->storage_helper->get_current_provider($this->storage->get_name())
70-
);
69+
try
70+
{
71+
$storage_name = $this->storage->get_name();
72+
$provider_class = $this->storage_helper->get_current_provider($storage_name);
73+
$current_provider = $this->provider_collection->get_by_class($provider_class);
7174

72-
return $current_provider && $current_provider->get_name() === 'local';
75+
return $current_provider && $current_provider->get_name() === 'local';
76+
}
77+
catch (RuntimeException)
78+
{
79+
return false;
80+
}
7381
}
7482

7583
/**

tests/unit/helper_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public function test_is_storage_local()
159159
$this->assertTrue($this->helper->is_storage_local());
160160
}
161161

162+
public function test_is_storage_not_local()
163+
{
164+
$this->config->set('storage\phpbb_pwakit\provider', 'foo');
165+
$this->assertFalse($this->helper->is_storage_local());
166+
}
167+
162168
public function test_get_storage_path()
163169
{
164170
$this->assertEquals($this->storage_path, $this->helper->get_storage_path());

0 commit comments

Comments
 (0)