-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing notes typecast issue #34
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,34 +67,51 @@ protected function request($method, $relativeUrl, $data = null) | |
} | ||
else | ||
{ | ||
return static::buildEntity($response); | ||
return static::buildEntity(null, $response); | ||
} | ||
} | ||
|
||
protected static function buildEntity($data) | ||
protected static function buildEntity($key, $data) | ||
{ | ||
$entities = static::getDefinedEntitiesArray(); | ||
|
||
if (isset($data['entity'])) | ||
if (self::isNotes($key) === true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make a generic isArrayableAttribute function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
{ | ||
if (in_array($data['entity'], $entities)) | ||
$entity = $data; | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored |
||
{ | ||
if (isset($data['entity'])) | ||
{ | ||
$class = static::getEntityClass($data['entity']); | ||
$entity = new $class; | ||
if (in_array($data['entity'], $entities)) | ||
{ | ||
$class = static::getEntityClass($data['entity']); | ||
$entity = new $class; | ||
} | ||
else | ||
{ | ||
$entity = new self; | ||
} | ||
} | ||
else | ||
{ | ||
$entity = new static; | ||
$entity = new self; | ||
} | ||
|
||
$entity->fill($data); | ||
} | ||
else | ||
|
||
return $entity; | ||
} | ||
|
||
protected static function isNotes($key) | ||
{ | ||
if ($key === 'notes') | ||
{ | ||
$entity = new static; | ||
return true; | ||
} | ||
|
||
$entity->fill($data); | ||
|
||
return $entity; | ||
return false; | ||
} | ||
|
||
protected static function getDefinedEntitiesArray() | ||
|
@@ -138,7 +155,7 @@ public function fill($data) | |
{ | ||
if (is_array($v)) | ||
{ | ||
$entity = static::buildEntity($v); | ||
$entity = static::buildEntity($key, $v); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create a separate function for filling a single key => value pair. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored. Added a helper for the associate array case as well. |
||
array_push($collection, $entity); | ||
} | ||
else | ||
|
@@ -151,7 +168,7 @@ public function fill($data) | |
} | ||
else | ||
{ | ||
$value = static::buildEntity($value); | ||
$value = static::buildEntity($key, $value); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@captn3m0 not sure if it's a good idea to pass null. Was thinking if we can make key as the second argument. What do you think?