Skip to content

Commit ccc6a03

Browse files
committed
Simplify RequestBody
1 parent dd948b1 commit ccc6a03

File tree

2 files changed

+7
-40
lines changed

2 files changed

+7
-40
lines changed

src/PHPDraft/Model/Elements/ObjectStructureElement.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected function parse_value_structure($object, &$dependencies)
150150
case 'object':
151151
default:
152152
$value = isset($object->content->value->content) ? $object->content->value->content : NULL;
153-
$struct = new ObjectStructureElement();
153+
$struct = $this->new_instance();
154154

155155
$this->value = $struct->parse($value, $dependencies);
156156
break;
@@ -160,6 +160,10 @@ protected function parse_value_structure($object, &$dependencies)
160160
unset($value);
161161
}
162162

163+
protected function new_instance(){
164+
return new ObjectStructureElement();
165+
}
166+
163167
/**
164168
* Parse content formed as an array
165169
*

src/PHPDraft/Model/Elements/RequestBodyElement.php

+2-39
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,8 @@ public function print_request($type = 'application/x-www-form-urlencoded')
116116
}
117117
}
118118

119-
/**
120-
* Parse $this->value as a structure based on given content
121-
*
122-
* @param mixed $object APIB content
123-
* @param array $dependencies Object dependencies
124-
*
125-
* @return void
126-
*/
127-
protected function parse_value_structure($object, &$dependencies)
128-
{
129-
switch ($this->type) {
130-
case 'array':
131-
$struct = new ArrayStructureElement();
132-
$this->value = $struct->parse($object, $dependencies);
133-
break;
134-
case 'enum':
135-
$struct = new EnumStructureElement();
136-
$this->value = $struct->parse($object, $dependencies);
137-
break;
138-
case 'object':
139-
default:
140-
$value = isset($object->content->value->content) ? $object->content->value->content : NULL;
141-
$struct = new RequestBodyElement();
142-
143-
$this->value = $struct->parse($value, $dependencies);
144-
break;
145-
}
146-
147-
unset($struct);
148-
unset($value);
149-
}
150-
151-
/**
152-
*
153-
* @return string
154-
*/
155-
function __toString()
156-
{
157-
return parent::__toString();
119+
protected function new_instance(){
120+
return new RequestBodyElement();
158121
}
159122

160123
}

0 commit comments

Comments
 (0)