BookStackApp/BookStack

View on GitHub

Showing 205 of 290 total issues

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

    setupListeners() {
        // Filter tab click
        onSelect(this.filterTabs, e => {
            this.resetAll();
            this.filter = e.target.dataset.filter;
Severity: Major
Found in resources/js/components/image-manager.js - About 2 hrs to fix

    File PageContent.php has 261 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace BookStack\Entities\Tools;
    
    use BookStack\Entities\Models\Page;
    Severity: Minor
    Found in app/Entities/Tools/PageContent.php - About 2 hrs to fix

      Function isSortChangePermissible has a Cognitive Complexity of 17 (exceeds 5 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 2 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

      Function parsePlural has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          parsePlural(translation, count, replacements) {
              const splitText = translation.split('|');
              const exactCountRegex = /^{([0-9]+)}/;
              const rangeRegex = /^\[([0-9]+),([0-9*]+)]/;
              let result = null;
      Severity: Minor
      Found in resources/js/services/translations.js - About 2 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 TrashCan.php has 251 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace BookStack\Entities\Tools;
      
      use BookStack\Entities\EntityProvider;
      Severity: Minor
      Found in app/Entities/Tools/TrashCan.php - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

                if ($model instanceof Page) {
                    $parentPermission = ($currentParent instanceof Chapter) ? 'chapter-update' : 'book-update';
                    $hasCurrentParentPermission = userCan($parentPermission, $currentParent);
        
                    // This needs to check if there was an intended chapter location in the original sort map
        Severity: Critical
        Found in app/Entities/Tools/BookContents.php - About 2 hrs to fix

          Method processAccessTokenCallback has 49 lines of code (exceeds 25 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 1 hr to fix

            Function init has 49 lines of code (exceeds 25 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

              Method build has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function build(): array
                  {
                      // Note, while we attempt to use the user's preference here, the request to the manifest
                      // does not start a session, so we won't have current user context.
                      // This was attempted but removed since manifest calls could affect user session
              Severity: Minor
              Found in app/App/PwaManifestBuilder.php - About 1 hr to fix

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

                export function register(editor) {
                    // Headers
                    for (let i = 1; i < 5; i++) {
                        editor.shortcuts.add(`meta+${i}`, '', ['FormatBlock', false, `h${i + 1}`]);
                    }
                Severity: Minor
                Found in resources/js/wysiwyg/shortcuts.js - About 1 hr to fix

                  Method index has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function index(Request $request)
                      {
                          $this->checkPermission('settings-manage');
                          $this->checkPermission('users-manage');
                  
                  
                  Severity: Minor
                  Found in app/Activity/Controllers/AuditLogController.php - About 1 hr to fix

                    Function show has 45 lines of code (exceeds 25 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 1 hr to fix

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

                          protected function containHtml(string $htmlContent): string
                          {
                              $imageTagsOutput = [];
                              preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\").*?\>/i", $htmlContent, $imageTagsOutput);
                      
                      
                      Severity: Minor
                      Found in app/Entities/Tools/ExportFormatter.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 drop has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function drop(editor, options, event) {
                          const {dom} = editor;
                          const rng = window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(
                              event.clientX,
                              event.clientY,
                      Severity: Minor
                      Found in resources/js/wysiwyg/drop-paste-handling.js - About 1 hr to fix

                        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
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language