Showing 4,939 of 4,939 total issues

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

    private static function mergeMethodParts(array $parts): array
    {
        $prev_parts = [];
        $delta = 0;
        $results = [];
Severity: Major
Found in src/Phan/Language/Element/Comment/Builder.php and 1 other location - About 1 day to fix
src/Phan/Language/UnionType.php on lines 530..562

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 355.

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 2 locations. Consider refactoring.
Open

    private static function mergeTypeParts(array $parts): array
    {
        $prev_parts = [];
        $delta = 0;
        $results = [];
Severity: Major
Found in src/Phan/Language/UnionType.php and 1 other location - About 1 day to fix
src/Phan/Language/Element/Comment/Builder.php on lines 1325..1357

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 355.

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 analyzePrintfPattern has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
Open

    protected function analyzePrintfPattern(CodeBase $code_base, Context $context, FunctionInterface $function, $pattern_node, $arg_nodes): void
    {
        // Given a node, extract the printf directive and whether or not it could be translated
        $primitive_for_fmtstr = $this->astNodeToPrimitive($code_base, $context, $pattern_node);
        /**
Severity: Minor
Found in .phan/plugins/PrintfCheckerPlugin.php - About 1 day 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

TolerantASTConverter has 86 functions (exceeds 20 allowed). Consider refactoring.
Open

class TolerantASTConverter
{
    // The latest stable version of php-ast.
    // For something != 70, update the library's release.
    public const AST_VERSION = 70;
Severity: Major
Found in src/Phan/AST/TolerantASTConverter/TolerantASTConverter.php - About 1 day to fix

    Function check_fields has a Cognitive Complexity of 81 (exceeds 5 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: Minor
    Found in internal/sanitycheck.php - About 1 day 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 NegatedConditionVisitor.php has 702 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=1);
    
    namespace Phan\Analysis;
    Severity: Major
    Found in src/Phan/Analysis/NegatedConditionVisitor.php - About 1 day to fix

      File BinaryOperatorFlagVisitor.php has 697 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      declare(strict_types=1);
      
      namespace Phan\Analysis;
      Severity: Major
      Found in src/Phan/Analysis/BinaryOperatorFlagVisitor.php - About 1 day to fix

        Function getElementsFromElementListForDeferredAnalysis has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function getElementsFromElementListForDeferredAnalysis(
                CodeBase $code_base,
                iterable $element_list,
                int $total_count,
                int &$i
        Severity: Minor
        Found in src/Phan/Analysis/ReferenceCountsAnalyzer.php - About 1 day 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 Config.php has 683 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php
        
        declare(strict_types=1);
        
        namespace Phan;
        Severity: Major
        Found in src/Phan/Config.php - About 1 day to fix

          Function analyzeRealSignatureCompatibility has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function analyzeRealSignatureCompatibility(CodeBase $code_base, FunctionInterface $method, int $minimum_target_php_version): void
              {
                  $php70_checks = $minimum_target_php_version < 70100;
          
                  foreach ($method->getRealParameterList() as $real_parameter) {
          Severity: Minor
          Found in src/Phan/Analysis/ParameterTypesAnalyzer.php - About 1 day 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 visitDim has a Cognitive Complexity of 76 (exceeds 5 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: Minor
          Found in src/Phan/AST/UnionTypeVisitor.php - About 1 day 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 FunctionLikeDeclarationType.php has 667 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          <?php
          
          declare(strict_types=1);
          
          namespace Phan\Language\Type;
          Severity: Major
          Found in src/Phan/Language/Type/FunctionLikeDeclarationType.php - About 1 day to fix

            Function getProperty has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getProperty(
                    bool $is_static,
                    bool $is_known_assignment = false
                ): Property {
                    $node = $this->node;
            Severity: Minor
            Found in src/Phan/AST/ContextNode.php - About 1 day 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 getReturnTypeOverridesStatic has 297 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function getReturnTypeOverridesStatic(CodeBase $code_base): array
                {
                    $string_union_type = StringType::instance(false)->asPHPDocUnionType();
                    $string_union_type_real = StringType::instance(false)->asRealUnionType();
                    $string_union_type_with_false_in_real = UnionType::fromFullyQualifiedPHPDocAndRealString('string', 'string|false');
            Severity: Major
            Found in src/Phan/Plugin/Internal/DependentReturnTypeOverridePlugin.php - About 1 day to fix

              Function analyzeReturnTypesInner has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function analyzeReturnTypesInner(CodeBase $code_base): void
                  {
                      if ($this->isPHPInternal()) {
                          // nothing to do, no known Node
                          return;
              Severity: Minor
              Found in src/Phan/Language/Element/FunctionTrait.php - About 1 day 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 analyzeParameterTypesInner has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function analyzeParameterTypesInner(
                      CodeBase $code_base,
                      FunctionInterface $method
                  ): void {
                      if (Config::getValue('check_docblock_signature_param_type_match')) {
              Severity: Minor
              Found in src/Phan/Analysis/ParameterTypesAnalyzer.php - About 1 day 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 Method.php has 648 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              <?php
              
              declare(strict_types=1);
              
              namespace Phan\Language\Element;
              Severity: Major
              Found in src/Phan/Language/Element/Method.php - About 1 day to fix

                Function addProperty has a Cognitive Complexity of 71 (exceeds 5 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: Minor
                Found in src/Phan/Parse/ParseVisitor.php - About 1 day 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

                    protected function getAvailableMethodPHPDocSummaries(): array
                    {
                        return $this->memoize(__METHOD__, /** @return array<string,string> */ function (): array {
                            $code_base = $this->code_base;
                            $function_name_map = [];
                Severity: Major
                Found in internal/lib/IncompatibleStubsSignatureDetector.php and 1 other location - About 1 day to fix
                internal/lib/IncompatibleRealStubsSignatureDetector.php on lines 435..473

                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 312.

                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

                    protected function getAvailableMethodPHPDocSummaries(): array
                    {
                        return $this->memoize(__METHOD__, /** @return array<string,string> */ function (): array {
                            $code_base = $this->code_base;
                            $function_name_map = [];
                Severity: Major
                Found in internal/lib/IncompatibleRealStubsSignatureDetector.php and 1 other location - About 1 day to fix
                internal/lib/IncompatibleStubsSignatureDetector.php on lines 416..454

                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 312.

                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

                Severity
                Category
                Status
                Source
                Language