BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

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

    protected function createTree(array $comments): array
    {
        $byId = [];
        foreach ($comments as $comment) {
            $byId[$comment->local_id] = $comment;
Severity: Minor
Found in app/Activity/Tools/CommentTree.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

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

    public function update(User $user, array $data, bool $manageUsersAllowed): User
    {
        if (!empty($data['name'])) {
            $user->name = $data['name'];
            $user->refreshSlug();
Severity: Minor
Found in app/Users/UserRepo.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

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

    setActiveTab(tabName, openToolbox = false) {
        // Set button visibility
        for (const button of this.buttons) {
            button.classList.remove('active');
            const bName = button.dataset.tab;
Severity: Minor
Found in resources/js/components/editor-toolbox.js - 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

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

    protected function getPermissionMapByTypeIdAndRoleForAllInvolved(): array
    {
        if (isset($this->permissionMapCache)) {
            return $this->permissionMapCache;
        }
Severity: Minor
Found in app/Permissions/MassEntityPermissionEvaluator.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

Method saveNewFromUpload has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        UploadedFile $uploadedFile,
        string $type,
        int $uploadedTo = 0,
        int $resizeWidth = null,
        int $resizeHeight = null,
Severity: Minor
Found in app/Uploads/ImageService.php - About 45 mins to fix

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

        public function imageUrlToBase64(string $url): ?string
        {
            $storagePath = $this->storage->urlToPath($url);
            if (empty($url) || is_null($storagePath)) {
                return null;
    Severity: Minor
    Found in app/Uploads/ImageService.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

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

        show(event = null) {
            this.hideAll();
    
            this.menu.style.display = 'block';
            this.menu.classList.add('anim', 'menuIn');
    Severity: Minor
    Found in resources/js/components/dropdown.js - 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

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

    export function elem(tagName, attrs = {}, children = []) {
        const el = document.createElement(tagName);
    
        for (const [key, val] of Object.entries(attrs)) {
            if (val === null) {
    Severity: Minor
    Found in resources/js/services/dom.js - 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

    Method getEntityFiltered has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            string $type,
            ?string $filterType,
            int $page,
            int $pageSize,
            int $uploadedTo,
    Severity: Minor
    Found in app/Uploads/ImageRepo.php - About 45 mins to fix

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

      function drawReceive(event) {
          if (!event.data || event.data.length < 1) return;
          if (event.origin !== lastApprovedOrigin) return;
      
          const message = JSON.parse(event.data);
      Severity: Minor
      Found in resources/js/services/drawio.js - 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

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

          protected function processAccessTokenCallback(OidcAccessToken $accessToken, OidcProviderSettings $settings): User
          {
              $idTokenText = $accessToken->getIdToken();
              $idToken = new OidcIdToken(
                  $idTokenText,
      Severity: Minor
      Found in app/Access/Oidc/OidcService.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

      Method saveNew has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public function saveNew(UploadedFile $uploadFile, string $type, int $uploadedTo = 0, int $resizeWidth = null, int $resizeHeight = null, bool $keepRatio = true): Image
      Severity: Minor
      Found in app/Uploads/ImageRepo.php - About 45 mins to fix

        Method getPaginatedByType has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                string $type,
                int $page = 0,
                int $pageSize = 24,
                int $uploadedTo = null,
                string $search = null,
        Severity: Minor
        Found in app/Uploads/ImageRepo.php - About 45 mins to fix

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

          function sortUrl(string $path, array $data, array $overrideData = []): string
          {
              $queryStringSections = [];
              $queryData = array_merge($data, $overrideData);
          
          
          Severity: Minor
          Found in app/App/helpers.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

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

              protected function loadSettingsFromIssuerDiscovery(ClientInterface $httpClient): array
              {
                  $issuerUrl = rtrim($this->issuer, '/') . '/.well-known/openid-configuration';
                  $request = new Request('GET', $issuerUrl);
                  $response = $httpClient->sendRequest($request);
          Severity: Minor
          Found in app/Access/Oidc/OidcProviderSettings.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

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

              protected function getProviderSettings(): OidcProviderSettings
              {
                  $config = $this->config();
                  $settings = new OidcProviderSettings([
                      'issuer'                => $config['issuer'],
          Severity: Minor
          Found in app/Access/Oidc/OidcService.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

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

              public function searchEntities(SearchOptions $searchOpts, string $entityType = 'all', int $page = 1, int $count = 20): array
              {
                  $entityTypes = array_keys($this->entityProvider->all());
                  $entityTypesToSearch = $entityTypes;
          
          
          Severity: Minor
          Found in app/Search/SearchRunner.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

          Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  protected BaseRepo $baseRepo,
                  protected RevisionRepo $revisionRepo,
                  protected EntityQueries $entityQueries,
                  protected ReferenceStore $referenceStore,
                  protected ReferenceUpdater $referenceUpdater,
          Severity: Minor
          Found in app/Entities/Repos/PageRepo.php - About 45 mins to fix

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

                editor.ui.registry.addButton('customhr', {
                    icon: 'horizontal-rule',
                    tooltip: 'Insert horizontal line',
                    onAction() {
                        editor.execCommand('InsertHorizontalRule');
            Severity: Major
            Found in resources/js/wysiwyg/plugins-customhr.js and 3 other locations - About 45 mins to fix
            resources/js/wysiwyg/plugin-codeeditor.js on lines 161..167
            resources/js/wysiwyg/plugin-codeeditor.js on lines 169..175
            resources/js/wysiwyg/plugins-details.js on lines 180..186

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

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

                editor.ui.registry.addButton('codeeditor', {
                    tooltip: 'Insert code block',
                    icon: 'codeblock',
                    onAction() {
                        editor.execCommand('codeeditor');
            Severity: Major
            Found in resources/js/wysiwyg/plugin-codeeditor.js and 3 other locations - About 45 mins to fix
            resources/js/wysiwyg/plugin-codeeditor.js on lines 169..175
            resources/js/wysiwyg/plugins-customhr.js on lines 12..18
            resources/js/wysiwyg/plugins-details.js on lines 180..186

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

            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