Skip to content

Commit 7a640e1

Browse files
committed
make phpstan happy
1 parent d22a3e1 commit 7a640e1

5 files changed

Lines changed: 33 additions & 25 deletions

File tree

doom-scroll.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function object_table_iter(?array $arr): string
358358
foreach ($json_data['Hardware']['Storage'] as $disk) {
359359
foreach ($disk['Partitions'] as $partNum => $part) {
360360
if (isset($part['DirtyBitSet']) && $part['DirtyBitSet']) {
361-
if (empty($part['PartitionLetter'])) {
361+
if ($part['PartitionLetter'] === '') {
362362
echo "
363363
<li>
364364
Dirty bit set on <span>partition $partNum ({$disk['DeviceName']})</span>
@@ -425,7 +425,7 @@ function object_table_iter(?array $arr): string
425425

426426
foreach ($json_data['System']['ChoiceRegistryValues'] as $regkey) {
427427

428-
if ($regkey['Value'] && !in_array($regkey['Value'], $defaultRegKeys[$regkey['Name']])) {
428+
if ($regkey['Value'] && !in_array($regkey['Value'], $defaultRegKeys[$regkey['Name']], true)) {
429429
echo "
430430
<li>
431431
Registry Value <span>{$regkey['Name']}</span> found set, value of <span>{$regkey['Value']}</span>
@@ -879,24 +879,24 @@ function(&$row) {
879879
<h1>Storage</h1>
880880
<?php
881881
$drives_amount = safe_count($json_data['Hardware']['Storage']);
882-
$driveKey = 0;
883882

884-
foreach ($json_data['Hardware']['Storage'] as $driveKey => $drive) {
883+
884+
foreach ($json_data['Hardware']['Storage'] as $drive) {
885885
$drive_size_raw = $drive['DiskCapacity'];
886886
$drive_free_raw = getDriveFree($drive);
887887
$drive_taken_raw = $drive_size_raw - $drive_free_raw;
888888
$drive_size = floor(bytesToGigabytes($drive_size_raw));
889889
$drive_taken = floor(bytesToGigabytes($drive_taken_raw));
890890
// the drive size can sometimes be z ero if the drive is failing
891891
if ($drive_taken != 0 && $drive_size != 0) {
892-
$drive_percentage = round((float)$drive_taken / (float)$drive_size * 100);
892+
$drive_percentage = round($drive_taken / $drive_size * 100);
893893
} else $drive_percentage = 0;
894894

895895
$letters = array_filter(
896896
array_column($drive['Partitions'], 'PartitionLetter')
897897
);
898898
$lettersString = implode(", ", $letters);
899-
$lettersStringDisplay = empty($lettersString) ? '' : "($lettersString)";
899+
$lettersStringDisplay = ($lettersString === '') ? '' : "($lettersString)";
900900

901901
echo '
902902
<h2 class="item-header">' . $drive['DeviceName'] . '</h2>
@@ -930,15 +930,15 @@ function(&$row) {
930930
$part_size_mb = bytesToMegabytes($part_size);
931931
$part_taken_mb = ceil(bytesToMegabytes($part_taken));
932932
$part_display = "";
933-
if (!empty($part['PartitionLabel'])) {
933+
if ($part['PartitionLabel'] !== '') {
934934
$part_display .= $part['PartitionLabel'];
935935
if (isset($part['PartitionLetter'])) {
936936
$part_display .= " ({$part['PartitionLetter']})";
937937
}
938938
} else if (isset($part['PartitionLetter'])) { // and not partition label
939939
$part_display = $part['PartitionLetter'];
940940
}
941-
if (!empty($part_display))
941+
if ($part_display !== '')
942942
$part_display .= '<br/>';
943943
$fs_display = $part['Filesystem'] ?? 'Unknown';
944944

@@ -1145,7 +1145,7 @@ function(&$row) {
11451145
} else $default_browser = '';
11461146

11471147
foreach ($browser['Profiles'] as $profile):
1148-
$profile_key = array_search($profile, $browser['Profiles']);
1148+
$profile_key = array_search($profile, $browser['Profiles'], true);
11491149
?>
11501150
<h2 class="item-header"><?= $browser['Name'] ?> Profile
11511151
"<?= $profile['name'] /* This is lowercase in the json for some reason */ ?>"</h2>

manualupload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function check_keys_recursive($arr1, $arr2) {
3333
$randomString = bin2hex($randomBytes);
3434
$randomString = preg_replace('/[^A-Za-z0-9]/', '', substr($randomString, 0, 8));
3535

36-
if(in_array($file_ext,$extensions)== false){
36+
if(in_array($file_ext,$extensions, true)== false){
3737
$errors[]="Extension not allowed, please choose a Specify JSON file";
3838
}
3939

phpstan.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ includes:
22
- vendor/phpstan/phpstan-strict-rules/rules.neon
33
parameters:
44
strictRules:
5+
booleansInConditions: false
6+
57
level: 0
68
paths:
79
- .
10+
811
excludePaths:
9-
- 'vendor/'
12+
- 'vendor/'
13+
- 'gesp-mode.php'
14+
ignoreErrors:
15+
- identifier: empty.notAllowed

rudimentary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function scan_dir($dir) {
7979
$files = array(); //----------------------------------- create an empty files array to play with
8080
foreach (scandir($dir) as $file) {
8181
if ($file[0] === '.') continue; //----------------- ignores all files starting with '.'
82-
if (in_array($file, $ignored)) continue; //-------- ignores all files given in $ignored
82+
if (in_array($file, $ignored, true)) continue; //-------- ignores all files given in $ignored
8383
$files[$file] = filemtime($dir . '/' . $file); //-- add to files list
8484
}
8585
arsort($files); //------------------------------------- sort file values (creation timestamps)

viewer.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -874,16 +874,18 @@
874874
<div class="green">
875875

876876
<?php
877+
// the displayed adapter is the first one which has an IP address, or if none have an IP, then the first physical adapter.
877878
$adapterText = "Disconnected";
878879

879880
foreach ($json_data['Network']['Adapters'] as $adapter) {
880881
if ((bool) $adapter['PhysicalAdapter'] && is_array($adapter['IPAddress']) && count($adapter['IPAddress']) > 0) {
881882
$adapterText = $adapter['Description'];
883+
$foundAdapter = true;
882884
break;
883885
}
884886
};
885887

886-
if ($adapter == "") {
888+
if (!$foundAdapter) {
887889
foreach ($json_data['Network']['Adapters'] as $adapter) {
888890
if ((bool) $adapter['PhysicalAdapter']) {
889891
$adapterText = $adapter['Description'];
@@ -1204,15 +1206,15 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
12041206
$part_size = $part['PartitionCapacity'];
12051207
$part_taken = $part_size - $part['PartitionFree'];
12061208
$part_display = "";
1207-
if (!empty($part['PartitionLabel'])) {
1209+
if ($part['PartitionLabel'] !== '') {
12081210
$part_display .= $part['PartitionLabel'];
12091211
if (isset($part['PartitionLetter'])) {
12101212
$part_display .= " ({$part['PartitionLetter']})";
12111213
}
12121214
} else if (isset($part['PartitionLetter'])) { // and not partition label
12131215
$part_display = $part['PartitionLetter'];
12141216
}
1215-
if (!empty($part_display))
1217+
if ($part_display !== '')
12161218
$part_display .= '<br/>';
12171219
$fs_display = $part['Filesystem'] ?? 'Unknown';
12181220

@@ -1599,7 +1601,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
15991601
';
16001602
}
16011603

1602-
if (!empty($json_data['Hardware']['Batteries'])) {
1604+
if (count($json_data['Hardware']['Batteries']) > 0) {
16031605
foreach ($json_data['Hardware']['Batteries'] as $battery) {
16041606
$cap = floatval($battery["Remaining_Life_Percentage"]);
16051607
if (
@@ -1618,7 +1620,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
16181620
foreach ($json_data['Hardware']['Storage'] as $disk) {
16191621
foreach ($disk['Partitions'] as $partNum => $part) {
16201622
if (isset($part['DirtyBitSet']) && $part['DirtyBitSet']) {
1621-
if (empty($part['PartitionLetter'])) {
1623+
if ($part['PartitionLetter'] === '') {
16221624
$noteshtml .= "
16231625
<p>
16241626
Dirty bit set on <span>partition $partNum ({$disk['DeviceName']})</span>
@@ -1692,7 +1694,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
16921694

16931695

16941696

1695-
if (!empty($noteshtml)) {
1697+
if ($noteshtml !== '') {
16961698
$noteshtml = '<br>' . $noteshtml;
16971699
echo $noteshtml;
16981700
}
@@ -1738,7 +1740,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
17381740
$driveKey += 1;
17391741
}
17401742

1741-
if (!empty($drivehtml)) {
1743+
if ($drivehtml !== '') {
17421744
$drivehtml = '<br> <h4 style="margin:5px; color:var(--meta-h4-color);">Drive / SMART Notes</h4>' . $drivehtml;
17431745
echo $drivehtml;
17441746
}
@@ -1757,7 +1759,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
17571759

17581760
foreach ($json_data['System']['ChoiceRegistryValues'] as $regkey) {
17591761

1760-
if ($regkey['Value'] && !in_array($regkey['Value'], $defaultRegKeys[$regkey['Name']])){
1762+
if ($regkey['Value'] && !in_array($regkey['Value'], $defaultRegKeys[$regkey['Name']], true)){
17611763
$reghtml .= '
17621764
<p>
17631765
Registry Value <span>' . $regkey['Name'] . '</span> found set, value of <span>' . $regkey['Value'] . '</span>
@@ -1766,7 +1768,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
17661768

17671769
}
17681770

1769-
if (!empty($reghtml)) {
1771+
if ($reghtml !== '') {
17701772
$reghtml = '<br> <h4 style="margin:5px; color:var(--meta-h4-color);">Notable Registry Changes</h4>' . $reghtml;
17711773
echo $reghtml;
17721774
}
@@ -1777,7 +1779,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
17771779
<?php
17781780
$puphtml = '';
17791781

1780-
if (!empty($pupsfoundInstalled)) {
1782+
if (count($pupsfoundInstalled) > 0) {
17811783

17821784
$puphtml .= '<h4>Notable Software found Installed</h4>';
17831785

@@ -1790,7 +1792,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
17901792
$puphtml .= '</table>';
17911793
}
17921794

1793-
if (!empty($pupsfoundRunning)) {
1795+
if (count($pupsfoundRunning) > 0) {
17941796

17951797
$puphtml .= '<h4>Notable Software found Running</h4>';
17961798

@@ -1803,7 +1805,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
18031805
$puphtml .= '</table>';
18041806
}
18051807

1806-
if (!empty($puphtml)) {
1808+
if ($puphtml !== '') {
18071809
echo $puphtml;
18081810
} else {
18091811
echo '<h4>No Notable Software found, yay!</h4>';
@@ -1904,7 +1906,7 @@ class="' . $flavor_color . '">' . (int)$drive_taken . ' GB</span>
19041906
</div>
19051907
<div class="modal-body" id="browser-container' . $browser['Name'] . '">';
19061908
foreach ($browser['Profiles'] as $browserprofile) {
1907-
$profileKey = array_search($browserprofile, $browser['Profiles']);
1909+
$profileKey = array_search($browserprofile, $browser['Profiles'], true);
19081910
echo '
19091911
<h2>' . $browser['Name'] . ' Profile "' . $browser['Profiles'][$profileKey]['name'] . '"</h2>
19101912
<table id="' . $browser['Name'] . 'Profile' . $profileKey . 'Table" class="table">

0 commit comments

Comments
 (0)