elabftw/elabftw

View on GitHub

Showing 221 of 356 total issues

Function handleEvent has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  handleEvent(event: Event): Promise<Response> | boolean {
    const el = event.target as HTMLFormElement;
    if (el.reportValidity() === false || el.hasAttribute('readonly')) {
      return false;
    }
Severity: Minor
Found in src/ts/Metadata.class.ts - 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

Function dbInsert has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    private function dbInsert($item): void
    {
        $Teams = new Teams($this->Users, $this->Users->userData['team']);
        // the body is updated after it has been fixed by the uploaded files with correct long_name
        $sql = 'INSERT INTO items(team, title, date, userid, category, status, canread, canwrite, canbook, elabid, metadata)
Severity: Minor
Found in src/Import/Zip.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 getResponse has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getResponse(): Response
    {
        try {
            $this->parseReq();

Severity: Minor
Found in src/controllers/Apiv2Controller.php - About 1 hr to fix

    Method getResponse has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getResponse(): Response
        {
            // this will disable output buffering and prevent issues when downloading big files
            if (ob_get_level()) {
                ob_end_clean();
    Severity: Minor
    Found in src/controllers/DownloadController.php - About 1 hr to fix

      Function init has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        init() {
      
          // CREATE EXPERIMENT or DATABASE item with shortcut
          // could work from anywhere but limit it to experiments|database pages
          key(this.create, () => {
      Severity: Minor
      Found in src/ts/KeyboardShortcuts.class.ts - About 1 hr to fix

        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 makeSortable has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public makeSortable(table: HTMLTableElement): void {
              // do not parse table twice, e.g. while loading entry bodies via toggle-body button
              if (table.dataset.sortingActivated === 'true') {
                return;
              }
          Severity: Minor
          Found in src/ts/TableSorting.class.ts - About 1 hr to fix

            Method getTeamWhereClause has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function getTeamWhereClause(EntityType $model): string
                {
                    // add team id filter for items + pub/org visibility filter
                    $sql = sprintf(
                        "%s AND (
            Severity: Minor
            Found in src/models/UnfinishedSteps.php - About 1 hr to fix

              Function imagesUploadHandler has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  const imagesUploadHandler = (blobInfo): Promise<string> => new Promise((resolve, reject) => {
                    // Edgecase for editing an image using tinymce ImageTools
                    // Check if it was selected. This is set by an event hook below
                    if (tinymceEditImage.selected === true) {
                      // Note: confirm will trigger the SelectionChange event hook below again
              Severity: Minor
              Found in src/ts/edit.ts - About 1 hr to fix

                Method getAllEmailAddressesRawData has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static function getAllEmailAddressesRawData(EmailTarget $target, ?int $targetId = null): array
                    {
                        $select = 'SELECT DISTINCT users.userid, email, CONCAT(firstname, " ", lastname) AS fullname FROM users';
                        switch($target) {
                            case EmailTarget::Team:
                Severity: Minor
                Found in src/services/Email.php - About 1 hr to fix

                  Method getHtml has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function getHtml(): string
                      {
                          $date = new DateTimeImmutable($this->Entity->entityData['date'] ?? date('Ymd'));
                  
                          $locked = $this->Entity->entityData['locked'];
                  Severity: Minor
                  Found in src/Make/MakePdf.php - About 1 hr to fix

                    Method view has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function view(): Response
                        {
                            // by default the id is taken from the URL
                            $id = $this->App->Request->query->getInt('id');
                            // but if we have an access_key we might be able to bypass read permissions
                    Severity: Minor
                    Found in src/controllers/AbstractEntityController.php - About 1 hr to fix

                      Function eventClick has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          eventClick: function(info): void {
                            if (!editable) {
                              // load page with selected item + correct start depending on current view
                              window.location.replace(`team.php?tab=1&item=${info.event.extendedProps.items_id}&start=${calendar.view.activeStart.toISOString()}`);
                              return;
                      Severity: Minor
                      Found in src/ts/team.ts - About 1 hr to fix

                        Method execute has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function execute(InputInterface $input, OutputInterface $output): int
                            {
                                $Db = Db::getConnection();
                        
                                $req = $Db->q('SELECT COUNT(*) AS cnt FROM information_schema.tables WHERE table_schema = "' . Config::fromEnv('DB_NAME') . '"');
                        Severity: Minor
                        Found in src/commands/Install.php - About 1 hr to fix

                          Method readGroupsWithUsersFromUser has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function readGroupsWithUsersFromUser(): array
                              {
                                  $sql = "SELECT team_groups_of_user.name,
                                          teams.name AS team_name,
                                          JSON_ARRAYAGG(JSON_OBJECT(
                          Severity: Minor
                          Found in src/models/TeamGroups.php - About 1 hr to fix

                            Function convertToFeaturedDNASequence has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                  const convertToFeaturedDNASequence = function(openVESequence): void {
                                    data.sequenceData = {
                                      features: [],
                                      sequence: openVESequence.sequence,
                                    };
                            Severity: Minor
                            Found in src/ts/ove.ts - About 1 hr to fix

                              Function handleEvent has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                handleEvent(event: Event): Promise<Response> | boolean {
                                  const el = event.target as HTMLFormElement;
                                  if (el.reportValidity() === false || el.hasAttribute('readonly')) {
                                    return false;
                                  }
                              Severity: Minor
                              Found in src/ts/Metadata.class.ts - About 1 hr to fix

                                Function factory has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  factory: require => {
                                    const { PosixFS } = require('@yarnpkg/fslib');
                                    const { ZipOpenFS } = require('@yarnpkg/libzip');
                                    const libzip = require('@yarnpkg/libzip').getLibzipSync();
                                    const { structUtils, Cache } = require('@yarnpkg/core');
                                Severity: Minor
                                Found in src/tools/yarn-plugin-tinymce.js - About 1 hr to fix

                                  Method readFromQuery has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public function readFromQuery(
                                          string $query,
                                          int $teamId = 0,
                                          bool $includeArchived = false,
                                          bool $onlyAdmins = false,
                                  Severity: Minor
                                  Found in src/models/Users.php - About 1 hr to fix

                                    Method patch has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        public function patch(Action $action, array $params): array
                                        {
                                            $this->canWriteOrExplode($action);
                                            match ($action) {
                                                Action::Add => (
                                    Severity: Minor
                                    Found in src/models/Users.php - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language