[Pkg-owncloud-commits] [php-sabre-vobject] 217/341: Refactor to ease mappings for structured-values.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit 901bb845b1eee033d9d4bb8776351c291b3e78be
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Mon Jan 26 18:07:01 2015 +0100

    Refactor to ease mappings for structured-values.
---
 lib/Property/Text.php | 75 ++++++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

diff --git a/lib/Property/Text.php b/lib/Property/Text.php
index 56b3db0..ac34123 100644
--- a/lib/Property/Text.php
+++ b/lib/Property/Text.php
@@ -298,46 +298,49 @@ class Text extends Property {
 
         $values = $this->getParts();
 
-        // Special-casing the REQUEST-STATUS property.
-        //
-        // See:
-        // http://tools.ietf.org/html/rfc6321#section-3.4.1.3
-        if ($this->name === 'REQUEST-STATUS') {
-
-            $writer->writeElement('code', $values[0]);
-            $writer->writeElement('description', $values[1]);
-
-            if (isset($values[2])) {
-                $writer->writeElement('data', $values[2]);
-            }
-
-        } elseif ($this->name === 'N') {
-
-            $mapping = [
-                'surname'    => !empty($values[0]) ? $values[0] : null,
-                'given'      => !empty($values[1]) ? $values[1] : null,
-                'additional' => !empty($values[2]) ? $values[2] : null,
-                'prefix'     => !empty($values[3]) ? $values[3] : null,
-                'suffix'     => !empty($values[4]) ? $values[4] : null,
-            ];
-
-            foreach ($mapping as $name => $value) {
-                $writer->writeElement($name, $value);
+        $map = function($items) use($values, $writer) {
+            foreach ($items as $i => $item) {
+                $writer->writeElement(
+                    $item,
+                    !empty($values[$i]) ? $values[$i] : null
+                );
             }
+        };
 
-        } elseif ($this->name === 'GENDER') {
-
-            $mapping = [
-                'sex'  => !empty($values[0]) ? $values[0] : null,
-                'text' => !empty($values[1]) ? $values[1] : null,
-            ];
+        switch ($this->name) {
 
-            foreach ($mapping as $name => $value) {
-                $writer->writeElement($name, $value);
-            }
+            // Special-casing the REQUEST-STATUS property.
+            //
+            // See:
+            // http://tools.ietf.org/html/rfc6321#section-3.4.1.3
+            case 'REQUEST-STATUS':
+                $writer->writeElement('code', $values[0]);
+                $writer->writeElement('description', $values[1]);
 
-        } else {
-            parent::xmlSerializeValue($writer);
+                if (isset($values[2])) {
+                    $writer->writeElement('data', $values[2]);
+                }
+                break;
+
+            case 'N':
+                $map([
+                    'surname',
+                    'given',
+                    'additional',
+                    'prefix',
+                    'suffix'
+                ]);
+                break;
+
+            case 'GENDER':
+                $map([
+                    'sex',
+                    'text'
+                ]);
+                break;
+
+            default:
+                parent::xmlSerializeValue($writer);
         }
 
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list