Showing 10 of 10 total issues
Function fixInjection
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public static function fixInjection(PHPType $type, string $fieldName, MethodWriter $methodWriter): void
{
if ($type instanceof EntityPHPType) {
$primaries = array_keys($type->getEntity()->getPrimaryKeyDatabaseTypes());
if (count($primaries) != 1) throw new \Exception("Not implemented for multiple or no primary keys");
- 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 mapValue
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
private function mapValue(string $fieldName, $value)
{
if (is_string($value) || is_numeric($value) || is_null($value)) return $value;
if (is_bool($value)) return $value ? '1' : '0';
if (is_object($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
Method toEntityBasePHPFile
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toEntityBasePHPFile(): string
{
$classWriter = (new ClassWriter("Base" . $this->name))->namespace($this->namespace)->abstract()
->extends(AClass::absolute(\mheinzerling\entity\orm\Entity::class));
Method toModelPHPFile
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toModelPHPFile(): string
{
//TODO 4 new properties
$classWriter = (new ClassWriter($this->modelClass->simple()))->namespace($this->modelClass->getNamespace());
Function toEntityBasePHPFile
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function toEntityBasePHPFile(): string
{
$classWriter = (new ClassWriter("Base" . $this->name))->namespace($this->namespace)->abstract()
->extends(AClass::absolute(\mheinzerling\entity\orm\Entity::class));
- 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 fixInjection
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function fixInjection(PHPType $type, string $fieldName, MethodWriter $methodWriter): void
{
if ($type instanceof EntityPHPType) {
$primaries = array_keys($type->getEntity()->getPrimaryKeyDatabaseTypes());
if (count($primaries) != 1) throw new \Exception("Not implemented for multiple or no primary keys");
Function persist
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function persist(Entity $entity)
{
$data = [];
$table = $this->database->getTables()[$this->table];
foreach ($table->getFields() as $fieldName => $field) {
- 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 handlePrimitive
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function handlePrimitive(PrimitivePHPType $type, ?int $length): Type
{
if ($type->isBool()) return new BoolType();
else if ($type->isInt()) return new IntType(); //TODO size , tiny big etc
else if ($type->isString()) return new VarcharType($length, "utf8mb4_unicode_ci"); //TODO collation etc
- 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 __construct
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function __construct(string $name, AClass $modelClass, array $json)
{
$this->name = $name;
$this->namespace = ANamespace::absolute(JsonUtils::required($json, 'namespace', "Missing namespace for entity '" . $name . "'"));
$this->unique = JsonUtils::optional($json, 'unique', []);
- 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 $value->format("Y-m-d H:i:s");