BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

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

        run(elem, parent) {
            const nextChapter = this.getNextChapter(elem, parent);
            nextChapter.querySelector('ul').prepend(elem);
        },
Severity: Minor
Found in resources/js/components/book-sort.js and 1 other location - About 30 mins to fix
resources/js/components/book-sort.js on lines 102..105

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

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

        run(elem, parent) {
            const prevChapter = this.getPrevChapter(elem, parent);
            prevChapter.querySelector('ul').append(elem);
        },
Severity: Minor
Found in resources/js/components/book-sort.js and 1 other location - About 30 mins to fix
resources/js/components/book-sort.js on lines 87..90

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

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

Avoid too many return statements within this method.
Open

            return '';
Severity: Major
Found in app/Entities/Tools/PageContent.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return $image->url;
    Severity: Major
    Found in app/Entities/Tools/PageContent.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return true;
      Severity: Major
      Found in app/Entities/Tools/BookContents.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return 0;
        Severity: Major
        Found in app/Entities/Tools/TrashCan.php - About 30 mins to fix

          Function updateLayout has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              updateLayout() {
                  let newLayout = 'tablet';
                  if (window.innerWidth <= 1000) newLayout = 'mobile';
                  if (window.innerWidth >= 1400) newLayout = 'desktop';
                  if (newLayout === this.lastLayoutType) return;
          Severity: Minor
          Found in resources/js/components/tri-layout.js - About 25 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 buildJointPermissionsForBooks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function buildJointPermissionsForBooks(EloquentCollection $books, array $roles, bool $deleteOld = false)
              {
                  $entities = clone $books;
          
                  /** @var Book $book */
          Severity: Minor
          Found in app/Permissions/JointPermissionBuilder.php - About 25 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 loadToLocalCache has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function loadToLocalCache(string $cacheCategory): void
              {
                  $query = Setting::query();
          
                  if ($cacheCategory === 'app') {
          Severity: Minor
          Found in app/Settings/SettingService.php - About 25 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 register has a Cognitive Complexity of 6 (exceeds 5 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 25 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 debounce has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function debounce(func, waitMs, immediate) {
              let timeout;
              return function debouncedWrapper(...args) {
                  const context = this;
                  const later = function debouncedTimeout() {
          Severity: Minor
          Found in resources/js/services/util.js - About 25 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 validateTokenStructure has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function validateTokenStructure(): void
              {
                  foreach (['header', 'payload'] as $prop) {
                      if (empty($this->$prop) || !is_array($this->$prop)) {
                          throw new OidcInvalidTokenException("Could not parse out a valid {$prop} within the provided token");
          Severity: Minor
          Found in app/Access/Oidc/OidcJwtWithClaims.php - About 25 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 parseTaskListNode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function parseTaskListNode(node) {
              // Force task list item class
              node.attr('class', 'task-list-item');
          
              // Copy checkbox status and remove checkbox within editor
          Severity: Minor
          Found in resources/js/wysiwyg/plugins-tasklist.js - About 25 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 configureTlsCaCerts has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function configureTlsCaCerts(string $caCertPath): void
              {
                  $errMessage = "Provided path [{$caCertPath}] for LDAP TLS CA certs could not be resolved to an existing location";
                  $path = realpath($caCertPath);
                  if ($path === false) {
          Severity: Minor
          Found in app/Access/LdapService.php - About 25 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 deleteRole has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function deleteRole(int $roleId, int $migrateRoleId = 0): void
              {
                  $role = $this->getRoleById($roleId);
          
                  // Prevent deleting admin role or default registration role.
          Severity: Minor
          Found in app/Permissions/PermissionsRepo.php - About 25 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 parseRequest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function parseRequest(Request $request): void
              {
                  $this->responseHeaders['Accept-Ranges'] = $request->isMethodSafe() ? 'bytes' : 'none';
          
                  $range = $this->getRangeFromRequest($request);
          Severity: Minor
          Found in app/Http/RangeSupportedStream.php - About 25 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 urlToPath has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function urlToPath(string $url): ?string
              {
                  $url = ltrim(trim($url), '/');
          
                  // Handle potential relative paths
          Severity: Minor
          Found in app/Uploads/ImageStorage.php - About 25 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 resizeToThumbnailUrl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function resizeToThumbnailUrl(
                  Image $image,
                  ?int $width,
                  ?int $height,
                  bool $keepRatio = false,
          Severity: Minor
          Found in app/Uploads/ImageResizer.php - About 25 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 render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function render($request, Throwable $e)
              {
                  if ($e instanceof FatalError && str_contains($e->getMessage(), 'bytes exhausted (tried to allocate') && $this->onOutOfMemory) {
                      $response = call_user_func($this->onOutOfMemory);
                      if ($response) {
          Severity: Minor
          Found in app/Exceptions/Handler.php - About 25 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 updateAppIcon has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function updateAppIcon(Request $request): void
              {
                  $sizes = [180, 128, 64, 32];
          
                  // Update icon image if set
          Severity: Minor
          Found in app/Settings/AppSettingsStore.php - About 25 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

          Severity
          Category
          Status
          Source
          Language