BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

Method handle has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function handle(Connection $db): int
    {
        $oldUrl = str_replace("'", '', $this->argument('oldUrl'));
        $newUrl = str_replace("'", '', $this->argument('newUrl'));

Severity: Minor
Found in app/Console/Commands/UpdateUrlCommand.php - About 1 hr to fix

    Function register has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function register(editor) {
        editor.addCommand('drawio', () => {
            const selectedNode = editor.selection.getNode();
            showDrawingEditor(editor, isDrawing(selectedNode) ? selectedNode : null);
        });
    Severity: Minor
    Found in resources/js/wysiwyg/plugin-drawio.js - About 1 hr to fix

      Function setup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          setup() {
              // Options
              this.draftsEnabled = this.$opts.draftsEnabled === 'true';
              this.editorType = this.$opts.editorType;
              this.pageId = Number(this.$opts.pageId);
      Severity: Minor
      Found in resources/js/components/page-editor.js - About 1 hr to fix

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

        async function updateContent(pngData) {
            const loadingImage = window.baseUrl('/loading.gif');
        
            const handleUploadError = error => {
                if (error.status === 413) {
        Severity: Minor
        Found in resources/js/wysiwyg/plugin-drawio.js - About 1 hr to fix

          Function processUsers has a Cognitive Complexity of 13 (exceeds 5 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

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

              public function run()
              {
                  // Create an editor user
                  $editorUser = User::factory()->create();
                  $editorRole = Role::getRole('editor');
          Severity: Minor
          Found in database/seeders/DummyContentSeeder.php - About 1 hr to fix

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

                open() {
                    this.toggle.classList.add('open');
                    this.toggle.setAttribute('aria-expanded', 'true');
                    slideDown(this.list, 180);
                    this.isOpen = true;
            Severity: Major
            Found in resources/js/components/chapter-contents.js and 1 other location - About 1 hr to fix
            resources/js/components/chapter-contents.js on lines 21..26

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

            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

                close() {
                    this.toggle.classList.remove('open');
                    this.toggle.setAttribute('aria-expanded', 'false');
                    slideUp(this.list, 180);
                    this.isOpen = false;
            Severity: Major
            Found in resources/js/components/chapter-contents.js and 1 other location - About 1 hr to fix
            resources/js/components/chapter-contents.js on lines 14..19

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

            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

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

                    window.tinymce.init(config).then(editors => {
                        this.wysiwygEditor = editors[0];
                        setTimeout(() => this.wysiwygEditor.focus(), 50);
                    });
            Severity: Major
            Found in resources/js/components/page-comment.js and 1 other location - About 1 hr to fix
            resources/js/components/page-comments.js on lines 135..138

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

            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

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

                    window.tinymce.init(config).then(editors => {
                        this.wysiwygEditor = editors[0];
                        setTimeout(() => this.wysiwygEditor.focus(), 50);
                    });
            Severity: Major
            Found in resources/js/components/page-comments.js and 1 other location - About 1 hr to fix
            resources/js/components/page-comment.js on lines 74..77

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

            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

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

            export function handleTableCellRangeEvents(editor) {
                /** @var {HTMLTableCellElement[]} * */
                let selectedCells = [];
            
                editor.on('TableSelectionChange', event => {
            Severity: Minor
            Found in resources/js/wysiwyg/fixes.js - About 1 hr to fix

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

              export function handleEmbedAlignmentChanges(editor) {
                  function updateClassesForPreview(previewElem) {
                      const mediaTarget = previewElem.querySelector('iframe, video');
                      if (!mediaTarget) {
                          return;
              Severity: Minor
              Found in resources/js/wysiwyg/fixes.js - About 1 hr to fix

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

                    protected function isSortChangePermissible(BookSortMapItem $sortMapItem, BookChild $model, ?Entity $currentParent, ?Entity $newBook, ?Entity $newChapter): bool
                    {
                        // Stop if we can't see the current parent or new book.
                        if (!$currentParent || !$newBook) {
                            return false;
                Severity: Minor
                Found in app/Entities/Tools/BookContents.php - About 1 hr to fix

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

                          editor.parser.addNodeFilter('li', nodes => {
                              for (const node of nodes) {
                                  if (node.attributes.map.class === 'task-list-item') {
                                      parseTaskListNode(node);
                                  }
                  Severity: Major
                  Found in resources/js/wysiwyg/plugins-tasklist.js and 1 other location - About 1 hr to fix
                  resources/js/wysiwyg/plugins-tasklist.js on lines 149..155

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

                  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.serializer.addNodeFilter('li', nodes => {
                              for (const node of nodes) {
                                  if (node.attributes.map.class === 'task-list-item') {
                                      serializeTaskListNode(node);
                                  }
                  Severity: Major
                  Found in resources/js/wysiwyg/plugins-tasklist.js and 1 other location - About 1 hr to fix
                  resources/js/wysiwyg/plugins-tasklist.js on lines 142..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 65.

                  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

                      book_end: {
                          active(elem, parent) {
                              return parent || (parent === null && elem.nextElementSibling);
                          },
                          run(elem, parent, book) {
                  Severity: Major
                  Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
                  resources/js/components/book-sort.js on lines 121..128

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

                  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

                      book_start: {
                          active(elem, parent) {
                              return parent || (parent === null && elem.previousElementSibling);
                          },
                          run(elem, parent, book) {
                  Severity: Major
                  Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
                  resources/js/components/book-sort.js on lines 113..120

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

                  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

                  Function request has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  async function request(url, options = {}) {
                      let requestUrl = url;
                  
                      if (!requestUrl.startsWith('http')) {
                          requestUrl = window.baseUrl(requestUrl);
                  Severity: Minor
                  Found in resources/js/services/http.js - About 1 hr to fix

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

                    export async function init(editor) {
                        const Code = await window.importVersioned('code');
                    
                        /**
                         * @param {ViewUpdate} v
                    Severity: Minor
                    Found in resources/js/markdown/codemirror.js - 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 formatSingle has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function formatSingle(Entity $entity): array
                        {
                            $result = [];
                            $values = (clone $entity)->toArray();
                    
                    
                    Severity: Minor
                    Found in app/Api/ApiEntityListFormatter.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

                    Severity
                    Category
                    Status
                    Source
                    Language