Showing 4,939 of 4,939 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    protected function canCastToNonNullableTypeWithoutConfig(Type $type): bool
    {
        // can't cast native types (includes iterable or array) to object. ObjectType overrides this function.
        if ($type instanceof ObjectType
            && !$this->isNativeType()
Severity: Major
Found in src/Phan/Language/Type.php and 1 other location - About 7 hrs to fix
src/Phan/Language/Type.php on lines 3014..3044

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 229.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File ASTReverter.php has 465 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Phan\AST;
Severity: Minor
Found in src/Phan/AST/ASTReverter.php - About 7 hrs to fix

    IncompatibleSignatureDetectorBase has 50 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class IncompatibleSignatureDetectorBase
    {
        use Memoize;
    
        const FUNCTIONLIKE_BLACKLIST = '@' .
    Severity: Minor
    Found in internal/lib/IncompatibleSignatureDetectorBase.php - About 7 hrs to fix

      Method visitDim has 173 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function visitDim(Node $node, bool $treat_undef_as_nullable = false): UnionType
          {
              $union_type = self::unionTypeFromNode(
                  $this->code_base,
                  $this->context,
      Severity: Major
      Found in src/Phan/AST/UnionTypeVisitor.php - About 6 hrs to fix

        Function merge has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function merge(array $union_types, bool $normalize_array_shapes = true): UnionType
            {
                $n = \count($union_types);
                if ($n < 2) {
                    return \reset($union_types) ?: UnionType::$empty_instance;
        Severity: Minor
        Found in src/Phan/Language/UnionType.php - About 6 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 analyzePropertyTypes has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function analyzePropertyTypes(CodeBase $code_base, Clazz $clazz): void
            {
                foreach ($clazz->getPropertyMap($code_base) as $property) {
                    // This phase is done before the analysis phase, so there aren't any dynamic properties to filter out.
        
        
        Severity: Minor
        Found in src/Phan/Analysis/PropertyTypesAnalyzer.php - About 6 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

        File Initializer.php has 453 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php
        
        declare(strict_types=1);
        
        namespace Phan\Config;
        Severity: Minor
        Found in src/Phan/Config/Initializer.php - About 6 hrs to fix

          ConfigPluginSet has 49 functions (exceeds 20 allowed). Consider refactoring.
          Open

          final class ConfigPluginSet extends PluginV3 implements
              AfterAnalyzeFileCapability,
              AnalyzeClassCapability,
              AnalyzeFunctionCapability,
              AnalyzeFunctionCallCapability,
          Severity: Minor
          Found in src/Phan/Plugin/ConfigPluginSet.php - About 6 hrs to fix

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                private static function getGenericClosureForBeforeLoopBodyAnalysisVisitor(string $plugin_analysis_class): Closure
                {
                    if (property_exists($plugin_analysis_class, 'parent_node_list')) {
                        /**
                         * Create an instance of $plugin_analysis_class and run the visit*() method corresponding to $node->kind.
            Severity: Major
            Found in src/Phan/Plugin/ConfigPluginSet.php and 2 other locations - About 6 hrs to fix
            src/Phan/Plugin/ConfigPluginSet.php on lines 1164..1193
            src/Phan/Plugin/ConfigPluginSet.php on lines 1263..1292

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 220.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                private static function getGenericClosureForPluginAwarePreAnalysisVisitor(string $plugin_analysis_class): Closure
                {
                    if (property_exists($plugin_analysis_class, 'parent_node_list')) {
                        /**
                         * Create an instance of $plugin_analysis_class and run the visit*() method corresponding to $node->kind.
            Severity: Major
            Found in src/Phan/Plugin/ConfigPluginSet.php and 2 other locations - About 6 hrs to fix
            src/Phan/Plugin/ConfigPluginSet.php on lines 1263..1292
            src/Phan/Plugin/ConfigPluginSet.php on lines 1377..1406

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 220.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                private static function getGenericClosureForPluginAwarePostAnalysisVisitor(string $plugin_analysis_class): Closure
                {
                    if (property_exists($plugin_analysis_class, 'parent_node_list')) {
                        /**
                         * Create an instance of $plugin_analysis_class and run the visit*() method corresponding to $node->kind.
            Severity: Major
            Found in src/Phan/Plugin/ConfigPluginSet.php and 2 other locations - About 6 hrs to fix
            src/Phan/Plugin/ConfigPluginSet.php on lines 1164..1193
            src/Phan/Plugin/ConfigPluginSet.php on lines 1377..1406

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 220.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function analyzeComposition has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function analyzeComposition(
                    CodeBase $code_base,
                    Clazz $class
                ): void {
                    // Get the list of all inherited classes.
            Severity: Minor
            Found in src/Phan/Analysis/CompositionAnalyzer.php - About 6 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

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                    foreach ($name_parts as $i => $part) {
                        if ($part === '') {
                            if ($i > 0) {
                                throw new InvalidFQSENException(
                                    "Invalid part '' of fqsen",
            src/Phan/Language/FQSEN/FullyQualifiedGlobalStructuralElement.php on lines 110..131

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 219.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                    foreach ($name_parts as $i => $part) {
                        if ($part === '') {
                            if ($i > 0) {
                                throw new InvalidFQSENException(
                                    "Invalid part '' of fqsen",
            src/Phan/Language/FQSEN/FullyQualifiedGlobalStructuralElement.php on lines 233..254

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 219.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            File Parser.php has 444 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            <?php
            
            declare(strict_types=1);
            
            namespace Phan\AST;
            Severity: Minor
            Found in src/Phan/AST/Parser.php - About 6 hrs to fix

              Method addProperty has 165 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function addProperty(Clazz $class, string $property_name, $default_node, UnionType $real_union_type, ?Comment\Parameter $variable, int $lineno, int $flags, ?string $doc_comment, Comment $property_comment): ?Property
                  {
                      $variable_has_literals = $variable && $variable->getUnionType()->hasLiterals();
              
                      // If something goes wrong will getting the type of
              Severity: Major
              Found in src/Phan/Parse/ParseVisitor.php - About 6 hrs to fix

                File IncompatibleSignatureDetectorBase.php has 441 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                <?php
                
                declare(strict_types=1);
                
                use Phan\CodeBase;
                Severity: Minor
                Found in internal/lib/IncompatibleSignatureDetectorBase.php - About 6 hrs to fix

                  Function combineArrayTypeListsOverriding has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private static function combineArrayTypeListsOverriding(array $left_types, array $right_types, bool $is_assignment, bool $is_real): array
                      {
                          if ($is_real && !$right_types) {
                              return [];
                          }
                  Severity: Minor
                  Found in src/Phan/Language/Type/ArrayType.php - About 6 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 visitArray has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function visitArray(Node $node): UnionType
                      {
                          $children = $node->children;
                          if (\count($children) > 0) {
                              $key_set = $this->getEquivalentArraySet($node);
                  Severity: Minor
                  Found in src/Phan/AST/UnionTypeVisitor.php - About 6 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 check_fields has 164 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function check_fields(string $function_name, array $fields, array $signatures): void
                  {
                      $return_type = $fields[0];  // TODO: Check type
                      if (!is_string($return_type)) {
                          throw new InvalidArgumentException("Invalid return type: " . json_encode($return_type));
                  Severity: Major
                  Found in internal/sanitycheck.php - About 6 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language