BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

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

    protected function getConnection()
    {
        if ($this->ldapConnection !== null) {
            return $this->ldapConnection;
        }
Severity: Minor
Found in app/Access/LdapService.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

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

    protected function ensureDeletable(Entity $entity): void
    {
        $customHomeId = intval(explode(':', setting('app-homepage', '0:'))[0]);
        $customHomeActive = setting('app-homepage-type') === 'page';
        $removeCustomHome = false;
Severity: Minor
Found in app/Entities/Tools/TrashCan.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

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

    public function parse(): int
    {
        $nodesAdded = 0;
        $tags = $this->locateAndIsolateIncludeTags();

Severity: Minor
Found in app/Entities/Tools/PageIncludeParser.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

Function buildForInput has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function buildForInput(options) {
    // Set language
    window.tinymce.addI18n(options.language, options.translationMap);

    // BookStack Version
Severity: Minor
Found in resources/js/wysiwyg/config.js - About 1 hr to fix

    Method getConnection has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function getConnection()
        {
            if ($this->ldapConnection !== null) {
                return $this->ldapConnection;
            }
    Severity: Minor
    Found in app/Access/LdapService.php - About 1 hr to fix

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

          editor.ui.registry.addContextToolbar('codeeditor', {
              predicate(node) {
                  return node.nodeName.toLowerCase() === 'code-block';
              },
              items: 'editcodeeditor',
      Severity: Major
      Found in resources/js/wysiwyg/plugin-codeeditor.js and 1 other location - About 1 hr to fix
      resources/js/wysiwyg/plugins-details.js on lines 245..252

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

      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

              editor.ui.registry.addMenuItem('tableclearformatting', {
                  icon: 'tableclearformatting',
                  text: 'Clear table formatting',
                  onSetup: exitingButtons.tableprops.onSetup,
                  onAction() {
      Severity: Major
      Found in resources/js/wysiwyg/plugins-table-additions.js and 1 other location - About 1 hr to fix
      resources/js/wysiwyg/plugins-table-additions.js on lines 72..79

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

      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

              editor.ui.registry.addMenuItem('tableclearsizes', {
                  icon: 'resize',
                  text: 'Resize to contents',
                  onSetup: exitingButtons.tableprops.onSetup,
                  onAction() {
      Severity: Major
      Found in resources/js/wysiwyg/plugins-table-additions.js and 1 other location - About 1 hr to fix
      resources/js/wysiwyg/plugins-table-additions.js on lines 63..70

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

      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

          editor.ui.registry.addContextToolbar('details', {
              predicate(node) {
                  return node.nodeName.toLowerCase() === 'details';
              },
              items: 'editdetials toggledetails removedetails',
      Severity: Major
      Found in resources/js/wysiwyg/plugins-details.js and 1 other location - About 1 hr to fix
      resources/js/wysiwyg/plugin-codeeditor.js on lines 249..256

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

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

          private function processUsers(array $users, UserAvatars $userAvatar): int
          {
              $dryRun = !$this->option('force');
              $this->info(count($users) . " user(s) found to update avatars for.");
      
      
      Severity: Minor
      Found in app/Console/Commands/RefreshAvatarCommand.php - About 1 hr to fix

        Function createUploadFromFile has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            createUploadFromFile(file) {
                const {
                    dom, status, progress, dismiss,
                } = this.createDomForFile(file);
                this.statusArea.append(dom);
        Severity: Minor
        Found in resources/js/components/dropzone.js - About 1 hr to fix

          Function setupDropTargetHandlers has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              setupDropTargetHandlers() {
                  let depth = 0;
          
                  const reset = () => {
                      this.hideOverlay();
          Severity: Minor
          Found in resources/js/components/dropzone.js - About 1 hr to fix

            Function setupListeners has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                setupListeners() {
                    this.elem.addEventListener('click', this.onClick.bind(this));
            
                    let lastSearch = 0;
                    this.searchInput.addEventListener('input', () => {
            Severity: Minor
            Found in resources/js/components/entity-selector.js - About 1 hr to fix

              Method decode has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected static function decode(string $searchString): array
                  {
                      $terms = [
                          'searches' => [],
                          'exacts'   => [],
              Severity: Minor
              Found in app/Search/SearchOptions.php - About 1 hr to fix

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

                    protected function filterOwnedBy(EloquentBuilder $query, Entity $model, $input)
                    {
                        $userSlug = $input === 'me' ? user()->slug : trim($input);
                        $user = User::query()->where('slug', '=', $userSlug)->first(['id']);
                        if ($user) {
                Severity: Major
                Found in app/Search/SearchRunner.php and 2 other locations - About 1 hr to fix
                app/Search/SearchRunner.php on lines 401..408
                app/Search/SearchRunner.php on lines 410..417

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

                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

                    public function bookToContainedHtml(Book $book): string
                    {
                        $bookTree = (new BookContents($book))->getTree(false, true);
                        $html = view('exports.book', [
                            'book'         => $book,
                Severity: Major
                Found in app/Entities/Tools/ExportFormatter.php and 1 other location - About 1 hr to fix
                app/Entities/Tools/ExportFormatter.php on lines 131..143

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

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

                    protected function filterUpdatedBy(EloquentBuilder $query, Entity $model, $input)
                    {
                        $userSlug = $input === 'me' ? user()->slug : trim($input);
                        $user = User::query()->where('slug', '=', $userSlug)->first(['id']);
                        if ($user) {
                Severity: Major
                Found in app/Search/SearchRunner.php and 2 other locations - About 1 hr to fix
                app/Search/SearchRunner.php on lines 401..408
                app/Search/SearchRunner.php on lines 419..426

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

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

                    protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input)
                    {
                        $userSlug = $input === 'me' ? user()->slug : trim($input);
                        $user = User::query()->where('slug', '=', $userSlug)->first(['id']);
                        if ($user) {
                Severity: Major
                Found in app/Search/SearchRunner.php and 2 other locations - About 1 hr to fix
                app/Search/SearchRunner.php on lines 410..417
                app/Search/SearchRunner.php on lines 419..426

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

                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

                    public function bookToPdf(Book $book): string
                    {
                        $bookTree = (new BookContents($book))->getTree(false, true);
                        $html = view('exports.book', [
                            'book'         => $book,
                Severity: Major
                Found in app/Entities/Tools/ExportFormatter.php and 1 other location - About 1 hr to fix
                app/Entities/Tools/ExportFormatter.php on lines 71..83

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

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

                    protected function getConverterEnvironment(): Environment
                    {
                        $environment = new Environment([
                            'header_style'            => 'atx', // Set to 'atx' to output H1 and H2 headers as # Header1 and ## Header2
                            'suppress_errors'         => true, // Set to false to show warnings when loading malformed HTML
                Severity: Minor
                Found in app/Entities/Tools/Markdown/HtmlToMarkdown.php - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language