voyager-admin/voyager

View on GitHub

Showing 125 of 127 total issues

Function stored has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function stored(mixed $model, mixed $value): void
    {
        $relationship = $this->getRelationship();
        $method = $model->{$relationship['method']}();

Severity: Minor
Found in src/Formfields/Relationship.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 orderQuery has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function orderQuery(Layout $layout, mixed $direction, mixed $order, mixed $query, string $locale, array &$warnings): mixed
    {
        if (!empty($direction) && !empty($order)) {
            $formfield = $layout->getFormfieldByColumn($order);
            if ($formfield && $formfield->column->type == 'column') {
Severity: Minor
Found in src/Traits/Bread/Browsable.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 getThumbnailOptions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getThumbnailOptions(Request $request): DynamicInput
    {
        $method = $request->input('method', 'fit');

        $select = (new DynamicInput())
Severity: Minor
Found in src/Http/Controllers/VoyagerController.php - About 1 hr to fix

    Method getBreads has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getBreads()
        {
            if (!$this->breads) {
                VoyagerFacade::ensureDirectoryExists($this->path);
                $this->breads = collect(File::files($this->path))->transform(function ($bread) {
    Severity: Minor
    Found in src/Manager/Breads.php - About 1 hr to fix

      Method store has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function store(Request $request): \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
          {
              // Push a fake column object to settings
              $settings = collect($request->get('settings', []))->transform(function ($setting) {
                  $setting = (object) $setting;
      Severity: Minor
      Found in src/Http/Controllers/SettingsController.php - About 1 hr to fix

        Method globalSearch has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function globalSearch(Request $request): ?array
            {
                $q = $request->get('query');
                $results = [];
                $this->breadmanager->getBreads()->each(function ($bread) use ($q, &$results) {
        Severity: Minor
        Found in src/Http/Controllers/VoyagerController.php - About 1 hr to fix

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

                  $delete_action = (new Action('voyager::generic.delete', 'trash', null, 'red'))
                  ->route(function ($bread) {
                      return 'voyager.'.$bread->slug.'.delete';
                  })
                  ->method('delete')
          Severity: Major
          Found in src/VoyagerServiceProvider.php and 1 other location - About 1 hr to fix
          src/VoyagerServiceProvider.php on lines 242..251

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

          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

                  $restore_action = (new Action('voyager::generic.restore', 'trash', null, 'yellow'))
                  ->route(function ($bread) {
                      return 'voyager.'.$bread->slug.'.restore';
                  })
                  ->method('patch')
          Severity: Major
          Found in src/VoyagerServiceProvider.php and 1 other location - About 1 hr to fix
          src/VoyagerServiceProvider.php on lines 231..240

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

          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

                  } else if ((this._has_select || this._prompt) && this._buttons.length == 0) {
                      this.addButton({
                          key: true,
                          value: 'voyager::generic.ok',
                          color: 'green',
          Severity: Major
          Found in resources/assets/js/notify.ts and 1 other location - About 1 hr to fix
          resources/assets/js/notify.ts on lines 144..164

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

          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

                  if (this._confirm && this._buttons.length == 0) {
                      this.addButton({
                          key: true,
                          value: 'voyager::generic.yes',
                          color: 'green',
          Severity: Major
          Found in resources/assets/js/notify.ts and 1 other location - About 1 hr to fix
          resources/assets/js/notify.ts on lines 154..164

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

          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

                  $restore_action = (new Action('voyager::bread.restore_type', 'trash', null, 'yellow'))
                  ->route(function ($bread) {
                      return 'voyager.'.$bread->slug.'.restore';
                  })
                  ->method('patch')
          Severity: Minor
          Found in src/VoyagerServiceProvider.php and 1 other location - About 55 mins to fix
          src/VoyagerServiceProvider.php on lines 277..286

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

          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

                  $delete_action = (new Action('voyager::bread.delete_type', 'trash', null, 'red'))
                  ->route(function ($bread) {
                      return 'voyager.'.$bread->slug.'.delete';
                  })
                  ->method('delete')
          Severity: Minor
          Found in src/VoyagerServiceProvider.php and 1 other location - About 55 mins to fix
          src/VoyagerServiceProvider.php on lines 288..297

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

          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 addNumber has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function addNumber(?string $key = null, string|array|null $title = null, string|array|null $placeholder = null, ?int $value = null, ?int $min = null, ?int $max = null): self
          Severity: Minor
          Found in src/Classes/DynamicInput.php - About 45 mins to fix

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

                mounted(el: TooltipElement, binding: any) {
                    let placement = 'bottom';
                    if (placements.includes(binding.arg)) {
                        placement = binding.arg;
                    } else if (binding.arg) {
            Severity: Minor
            Found in resources/assets/js/directives/tooltip.ts - 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 download has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function download(Request $request)
                {
                    $files = $request->get('files', []);
                    if (count($files) == 1 && $files[0]['file']['type'] !== 'directory') {
                        return Storage::disk($this->disk)->get($files[0]['file']['relative_path'].$files[0]['file']['name']);
            Severity: Minor
            Found in src/Http/Controllers/MediaController.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 addMultipleChoiceInput has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                private function addMultipleChoiceInput(string $type, ?string $key = null, string|array|null $title = null, ?array $options = [], ?bool $multiple = false, mixed $value = null): void
            Severity: Minor
            Found in src/Classes/DynamicInput.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                              if (!empty($setting->key) && !empty($setting->info)) {
                                                  if (empty($setting->group)) {
                                                      $this->line('New setting: "'.$setting->key.'": '.$setting->info);
                                                  } else {
                                                      $this->line('New setting: "'.$setting->group.'.'.$setting->key.'": '.$setting->info);
              Severity: Major
              Found in src/Commands/InstallCommand.php - About 45 mins to fix

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

                    public function translate(mixed $value, ?string $locale = null, ?string $fallback = null): ?string
                    {
                        if ($locale == null) {
                            $locale = app()->getLocale();
                        }
                Severity: Minor
                Found in src/Traits/Facade/Localization.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 orderQuery has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function orderQuery(Layout $layout, mixed $direction, mixed $order, mixed $query, string $locale, array &$warnings): mixed
                Severity: Minor
                Found in src/Traits/Bread/Browsable.php - About 45 mins to fix

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

                      public function __construct(mixed $input)
                      {
                          foreach ($input as $key => $value) {
                              if ($key == 'meta') {
                                  foreach ($value as $meta_key => $meta_value) {
                  Severity: Minor
                  Found in src/Classes/Media.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

                  Severity
                  Category
                  Status
                  Source
                  Language