Skip to content

Commit 22c53f2

Browse files
committed
Fix places where potential null handling was missing
New versions of Psalm will start detecting them soon, so better we fix the in advance. Note that it's rare to get those 2 cases reproduced in real life, because other validations will fail earlier if those XML are corrupt, but better have the case covered there.
1 parent fe864f1 commit 22c53f2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Bridge/Vendors.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public function __construct($path)
5050
*/
5151
public function getVendorPaths()
5252
{
53-
$base = dirname($this->path);
54-
$paths = [];
55-
foreach ($this->xml->xpath('/libraries/library/location') as $location) {
53+
$base = dirname($this->path);
54+
$paths = [];
55+
$locations = $this->xml->xpath('/libraries/library/location') ?? false ?: [];
56+
foreach ($locations as $location) {
5657
$location = trim((string) $location, '/');
5758
$location = $base . '/' . $location;
5859

src/PluginValidate/Finder/TableFinder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public function findTokens($file, FileTokens $fileTokens): void
3636
*/
3737
protected function findTables(string $file): array
3838
{
39-
$tables = [];
40-
$xml = simplexml_load_file($file);
41-
foreach ($xml->xpath('TABLES/TABLE') as $element) {
39+
$tables = [];
40+
$xml = simplexml_load_file($file);
41+
$elements = $xml->xpath('TABLES/TABLE') ?? false ?: [];
42+
foreach ($elements as $element) {
4243
if (isset($element['NAME'])) {
4344
$tables[] = (string) $element['NAME'];
4445
}

0 commit comments

Comments
 (0)