Skip to content

Commit 8a2357f

Browse files
author
Owen Leibman
committed
Scrutinizer
Its analysis is wrong, but the "errors" it pointed out are easy to fix.
1 parent b74c476 commit 8a2357f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/PhpSpreadsheet/Reader/Xlsx.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,10 @@ private function loadStyleZip(string $filename, string $ns = ''): SimpleXMLEleme
148148
$pattern = "~ xmlns:([A-Za-z0-9_]+)=\"$ns\"~";
149149
if (preg_match($pattern, $xml, $matches) === 1) {
150150
$pattern = "~ xmlns:${matches[1]}=~";
151-
$repl = preg_replace($pattern, ' xmlns=', $xml);
152-
if (is_string($repl)) {
153-
$pattern = "~<(/?)${matches[1]}:~";
154-
$repl = preg_replace($pattern, '<$1', $repl);
155-
}
156-
if (is_string($repl)) {
151+
$repl = Worksheet::pregReplace($pattern, ' xmlns=', $xml);
152+
$pattern = "~<(/?)${matches[1]}:~";
153+
$repl = Worksheet::pregReplace($pattern, '<$1', $repl);
154+
if ($repl !== '') {
157155
$xml = $repl;
158156
}
159157
}

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ public function setNamespace(string $namespace): void
4141
$this->namespace = $namespace;
4242
}
4343

44+
/**
45+
* Cast SimpleXMLElement to bool to overcome Scrutinizer problem.
46+
*
47+
* @param mixed $value
48+
*/
49+
private static function castBool($value): bool
50+
{
51+
return (bool) $value;
52+
}
53+
4454
private function getStyleAttributes(SimpleXMLElement $value): SimpleXMLElement
4555
{
4656
$attr = null;
47-
if ($value) {
57+
if (self::castBool($value)) {
4858
$attr = $value->attributes('');
4959
if ($attr === null || count($attr) === 0) {
5060
$attr = $value->attributes($this->namespace);

0 commit comments

Comments
 (0)