mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-11 04:08:12 +00:00
Code clean up and reformat.
This commit is contained in:
@@ -10,18 +10,18 @@ use LaravelBook\Ardent\Ardent;
|
||||
*/
|
||||
abstract class SingleTableInheritanceEntity extends Ardent
|
||||
{
|
||||
/**
|
||||
* The field that stores the subclass
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subclassField = null;
|
||||
/**
|
||||
* must be overridden and set to true in subclasses
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isSubclass = false;
|
||||
/**
|
||||
* The field that stores the subclass
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $subclassField = null;
|
||||
|
||||
/**
|
||||
* @param array $attributes
|
||||
@@ -36,24 +36,6 @@ abstract class SingleTableInheritanceEntity extends Ardent
|
||||
return $instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* if no subclass is defined, function as normal
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|static
|
||||
*/
|
||||
public function mapData(array $attributes)
|
||||
{
|
||||
if (!$this->subclassField) {
|
||||
return $this->newInstance();
|
||||
}
|
||||
|
||||
return new $attributes[$this->subclassField];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* instead of using $this->newInstance(), call
|
||||
@@ -86,14 +68,6 @@ abstract class SingleTableInheritanceEntity extends Ardent
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSubclass()
|
||||
{
|
||||
return $this->isSubclass;
|
||||
}
|
||||
|
||||
/**
|
||||
* ensure that the subclass field is assigned on save
|
||||
*
|
||||
@@ -106,11 +80,7 @@ abstract class SingleTableInheritanceEntity extends Ardent
|
||||
* @return bool
|
||||
*/
|
||||
public function save(
|
||||
array $rules = [],
|
||||
array $customMessages = [],
|
||||
array $options = [],
|
||||
\Closure $beforeSave = null,
|
||||
\Closure $afterSave = null
|
||||
array $rules = [], array $customMessages = [], array $options = [], \Closure $beforeSave = null, \Closure $afterSave = null
|
||||
) {
|
||||
if ($this->subclassField) {
|
||||
$this->attributes[$this->subclassField] = get_class($this);
|
||||
@@ -118,4 +88,28 @@ abstract class SingleTableInheritanceEntity extends Ardent
|
||||
|
||||
return parent::save($rules, $customMessages, $options, $beforeSave, $afterSave);
|
||||
}
|
||||
|
||||
/**
|
||||
* if no subclass is defined, function as normal
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|static
|
||||
*/
|
||||
public function mapData(array $attributes)
|
||||
{
|
||||
if (!$this->subclassField) {
|
||||
return $this->newInstance();
|
||||
}
|
||||
|
||||
return new $attributes[$this->subclassField];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSubclass()
|
||||
{
|
||||
return $this->isSubclass;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user