Browse Source

Clean code

Laurent Destailleur 3 years ago
parent
commit
9180e9a5c6
2 changed files with 7 additions and 4 deletions
  1. 4 3
      htdocs/includes/odtphp/Segment.php
  2. 3 1
      htdocs/includes/odtphp/odf.php

+ 4 - 3
htdocs/includes/odtphp/Segment.php

@@ -223,16 +223,17 @@ class Segment implements IteratorAggregate, Countable
 	 */
 	public function setVars($key, $value, $encode = true, $charset = 'ISO-8859')
 	{
-		if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) {
+		$tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT');
+
+		if (strpos($this->xml, $tag) === false) {
 			//throw new SegmentException("var $key not found in {$this->getName()}");
 		}
 
-		$tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT');
-
 		$this->vars[$tag] = $this->odf->convertVarToOdf($value, $encode, $charset);
 
 		return $this;
 	}
+
 	/**
 	 * Assign a template variable as a picture
 	 *

+ 3 - 1
htdocs/includes/odtphp/odf.php

@@ -122,7 +122,8 @@ class Odf
 	}
 
 	/**
-	 * Assing a template variable
+	 * Assing a template variable into ->vars.
+	 * For example, key is {object_date} and value is '2021-01-01'
 	 *
 	 * @param string   $key        Name of the variable within the template
 	 * @param string   $value      Replacement value
@@ -134,6 +135,7 @@ class Odf
 	public function setVars($key, $value, $encode = true, $charset = 'ISO-8859')
 	{
 		$tag = $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT'];
+
 		// TODO Warning string may be:
 		// <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span>
 		// instead of {aaa} so we should enhance this function.