for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PagaMasTarde\Model;
use Nayjest\StrCaseConverter\Str;
/**
* Class AbstractModel
* @package PagaMasTarde\Model
*/
abstract class AbstractModel
{
* Card constructor.
*
* @param $nonStandardCard
public function __construct($nonStandardCard)
$this->fill($nonStandardCard);
}
public function fill($nonStandardCard)
$nonStandardCard = $this->getArray($nonStandardCard);
foreach ($nonStandardCard as $key => $value) {
$this->fillKeyValue($key, $value);
* Encode protected properties
* @return array
public function jsonSerialize()
$object = array();
foreach ($this as $key => $value) {
$object[$key] = $value;
return $object;
* @return array | false
protected function getArray($nonStandardCard)
if ($nonStandardCard instanceof \stdClass) {
return (array) $nonStandardCard;
return is_array($nonStandardCard) ? $nonStandardCard : false;
* @param $key
* @param $value
protected function fillKeyValue($key, $value)
$key = lcfirst(Str::toCamelCase($key));
if (property_exists($this, $key)) {
if (method_exists($this, 'autoFill' . ucfirst($key))) {
$this->{'autoFill' . ucfirst($key)}($value);
} else {
$this->{$key} = $value;