mheinzerling/php-entity

View on GitHub

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");
Severity: Minor
Found in src/config/InjectionConverter.php - About 4 hrs to fix

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)) {
Severity: Minor
Found in src/orm/EntityRepository.php - About 2 hrs to fix

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));

Severity: Minor
Found in src/config/Entity.php - About 1 hr to fix

    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());
    
    
    Severity: Minor
    Found in src/config/Config.php - About 1 hr to fix

      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));
      
      
      Severity: Minor
      Found in src/config/Entity.php - About 1 hr to fix

      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");
      Severity: Minor
      Found in src/config/InjectionConverter.php - About 1 hr to fix

        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) {
        Severity: Minor
        Found in src/orm/EntityRepository.php - About 1 hr to fix

        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
        Severity: Minor
        Found in src/DatabaseTypeConverter.php - About 55 mins to fix

        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', []);
        Severity: Minor
        Found in src/config/Entity.php - About 35 mins to fix

        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");
        Severity: Major
        Found in src/orm/EntityRepository.php - About 30 mins to fix
          Severity
          Category
          Status
          Source
          Language