elabftw/elabftw

View on GitHub
src/Import/Eln.php

Summary

Maintainability
D
2 days
Test Coverage

Function importRootDataset has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    private function importRootDataset(array $dataset): void
    {
        $createTarget = $this->targetNumber;
        $title = $this->transformIfNecessary($dataset['name'] ?? _('Untitled'));

Severity: Minor
Found in src/Import/Eln.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 importRootDataset has 109 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function importRootDataset(array $dataset): void
    {
        $createTarget = $this->targetNumber;
        $title = $this->transformIfNecessary($dataset['name'] ?? _('Untitled'));

Severity: Major
Found in src/Import/Eln.php - About 4 hrs to fix

    File Eln.php has 289 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /**
     * @author Nicolas CARPi <nico-git@deltablot.email>
     * @copyright 2022 Nicolas CARPi
    Severity: Minor
    Found in src/Import/Eln.php - About 2 hrs to fix

      Function importFile has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          private function importFile(array $file): void
          {
              // note: path transversal vuln is detected and handled by flysystem
              $filepath = $this->tmpPath . '/' . basename($this->root) . '/' . $file['@id'];
              // checksum is mandatory for import
      Severity: Minor
      Found in src/Import/Eln.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 importFile has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function importFile(array $file): void
          {
              // note: path transversal vuln is detected and handled by flysystem
              $filepath = $this->tmpPath . '/' . basename($this->root) . '/' . $file['@id'];
              // checksum is mandatory for import
      Severity: Minor
      Found in src/Import/Eln.php - About 1 hr to fix

        Function import has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            public function import(): void
            {
                // figure out the path to the root of the eln (where the metadata file lives)
                // the name of the folder is not fixed, so list folders and pick the first one found (there should be only one)
                $listing = $this->fs->listContents($this->tmpDir);
        Severity: Minor
        Found in src/Import/Eln.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 import has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function import(): void
            {
                // figure out the path to the root of the eln (where the metadata file lives)
                // the name of the folder is not fixed, so list folders and pick the first one found (there should be only one)
                $listing = $this->fs->listContents($this->tmpDir);
        Severity: Minor
        Found in src/Import/Eln.php - About 1 hr to fix

          Function importPart has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function importPart(array $part): void
              {
                  if (empty($part['@type'])) {
                      return;
                  }
          Severity: Minor
          Found in src/Import/Eln.php - About 45 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

          There are no issues that match your filters.

          Category
          Status