@@ -27,12 +27,12 @@ |
||
| 27 | 27 | |
| 28 | 28 | protected function _validate() |
| 29 | 29 | { |
| 30 | - if(!is_string($this->value)) { |
|
| 30 | + if (!is_string($this->value)) { |
|
| 31 | 31 | return ''; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $info = parseURL($this->value); |
| 35 | - if($info->isValid()) { |
|
| 35 | + if ($info->isValid()) { |
|
| 36 | 36 | return $this->value; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | protected function _validate() |
| 29 | 29 | { |
| 30 | - if(is_numeric($this->value)) { |
|
| 30 | + if (is_numeric($this->value)) { |
|
| 31 | 31 | return $this->value * 1; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -29,26 +29,26 @@ |
||
| 29 | 29 | |
| 30 | 30 | protected function _validate() |
| 31 | 31 | { |
| 32 | - if(!is_string($this->value)) { |
|
| 32 | + if (!is_string($this->value)) { |
|
| 33 | 33 | return ''; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $value = trim($this->value); |
| 37 | 37 | |
| 38 | - if(empty($value)) { |
|
| 38 | + if (empty($value)) { |
|
| 39 | 39 | return ''; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // strictly validate for objects? |
| 43 | - if($this->getBoolOption('arrays') === false) |
|
| 43 | + if ($this->getBoolOption('arrays') === false) |
|
| 44 | 44 | { |
| 45 | - if(is_object(json_decode($value))) { |
|
| 45 | + if (is_object(json_decode($value))) { |
|
| 46 | 46 | return $value; |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | else |
| 50 | 50 | { |
| 51 | - if(is_array(json_decode($value, true))) { |
|
| 51 | + if (is_array(json_decode($value, true))) { |
|
| 52 | 52 | return $value; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -45,8 +45,7 @@ |
||
| 45 | 45 | if(is_object(json_decode($value))) { |
| 46 | 46 | return $value; |
| 47 | 47 | } |
| 48 | - } |
|
| 49 | - else |
|
| 48 | + } else |
|
| 50 | 49 | { |
| 51 | 50 | if(is_array(json_decode($value, true))) { |
| 52 | 51 | return $value; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | protected function _validate() |
| 29 | 29 | { |
| 30 | - if(!is_scalar($this->value)) { |
|
| 30 | + if (!is_scalar($this->value)) { |
|
| 31 | 31 | return null; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | // is a boolan, which is converted to an integer when |
| 36 | 36 | // converted to string, which in turn can be validated |
| 37 | 37 | // with a regex. |
| 38 | - if(is_bool($this->value)) { |
|
| 38 | + if (is_bool($this->value)) { |
|
| 39 | 39 | return null; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $value = (string)$this->value; |
| 43 | 43 | |
| 44 | - if(preg_match($this->getStringOption('regex'), $value)) { |
|
| 44 | + if (preg_match($this->getStringOption('regex'), $value)) { |
|
| 45 | 45 | return $value; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | protected function _validate() |
| 31 | 31 | { |
| 32 | - if(in_array($this->value, $this->getArrayOption('values'))) { |
|
| 32 | + if (in_array($this->value, $this->getArrayOption('values'))) { |
|
| 33 | 33 | return $this->value; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -6,9 +6,9 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class VariableInfo_Renderer_String extends VariableInfo_Renderer |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var mixed |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var mixed |
|
| 11 | + */ |
|
| 12 | 12 | protected $value; |
| 13 | 13 | |
| 14 | 14 | protected function init() |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | str_replace(' ', '-', $this->type) |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - if($this->info->getBoolOption('prepend-type') && !$this->info->isNull()) |
|
| 43 | + if ($this->info->getBoolOption('prepend-type') && !$this->info->isNull()) |
|
| 44 | 44 | { |
| 45 | 45 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->info->getType().'</span> '; |
| 46 | 46 | $converted = $typeLabel.' '.$converted; |
@@ -6,19 +6,19 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | abstract class VariableInfo_Renderer |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var mixed |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var mixed |
|
| 11 | + */ |
|
| 12 | 12 | protected $value; |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var VariableInfo |
|
| 16 | - */ |
|
| 14 | + /** |
|
| 15 | + * @var VariableInfo |
|
| 16 | + */ |
|
| 17 | 17 | protected $info; |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | 22 | protected $type; |
| 23 | 23 | |
| 24 | 24 | public function __construct(VariableInfo $info) |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | abstract protected function init(); |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Renders the value to the target format. |
|
| 36 | - * |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 34 | + /** |
|
| 35 | + * Renders the value to the target format. |
|
| 36 | + * |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | 39 | public function render() |
| 40 | 40 | { |
| 41 | 41 | return $this->_render(); |
@@ -21,25 +21,25 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class XMLHelper_Converter_Decorator implements \JsonSerializable |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var \SimpleXMLElement |
|
| 26 | - */ |
|
| 24 | + /** |
|
| 25 | + * @var \SimpleXMLElement |
|
| 26 | + */ |
|
| 27 | 27 | private $subject; |
| 28 | 28 | |
| 29 | 29 | const DEF_DEPTH = 512; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | 34 | private $options = array( |
| 35 | 35 | '@attributes' => true, |
| 36 | 36 | '@text' => true, |
| 37 | 37 | 'depth' => self::DEF_DEPTH |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var array|string|null |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var array|string|null |
|
| 42 | + */ |
|
| 43 | 43 | protected $result = array(); |
| 44 | 44 | |
| 45 | 45 | public function __construct(\SimpleXMLElement $element) |
@@ -47,36 +47,36 @@ discard block |
||
| 47 | 47 | $this->subject = $element; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Whether to use the `@attributes` key to store element attributes. |
|
| 52 | - * |
|
| 53 | - * @param bool $bool |
|
| 54 | - * @return XMLHelper_Converter_Decorator |
|
| 55 | - */ |
|
| 50 | + /** |
|
| 51 | + * Whether to use the `@attributes` key to store element attributes. |
|
| 52 | + * |
|
| 53 | + * @param bool $bool |
|
| 54 | + * @return XMLHelper_Converter_Decorator |
|
| 55 | + */ |
|
| 56 | 56 | public function useAttributes(bool $bool) : XMLHelper_Converter_Decorator |
| 57 | 57 | { |
| 58 | 58 | $this->options['@attributes'] = (bool)$bool; |
| 59 | 59 | return $this; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Whether to use the `@text` key to store the node text. |
|
| 64 | - * |
|
| 65 | - * @param bool $bool |
|
| 66 | - * @return XMLHelper_Converter_Decorator |
|
| 67 | - */ |
|
| 62 | + /** |
|
| 63 | + * Whether to use the `@text` key to store the node text. |
|
| 64 | + * |
|
| 65 | + * @param bool $bool |
|
| 66 | + * @return XMLHelper_Converter_Decorator |
|
| 67 | + */ |
|
| 68 | 68 | public function useText(bool $bool) : XMLHelper_Converter_Decorator |
| 69 | 69 | { |
| 70 | 70 | $this->options['@text'] = (bool)$bool; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Set the maximum depth to parse in the document. |
|
| 76 | - * |
|
| 77 | - * @param int $depth |
|
| 78 | - * @return XMLHelper_Converter_Decorator |
|
| 79 | - */ |
|
| 74 | + /** |
|
| 75 | + * Set the maximum depth to parse in the document. |
|
| 76 | + * |
|
| 77 | + * @param int $depth |
|
| 78 | + * @return XMLHelper_Converter_Decorator |
|
| 79 | + */ |
|
| 80 | 80 | public function setDepth(int $depth) : XMLHelper_Converter_Decorator |
| 81 | 81 | { |
| 82 | 82 | $this->options['depth'] = (int)max(0, $depth); |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | protected function detectAttributes() |
| 109 | 109 | { |
| 110 | - if(!$this->options['@attributes']) { |
|
| 110 | + if (!$this->options['@attributes']) { |
|
| 111 | 111 | return; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $attributes = $this->subject->attributes(); |
| 115 | 115 | |
| 116 | - if(!empty($attributes)) |
|
| 116 | + if (!empty($attributes)) |
|
| 117 | 117 | { |
| 118 | 118 | $this->result['@attributes'] = array_map('strval', iterator_to_array($attributes)); |
| 119 | 119 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $children = $this->subject; |
| 125 | 125 | $depth = $this->options['depth'] - 1; |
| 126 | 126 | |
| 127 | - if($depth <= 0) |
|
| 127 | + if ($depth <= 0) |
|
| 128 | 128 | { |
| 129 | 129 | $children = []; |
| 130 | 130 | } |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $decorator->options = ['depth' => $depth] + $this->options; |
| 139 | 139 | |
| 140 | - if(isset($this->result[$name])) |
|
| 140 | + if (isset($this->result[$name])) |
|
| 141 | 141 | { |
| 142 | - if(!is_array($this->result[$name])) |
|
| 142 | + if (!is_array($this->result[$name])) |
|
| 143 | 143 | { |
| 144 | 144 | $this->result[$name] = [$this->result[$name]]; |
| 145 | 145 | } |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | // json encode non-whitespace element simplexml text values. |
| 159 | 159 | $text = trim((string)$this->subject); |
| 160 | 160 | |
| 161 | - if(strlen($text)) |
|
| 161 | + if (strlen($text)) |
|
| 162 | 162 | { |
| 163 | - if($this->options['@text']) |
|
| 163 | + if ($this->options['@text']) |
|
| 164 | 164 | { |
| 165 | 165 | $this->result['@text'] = $text; |
| 166 | 166 | } |
@@ -145,8 +145,7 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $this->result[$name][] = $decorator; |
| 148 | - } |
|
| 149 | - else |
|
| 148 | + } else |
|
| 150 | 149 | { |
| 151 | 150 | $this->result[$name] = $decorator; |
| 152 | 151 | } |
@@ -163,8 +162,7 @@ discard block |
||
| 163 | 162 | if($this->options['@text']) |
| 164 | 163 | { |
| 165 | 164 | $this->result['@text'] = $text; |
| 166 | - } |
|
| 167 | - else |
|
| 165 | + } else |
|
| 168 | 166 | { |
| 169 | 167 | $this->result = $text; |
| 170 | 168 | } |