File HasAttributes.php
has 1186 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Illuminate\Database\Eloquent\Concerns;
use BackedEnum;
Function addCastAttributesToArray
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
{
foreach ($this->getCasts() as $key => $value) {
if (! array_key_exists($key, $attributes) ||
in_array($key, $mutatedAttributes)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function originalIsEquivalent
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function originalIsEquivalent($key)
{
if (! array_key_exists($key, $this->original)) {
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method castAttribute
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function castAttribute($key, $value)
{
$castType = $this->getCastType($key);
if (is_null($value) && in_array($castType, static::$primitiveCastTypes)) {
Method originalIsEquivalent
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function originalIsEquivalent($key)
{
if (! array_key_exists($key, $this->original)) {
return false;
}
Method addCastAttributesToArray
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
{
foreach ($this->getCasts() as $key => $value) {
if (! array_key_exists($key, $attributes) ||
in_array($key, $mutatedAttributes)) {
Method setAttribute
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setAttribute($key, $value)
{
// First we will check for the presence of a mutator for the set operation
// which simply lets the developers tweak the attribute as it is set on
// this model, such as "json_encoding" a listing of data for storage.
Function setAttribute
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function setAttribute($key, $value)
{
// First we will check for the presence of a mutator for the set operation
// which simply lets the developers tweak the attribute as it is set on
// this model, such as "json_encoding" a listing of data for storage.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if ($attribute === $original) {
return true;
} elseif (is_null($attribute)) {
return false;
} elseif ($this->isDateAttribute($key) || $this->isDateCastableWithCustomFormat($key)) {
Function transformModelValue
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function transformModelValue($key, $value)
{
// If the attribute has a get mutator, we will call that then return what
// it returns as the value, which is useful for transforming values on
// retrieval from the model to a form that is more useful for usage.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function relationsToArray
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function relationsToArray()
{
$attributes = [];
foreach ($this->getArrayableRelations() as $key => $value) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getClassCastableAttributeValue
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function getClassCastableAttributeValue($key, $value)
{
$caster = $this->resolveCasterClass($key);
$objectCachingDisabled = $caster->withoutObjectCaching ?? false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return (string) $value;
Avoid too many return
statements within this method. Open
return $this->fromJson($value, true);
Avoid too many return
statements within this method. Open
return $this->fillJsonAttribute($key, $value);
Avoid too many return
statements within this method. Open
return is_numeric($attribute) && is_numeric($original)
&& strcmp((string) $attribute, (string) $original) === 0;
Avoid too many return
statements within this method. Open
return $this->asDateTime($value)->toImmutable();
Avoid too many return
statements within this method. Open
return new BaseCollection($this->fromJson($value));
Avoid too many return
statements within this method. Open
return $this->castAttribute($key, $attribute) ===
$this->castAttribute($key, $original);
Avoid too many return
statements within this method. Open
return $this->getClassCastableAttributeValue($key, $value);
Avoid too many return
statements within this method. Open
return $this->getEnumCastableAttributeValue($key, $value);
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $this->fromJson($attribute) ===
$this->fromJson($original);
Avoid too many return
statements within this method. Open
return $this->fromJson($attribute) === $this->fromJson($original);
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $value;
Avoid too many return
statements within this method. Open
return $this;
Avoid too many return
statements within this method. Open
return $this->fromEncryptedString($attribute) === $this->fromEncryptedString($original);
Avoid too many return
statements within this method. Open
return $this->fromJson($value);
Avoid too many return
statements within this method. Open
return (bool) $value;
Avoid too many return
statements within this method. Open
return $this->asDateTime($value);
Avoid too many return
statements within this method. Open
return $value;
Avoid too many return
statements within this method. Open
return $this->asDate($value)->toImmutable();
Avoid too many return
statements within this method. Open
return $this->asTimestamp($value);
Avoid too many return
statements within this method. Open
return $date ?: Date::parse($value);
Avoid too many return
statements within this method. Open
return abs($this->castAttribute($key, $attribute) - $this->castAttribute($key, $original)) < PHP_FLOAT_EPSILON * 4;
Avoid too many return
statements within this method. Open
return $this->asDate($value);
Avoid too many return
statements within this method. Open
return $this->fromJson($attribute) === $this->fromJson($original);
Function getCastType
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function getCastType($key)
{
$castType = $this->getCasts()[$key];
if (isset(static::$castTypeCache[$castType])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function castAttribute
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function castAttribute($key, $value)
{
$castType = $this->getCastType($key);
if (is_null($value) && in_array($castType, static::$primitiveCastTypes)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"