[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject: split object property rendering

git at icinga.org git at icinga.org
Fri Jun 17 11:57:00 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: dc3a2ca9996f46cda875f1e2a4b6e830f54134ee
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=dc3a2ca9996f46cda875f1e2a4b6e830f54134ee

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Jun 17 11:44:38 2016 +0200

IcingaObject: split object property rendering

Improves readability

---

 library/Director/Objects/IcingaObject.php |   87 ++++++++++++++++-------------
 1 file changed, 49 insertions(+), 38 deletions(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 5164b33..935fe4c 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -1147,53 +1147,64 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         );
 
         foreach ($this->properties as $key => $value) {
+            if (in_array($key, $blacklist)) {
+                continue;
+            }
 
-            if (substr($key, -3) === '_id') {
-                $short = substr($key, 0, -3);
-                if ($this->hasUnresolvedRelatedProperty($key)) {
-                    $out .= c::renderKeyValue(
-                        $short, // NOT
-                        c::renderString($this->$short)
-                    );
+            $out .= $this->renderObjectProperty($key, $value);
+        }
 
-                    continue;
-                }
-            }
+        return $out;
+    }
 
-            if ($value === null) {
-                continue;
-            }
-            if (in_array($key, $blacklist)) {
-                continue;
+    protected function renderObjectProperty($key, $value)
+    {
+        if (substr($key, -3) === '_id') {
+            $short = substr($key, 0, -3);
+            if ($this->hasUnresolvedRelatedProperty($key)) {
+                return c::renderKeyValue(
+                    $short, // NOT
+                    c::renderString($this->$short)
+                );
+
+                return '';
             }
+        }
+
+        if ($value === null) {
+            return '';
+        }
 
-            $method = 'render' . ucfirst($key);
-            if (method_exists($this, $method)) {
-                $out .= $this->$method($value);
+        $method = 'render' . ucfirst($key);
+        if (method_exists($this, $method)) {
+            return $this->$method($value);
+        }
+
+        if ($this->propertyIsBoolean($key)) {
+            if ($value === $this->defaultProperties[$key]) {
+                return '';
             } else {
-                if ($this->propertyIsBoolean($key)) {
-                    if ($value !== $this->defaultProperties[$key]) {
-                        $out .= c::renderKeyValue(
-                            $this->booleans[$key],
-                            c::renderBoolean($value)
-                        );
-                    }
-                } elseif ($this->propertyIsInterval($key)) {
-                    $out .= c::renderKeyValue(
-                        $this->intervalProperties[$key],
-                        c::renderInterval($value)
-                    );
-                } elseif (substr($key, -3) === '_id'
-                     && $this->hasRelation($relKey = substr($key, 0, -3))
-                ) {
-                    $out .= $this->renderRelationProperty($relKey, $value);
-                } else {
-                    $out .= c::renderKeyValue($key, c::renderString($value));
-                }
+                return c::renderKeyValue(
+                    $this->booleans[$key],
+                    c::renderBoolean($value)
+                );
             }
         }
 
-        return $out;
+        if ($this->propertyIsInterval($key)) {
+            return c::renderKeyValue(
+                $this->intervalProperties[$key],
+                c::renderInterval($value)
+            );
+        }
+
+        if (substr($key, -3) === '_id'
+             && $this->hasRelation($relKey = substr($key, 0, -3))
+        ) {
+            return $this->renderRelationProperty($relKey, $value);
+        }
+
+        return c::renderKeyValue($key, c::renderString($value));
     }
 
     protected function renderBooleanProperty($key)



More information about the icinga-checkins mailing list