elabftw/elabftw

View on GitHub

Showing 356 of 356 total issues

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

  if (document.getElementById('createFavTagInput')) {
    document.getElementById('createFavTagInput').addEventListener('blur', event => {
      createTagFavorite(event.target as HTMLInputElement);
    });

Severity: Major
Found in src/ts/tags.ts and 2 other locations - About 4 hrs to fix
src/ts/tags.ts on lines 33..43
src/ts/tags.ts on lines 74..84

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

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

Method generate has 109 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function generate(Experiments | Items $Entity): void
    {
        $Teams = new Teams($Entity->Users, $Entity->Users->team);
        $Teams->bypassWritePermission = true;
        if ($Entity instanceof Experiments) {
Severity: Major
Found in src/services/Populate.php - About 4 hrs to fix

    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

      Function formatMetadata has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function formatMetadata(string $json): string
          {
              $final = '';
              $Metadata = new Metadata($json);
              $extraFields = $Metadata->getExtraFields();
      Severity: Minor
      Found in src/classes/TwigFilters.php - About 3 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 edit.ts has 329 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /**
       * @author Nicolas CARPi <nico-git@deltablot.email>
       * @copyright 2012 Nicolas CARPi
       * @see https://www.elabftw.net Official website
       * @license AGPL-3.0
      Severity: Minor
      Found in src/ts/edit.ts - About 3 hrs to fix

        Method getSettingsByIdp has 97 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getSettingsByIdp(array $idp): array
            {
                $idpSigningCerts = array($idp['x509']);
        
                if (!empty($idp['x509_new'])) {
        Severity: Major
        Found in src/classes/IdpsHelper.php - About 3 hrs to fix

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

          enum Target {
            All = 'all',
            Body = 'body',
            Comment = 'comments',
            ContentType = 'content_type',
          Severity: Major
          Found in src/ts/interfaces.ts and 1 other location - About 3 hrs to fix
          src/ts/interfaces.ts on lines 91..114

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

          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

          enum Model {
            Apikey = 'apikeys',
            Comment = 'comments',
            Config = 'config',
            FavTag = 'favtags',
          Severity: Major
          Found in src/ts/interfaces.ts and 1 other location - About 3 hrs to fix
          src/ts/interfaces.ts on lines 124..147

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

          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 show.ts has 321 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          /**
           * @author Nicolas CARPi <nico-git@deltablot.email>
           * @copyright 2012 Nicolas CARPi
           * @see https://www.elabftw.net Official website
           * @license AGPL-3.0
          Severity: Minor
          Found in src/ts/show.ts - About 3 hrs to fix

            File plugin.js has 318 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            class AutoComplete {
              editor;
              options = {};
              query = '';
              hasFocus = true;
            Severity: Minor
            Found in src/js/tinymce-plugins/mention/plugin.js - About 3 hrs to fix

              File EntitySqlBuilder.php has 315 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/classes/EntitySqlBuilder.php - About 3 hrs to fix

                Users has 29 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class Users implements RestInterface
                {
                    public bool $needValidation = false;
                
                    public array $userData = array();
                Severity: Minor
                Found in src/models/Users.php - About 3 hrs to fix

                  QueryBuilderVisitor has 29 functions (exceeds 20 allowed). Consider refactoring.
                  Open

                  class QueryBuilderVisitor implements Visitor
                  {
                      public function buildWhere(Visitable $parsedQuery, VisitorParameters $parameters): WhereCollector
                      {
                          return $parsedQuery->accept($this, $parameters);
                  Severity: Minor
                  Found in src/services/advancedSearchQuery/visitors/QueryBuilderVisitor.php - About 3 hrs to fix

                    Method createOne has 84 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function createOne(
                            string $email,
                            array $teams,
                            string $firstname = '',
                            string $lastname = '',
                    Severity: Major
                    Found in src/models/Users.php - About 3 hrs to fix

                      Function edit has 83 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        edit(): Promise<void> {
                          return this.read().then(json => {
                            this.editor.refresh(json as ValidMetadata);
                            // do nothing more if there is no extra_fields in our json
                            if (!Object.prototype.hasOwnProperty.call(json, 'extra_fields')) {
                      Severity: Major
                      Found in src/ts/Metadata.class.ts - About 3 hrs to fix

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

                            } else if (el.matches('[data-action="destroy-template"]')) {
                              if (confirm(i18next.t('generic-delete-warning'))) {
                                TemplateC.destroy(parseInt(el.dataset.id))
                                  .then(() => window.location.replace('team.php?tab=3'))
                                  .catch((e) => notif({'res': false, 'msg': e.message}));
                        Severity: Major
                        Found in src/ts/team.ts and 1 other location - About 3 hrs to fix
                        src/ts/ucp.ts on lines 77..148

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

                        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

                            } else if (el.matches('[data-action="destroy-template"]')) {
                              if (confirm(i18next.t('generic-delete-warning'))) {
                                EntityC.destroy(parseInt(el.dataset.id))
                                  .then(() => window.location.replace('ucp.php?tab=3'))
                                  .catch((e) => notif({'res': false, 'msg': e.message}));
                        Severity: Major
                        Found in src/ts/ucp.ts and 1 other location - About 3 hrs to fix
                        src/ts/team.ts on lines 358..364

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

                        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

                        AutoComplete has 27 functions (exceeds 20 allowed). Consider refactoring.
                        Open

                        class AutoComplete {
                          editor;
                          options = {};
                          query = '';
                          hasFocus = true;
                        Severity: Minor
                        Found in src/js/tinymce-plugins/mention/plugin.js - About 3 hrs to fix

                          Method notif has 78 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public static function notif(array $notif): string
                              {
                                  $relativeMoment = '<br><span class="relative-moment" title="%s"></span>';
                          
                                  return match (Notifications::from($notif['category'])) {
                          Severity: Major
                          Found in src/services/Transform.php - About 3 hrs to fix

                            Method formatMetadata has 77 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public static function formatMetadata(string $json): string
                                {
                                    $final = '';
                                    $Metadata = new Metadata($json);
                                    $extraFields = $Metadata->getExtraFields();
                            Severity: Major
                            Found in src/classes/TwigFilters.php - About 3 hrs to fix
                              Severity
                              Category
                              Status
                              Source
                              Language