mheinzerling/php-meta

View on GitHub

Showing 9 of 29 total issues

Function write has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public function write(): string
    {
        $result = $this->line("<?php");
        $result .= $this->line("declare(strict_types = 1);");
        $result .= $this->line("");
Severity: Minor
Found in src/writer/ClassWriter.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 write has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function write(): string
    {
        $result = $this->line("<?php");
        $result .= $this->line("declare(strict_types = 1);");
        $result .= $this->line("");
Severity: Minor
Found in src/writer/ClassWriter.php - About 1 hr to fix

    Function toValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function toValue(PHPType $type, $value): string
        {
            if ($type instanceof PrimitivePHPType) {
                if ($value === null) return 'null';
                if ($type->isInt()) return (string)$value;
    Severity: Minor
    Found in src/writer/TypeConverter.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

    Avoid too many return statements within this method.
    Open

                if ($value === null) return 'null';
    Severity: Major
    Found in src/writer/TypeConverter.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                  return 0;
      Severity: Major
      Found in src/writer/ClassWriter.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return $this;
        Severity: Major
        Found in src/writer/ClassWriter.php - About 30 mins to fix

          Function create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function create(): string
              {
                  $result = '    ' . $this->visibility->value();
                  if ($this->static) $result .= ' static';
                  $result .= ' function ' . $this->name . '(';
          Severity: Minor
          Found in src/writer/MethodWriter.php - About 25 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 toPHP has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function toPHP(PHPType $type, ClassWriter $classWriter): string
              {
                  $result = '';
                  if ($type->isOptional()) $result .= "?";
                  if ($type instanceof PrimitivePHPType) {
          Severity: Minor
          Found in src/writer/TypeConverter.php - About 25 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 toPHPDoc has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function toPHPDoc(PHPType $type, ClassWriter $classWriter): string
              {
                  $result = "";
                  if ($type instanceof PrimitivePHPType) {
                      $result .= $type->getToken();//TODO array of Object
          Severity: Minor
          Found in src/writer/TypeConverter.php - About 25 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

          Severity
          Category
          Status
          Source
          Language