diff options
author | zotlabs <mike@macgirvin.com> | 2019-04-25 21:49:18 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2019-04-25 21:49:18 -0700 |
commit | e6521d1cf3166a888ad58b09059d9dc5746ad795 (patch) | |
tree | 6ab3e41d888f18b2dcad351f86c3ed0628eda307 /vendor/sabre/vobject/lib/Property/ICalendar/Recur.php | |
parent | 96785e8df1b325a32c93ebebf67ab5208f4088dc (diff) | |
parent | d689778465c0439d0ceae071dab2509e3f95403e (diff) | |
download | volse-hubzilla-e6521d1cf3166a888ad58b09059d9dc5746ad795.tar.gz volse-hubzilla-e6521d1cf3166a888ad58b09059d9dc5746ad795.tar.bz2 volse-hubzilla-e6521d1cf3166a888ad58b09059d9dc5746ad795.zip |
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'vendor/sabre/vobject/lib/Property/ICalendar/Recur.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Property/ICalendar/Recur.php | 133 |
1 files changed, 56 insertions, 77 deletions
diff --git a/vendor/sabre/vobject/lib/Property/ICalendar/Recur.php b/vendor/sabre/vobject/lib/Property/ICalendar/Recur.php index 434b77088..baeda781e 100644 --- a/vendor/sabre/vobject/lib/Property/ICalendar/Recur.php +++ b/vendor/sabre/vobject/lib/Property/ICalendar/Recur.php @@ -22,36 +22,33 @@ use Sabre\Xml; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Recur extends Property { - +class Recur extends Property +{ /** * Updates the current value. * * This may be either a single, or multiple strings in an array. * * @param string|array $value - * - * @return void */ - function setValue($value) { - + public function setValue($value) + { // If we're getting the data from json, we'll be receiving an object if ($value instanceof \StdClass) { - $value = (array)$value; + $value = (array) $value; } if (is_array($value)) { $newVal = []; foreach ($value as $k => $v) { - if (is_string($v)) { $v = strtoupper($v); // The value had multiple sub-values - if (strpos($v, ',') !== false) { + if (false !== strpos($v, ',')) { $v = explode(',', $v); } - if (strcmp($k, 'until') === 0) { + if (0 === strcmp($k, 'until')) { $v = strtr($v, [':' => '', '-' => '']); } } elseif (is_array($v)) { @@ -66,7 +63,6 @@ class Recur extends Property { } else { throw new \InvalidArgumentException('You must either pass a string, or a key=>value array'); } - } /** @@ -80,26 +76,24 @@ class Recur extends Property { * * @return string */ - function getValue() { - + public function getValue() + { $out = []; foreach ($this->value as $key => $value) { - $out[] = $key . '=' . (is_array($value) ? implode(',', $value) : $value); + $out[] = $key.'='.(is_array($value) ? implode(',', $value) : $value); } - return strtoupper(implode(';', $out)); + return strtoupper(implode(';', $out)); } /** * Sets a multi-valued property. * * @param array $parts - * @return void */ - function setParts(array $parts) { - + public function setParts(array $parts) + { $this->setValue($parts); - } /** @@ -110,10 +104,9 @@ class Recur extends Property { * * @return array */ - function getParts() { - + public function getParts() + { return $this->value; - } /** @@ -123,13 +116,10 @@ class Recur extends Property { * not yet done, but parameters are not included. * * @param string $val - * - * @return void */ - function setRawMimeDirValue($val) { - + public function setRawMimeDirValue($val) + { $this->setValue($val); - } /** @@ -137,10 +127,9 @@ class Recur extends Property { * * @return string */ - function getRawMimeDirValue() { - + public function getRawMimeDirValue() + { return $this->getValue(); - } /** @@ -151,10 +140,9 @@ class Recur extends Property { * * @return string */ - function getValueType() { - + public function getValueType() + { return 'RECUR'; - } /** @@ -164,39 +152,36 @@ class Recur extends Property { * * @return array */ - function getJsonValue() { - + public function getJsonValue() + { $values = []; foreach ($this->getParts() as $k => $v) { - if (strcmp($k, 'UNTIL') === 0) { + if (0 === strcmp($k, 'UNTIL')) { $date = new DateTime($this->root, null, $v); $values[strtolower($k)] = $date->getJsonValue()[0]; - } elseif (strcmp($k, 'COUNT') === 0) { + } elseif (0 === strcmp($k, 'COUNT')) { $values[strtolower($k)] = intval($v); } else { $values[strtolower($k)] = $v; } } - return [$values]; + return [$values]; } /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. * - * @param Xml\Writer $writer XML writer. - * - * @return void + * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) { - + protected function xmlSerializeValue(Xml\Writer $writer) + { $valueType = strtolower($this->getValueType()); foreach ($this->getJsonValue() as $value) { $writer->writeElement($valueType, $value); } - } /** @@ -206,12 +191,11 @@ class Recur extends Property { * * @return array */ - static function stringToArray($value) { - + public static function stringToArray($value) + { $value = strtoupper($value); $newValue = []; foreach (explode(';', $value) as $part) { - // Skipping empty parts. if (empty($part)) { continue; @@ -219,11 +203,10 @@ class Recur extends Property { list($partName, $partValue) = explode('=', $part); // The value itself had multiple values.. - if (strpos($partValue, ',') !== false) { + if (false !== strpos($partValue, ',')) { $partValue = explode(',', $partValue); } $newValue[$partName] = $partValue; - } return $newValue; @@ -251,32 +234,31 @@ class Recur extends Property { * * @return array */ - function validate($options = 0) { - + public function validate($options = 0) + { $repair = ($options & self::REPAIR); $warnings = parent::validate($options); $values = $this->getParts(); foreach ($values as $key => $value) { - - if ($value === '') { + if ('' === $value) { $warnings[] = [ - 'level' => $repair ? 1 : 3, - 'message' => 'Invalid value for ' . $key . ' in ' . $this->name, - 'node' => $this + 'level' => $repair ? 1 : 3, + 'message' => 'Invalid value for '.$key.' in '.$this->name, + 'node' => $this, ]; if ($repair) { unset($values[$key]); } - } elseif ($key == 'BYMONTH') { - $byMonth = (array)$value; + } elseif ('BYMONTH' == $key) { + $byMonth = (array) $value; foreach ($byMonth as $i => $v) { - if (!is_numeric($v) || (int)$v < 1 || (int)$v > 12) { + if (!is_numeric($v) || (int) $v < 1 || (int) $v > 12) { $warnings[] = [ - 'level' => $repair ? 1 : 3, + 'level' => $repair ? 1 : 3, 'message' => 'BYMONTH in RRULE must have value(s) between 1 and 12!', - 'node' => $this + 'node' => $this, ]; if ($repair) { if (is_array($value)) { @@ -291,14 +273,14 @@ class Recur extends Property { if (is_array($value) && empty($values[$key])) { unset($values[$key]); } - } elseif ($key == 'BYWEEKNO') { - $byWeekNo = (array)$value; + } elseif ('BYWEEKNO' == $key) { + $byWeekNo = (array) $value; foreach ($byWeekNo as $i => $v) { - if (!is_numeric($v) || (int)$v < -53 || (int)$v == 0 || (int)$v > 53) { + if (!is_numeric($v) || (int) $v < -53 || 0 == (int) $v || (int) $v > 53) { $warnings[] = [ - 'level' => $repair ? 1 : 3, + 'level' => $repair ? 1 : 3, 'message' => 'BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', - 'node' => $this + 'node' => $this, ]; if ($repair) { if (is_array($value)) { @@ -313,14 +295,14 @@ class Recur extends Property { if (is_array($value) && empty($values[$key])) { unset($values[$key]); } - } elseif ($key == 'BYYEARDAY') { - $byYearDay = (array)$value; + } elseif ('BYYEARDAY' == $key) { + $byYearDay = (array) $value; foreach ($byYearDay as $i => $v) { - if (!is_numeric($v) || (int)$v < -366 || (int)$v == 0 || (int)$v > 366) { + if (!is_numeric($v) || (int) $v < -366 || 0 == (int) $v || (int) $v > 366) { $warnings[] = [ - 'level' => $repair ? 1 : 3, + 'level' => $repair ? 1 : 3, 'message' => 'BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', - 'node' => $this + 'node' => $this, ]; if ($repair) { if (is_array($value)) { @@ -336,13 +318,12 @@ class Recur extends Property { unset($values[$key]); } } - } if (!isset($values['FREQ'])) { $warnings[] = [ - 'level' => $repair ? 1 : 3, - 'message' => 'FREQ is required in ' . $this->name, - 'node' => $this + 'level' => $repair ? 1 : 3, + 'message' => 'FREQ is required in '.$this->name, + 'node' => $this, ]; if ($repair) { $this->parent->remove($this); @@ -353,7 +334,5 @@ class Recur extends Property { } return $warnings; - } - } |