Skip to content

Commit 2aff1f1

Browse files
committed
Cleanup
1 parent 8caab9e commit 2aff1f1

File tree

9 files changed

+51
-23
lines changed

9 files changed

+51
-23
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[*]
22
end_of_line = lf
3+
php_diagnostic_php0416 = false
34

45
[/vendor/**]
56
php_diagnostic = false

app/FrontController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Chell;
44

5+
use Exception;
56
use Throwable;
67

78
use Chell\Controllers\ErrorController;
@@ -270,7 +271,7 @@ private function setTranslator()
270271
*/
271272
private function setSettings()
272273
{
273-
$structuredSettings = new SettingsContainer($this->config);
274+
$structuredSettings = new SettingsContainer($this->config, $this->dbSet);
274275
$this->di->set('settings', $structuredSettings);
275276
$this->settings = $structuredSettings;
276277
}
@@ -283,6 +284,14 @@ private function setSettings()
283284
public function __toString() : string
284285
{
285286
$uri = (new Request())->getURI();
286-
return $this->application->handle($uri)->getContent();
287+
try
288+
{
289+
return $this->application->handle($uri)->getContent();
290+
}
291+
catch (Exception $exception)
292+
{
293+
(new ErrorController())->initialize(new ChellException($exception));
294+
return '';
295+
}
287296
}
288297
}

app/controllers/InstallController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
class InstallController extends BaseController
1919
{
20-
private string $dbStructureFilename = APP_PATH . 'sql/db-structure.sql';
2120
private $postedData;
2221

2322
private $tableOrder = ['devices', 'menu_items', 'users', 'menu_items_users', 'settings', 'snmp_hosts', 'snmp_records', 'speedtest', 'widget_position'];
@@ -91,13 +90,13 @@ public function goAction()
9190
{
9291
$migrationOptions['tableName'] = $table;
9392
$migration::run($migrationOptions);
94-
93+
9594
if ($this->tableOrder[count($this->tableOrder)-1] != $table)
9695
{
9796
$migration::removeCurrentVersion($migrationOptions, $migrationOptions['version']);
9897
}
9998
}
100-
99+
101100
$this->di->set('db', function() use ($config) {
102101
return new DbAdapter([
103102
'host' => $config['mysql-host'],
@@ -185,9 +184,8 @@ private function writeConfig()
185184
*/
186185
private function cleanup()
187186
{
188-
@unlink($this->dbStructureFilename);
189187
@unlink(APP_PATH . 'app/controllers/InstallController.php');
190-
@array_map('unlink', array_filter(glob(APP_PATH . 'app/views/install/')));
191-
@unlink(APP_PATH . 'app/views/install/');
188+
@unlink(APP_PATH . 'app/views/install/index.phtml');
189+
@rmdir(APP_PATH . 'app/views/install/');
192190
}
193191
}

app/models/Jellyfin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Chell\Models;
44

5+
use Exception;
56
use GuzzleHttp\Client;
67
use GuzzleHttp\Promise;
78
use GuzzleHttp\Promise\PromiseInterface;

app/models/Opcache.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Opcache extends Model
1515

1616
/**
1717
* Retrieves the Opcache status.
18+
* @suppress PHP0417
1819
*/
1920
public function initialize()
2021
{
@@ -124,4 +125,12 @@ public function getFormattedData(string $key, string $value) : string
124125
return number_format($value, 2) . '%';
125126
}
126127
}
128+
129+
/**
130+
* @suppress PHP0417
131+
*/
132+
public function getConfiguration()
133+
{
134+
return opcache_get_configuration();
135+
}
127136
}

app/models/SettingsCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __set(string $name, ?string $value)
3535
{
3636
if (!isset($this->_settings[$name]))
3737
{
38-
$this->_settings[$name] = new Settings(['name' => $name, 'category' => $this->name, 'section' => $this->section->name, 'value' => $value]);
38+
$this->_settings[$name] = new Settings(['name' => $name, 'category' => $this->name, 'section' => $this->section?->name, 'value' => $value]);
3939
}
4040

4141
$this->_settings[$name]->value = $value;

app/models/SettingsContainer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SettingsContainer implements IteratorAggregate
2727
* If DB is configured; get all settings from the database and add them to the SettingsContainer.
2828
* If DB is not configured; set some default settings which are required for Chell to work.
2929
*/
30-
public function __construct(ConfigIni $config)
30+
public function __construct(ConfigIni $config, bool $dbSet)
3131
{
3232
$this->addSection($dashboardSection = new SettingsSection('dashboard'));
3333
$this->addSection($generalSection = new SettingsSection('general'));
@@ -44,7 +44,8 @@ public function __construct(ConfigIni $config)
4444
$applicationCategory->addSetting(new SettingsDefault('check_device_states_interval', '10', SettingsDefaultStorageType::db));
4545

4646
//todo: better way to check if DB is initialized
47-
try {
47+
if ($dbSet)
48+
{
4849
$settings = Settings::find(['order' => 'category']);
4950

5051
foreach ($settings as $setting)
@@ -57,9 +58,6 @@ public function __construct(ConfigIni $config)
5758
$this->{$setting->section}->{$setting->category}->addSetting($setting);
5859
}
5960
}
60-
catch (DiException $exception)
61-
{
62-
}
6361
}
6462

6563
/**

app/models/Sonos.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ public function getHouseholds()
6363
$content = $this->getHttpClient($this->apiControlUrl . 'households', 'GET', $this->getBearerAuthorization());
6464
$result = [];
6565

66-
foreach ($content->households as $household)
66+
if ($content)
6767
{
68-
$result[$household->name] = $household->name;
68+
foreach ($content->households as $household)
69+
{
70+
$result[$household->name] = $household->name;
71+
}
6972
}
7073

7174
return $result;
@@ -74,11 +77,15 @@ public function getHouseholds()
7477
private function getHouseholdIdByName($name)
7578
{
7679
$content = $this->getHttpClient($this->apiControlUrl . 'households', 'GET', $this->getBearerAuthorization());
77-
foreach ($content->households as $household)
80+
81+
if ($content)
7882
{
79-
if ($household->name == $name)
83+
foreach ($content->households as $household)
8084
{
81-
return $household->id;
85+
if ($household->name == $name)
86+
{
87+
return $household->id;
88+
}
8289
}
8390
}
8491

@@ -97,9 +104,12 @@ public function getGroups(string $household)
97104
$content = $this->getHttpClient($this->apiControlUrl . 'households/' . $householdId . '/groups', 'GET', $this->getBearerAuthorization());
98105
$result = [];
99106

100-
foreach ($content->groups as $group)
107+
if ($content)
101108
{
102-
$result[$group->name] = $group->name;
109+
foreach ($content->groups as $group)
110+
{
111+
$result[$group->name] = $group->name;
112+
}
103113
}
104114

105115
return $result;

app/views/opcache/partials/config.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
<div class="table-responsive">
33
<table class="table table-striped table-hover">
44
<tbody>
5-
<?php $config = opcache_get_configuration();
6-
foreach ($config['directives'] as $key => $value): ?>
5+
<?php
6+
$config = $opcache->getConfiguration();
7+
foreach ($config['directives'] as $key => $value):
8+
?>
79
<tr>
810
<td>
911
<?php echo ucfirst(str_replace('_', ' ', $key)) ?>

0 commit comments

Comments
 (0)