for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Xetaravel\Models;
use Xetaravel\Models\Presenters\SettingPresenter;
class Setting extends Model
{
use SettingPresenter;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'value_int',
'value_str',
'value_bool',
'value',
'description',
'last_updated_user_id'
];
* The accessors to append to the model's array form.
protected $appends = [
'value'
* The "booting" method of the model.
* @return void
protected static function boot()
parent::boot();
// Get the type of the value before to save.
static::updating(function ($model) {
$model = self::castValue($model->new_value, $model);
unset($model->new_value);
});
}
private static function castValue($value, $model)
switch (gettype($value)) {
case 'int':
case 'integer':
$model->value_int = $value;
$model->value_str = null;
$model->value_bool = null;
return $model;
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
return
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case
case 'bool':
case 'boolean':
$model->value_int = null;
$model->value_bool = $value;
default:
$model->value_str = $value;
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.