Skip to content
Snippets Groups Projects

Issue #3257944: PHP 8.1: XmlSitemapWriter::openUri($uri) should either be compatible with XMLWriter::openUri(string $uri): bool

Closed Issue #3257944: PHP 8.1: XmlSitemapWriter::openUri($uri) should either be compatible with XMLWriter::openUri(string $uri): bool
+ 24
11
@@ -82,7 +82,7 @@ class XmlSitemapWriter extends \XMLWriter {
* @throws XmlSitemapGenerationException
* If the file URI cannot be opened.
*/
public function openUri($uri) {
public function openUri(string $uri): bool {
$return = parent::openUri($uri);
if (!$return) {
throw new XmlSitemapGenerationException("Could not open file $uri for writing.");
@@ -106,17 +106,17 @@ class XmlSitemapWriter extends \XMLWriter {
* @return bool
* Returns TRUE on success.
*/
public function startDocument($version = '1.0', $encoding = 'UTF-8', $standalone = NULL) {
public function startDocument(?string $version = '1.0', ?string $encoding = 'UTF-8', ?string $standalone = NULL): bool {
$this->setIndent(FALSE);
$result = parent::startDocument($version, $encoding);
if (!$result) {
$return = parent::startDocument($version, $encoding);
if (!$return) {
throw new XmlSitemapGenerationException("Unknown error occurred while writing to file {$this->uri}.");
}
if (\Drupal::config('xmlsitemap.settings')->get('xsl')) {
$this->writeXsl();
}
$this->startElement($this->isIndex() ? 'sitemapindex' : 'urlset', TRUE);
return $result;
return $return;
}
/**
@@ -172,16 +172,21 @@ class XmlSitemapWriter extends \XMLWriter {
* Element name.
* @param bool $root
* Specify if it is root element or not.
*
* @return bool
* Returns TRUE on success or FALSE on failure.
*/
public function startElement($name, $root = FALSE) {
parent::startElement($name);
public function startElement(string $name, $root = FALSE): bool {
$return = parent::startElement($name);
if ($root) {
if ($return && $root) {
foreach ($this->getRootAttributes() as $key => $value) {
$this->writeAttribute($key, $value);
}
$this->writeRaw(PHP_EOL);
}
return $return;
}
/**
@@ -205,15 +210,21 @@ class XmlSitemapWriter extends \XMLWriter {
* The element name.
* @param string|array $content
* The element contents or an array of the elements' sub-elements.
*
* @return bool
* Returns TRUE on success or FALSE on failure.
*/
public function writeElement($name, $content = NULL) {
public function writeElement(string $name, string|array $content = NULL): bool {
$return = FALSE;
if (is_array($content)) {
$this->startElement($name);
$this->writeRaw($this->formatXmlElements($content));
$this->endElement();
$return = TRUE;
}
else {
parent::writeElement($name, Html::escape(static::toString($content)));
$return = parent::writeElement($name, Html::escape(static::toString($content)));
}
$this->writeRaw(PHP_EOL);
@@ -223,6 +234,8 @@ class XmlSitemapWriter extends \XMLWriter {
if (($this->sitemapElementCount % $this->linkCountFlush) == 0) {
$this->flush();
}
return $return;
}
/**
@@ -253,7 +266,7 @@ class XmlSitemapWriter extends \XMLWriter {
* @return bool
* Returns TRUE on success.
*/
public function endDocument() {
public function endDocument(): bool {
$return = parent::endDocument();
if (!$return) {
Loading