voyager-admin/voyager

View on GitHub

Showing 105 of 127 total issues

File Plugins.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Voyager\Admin\Manager;

use Composer\InstalledVersions;
Severity: Minor
Found in src/Manager/Plugins.php - About 2 hrs to fix

    Method transformResults has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function transformResults(Layout $layout, bool $translatable, mixed $query, ?string $global, mixed $filters): mixed
        {
            return $query->transform(function ($item) use ($translatable, $layout) {
                $item->primary_key = $item->getKey();
                if ($translatable) {
    Severity: Major
    Found in src/Traits/Bread/Browsable.php - About 2 hrs to fix

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

          public function data(Request $request): array
          {
              $start = microtime(true);
              $bread = $this->getBread($request);
              $forcedLayout = $request->get('forcedLayout', null);
      Severity: Minor
      Found in src/Http/Controllers/BreadController.php - About 1 hr to fix

        Function set has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function set(string $key, mixed $value, ?string $locale = null, bool $save = true): void
            {
                $this->load();
                $setting = $this->getSettingsByKey($key);
        
        
        Severity: Minor
        Found in src/Manager/Settings.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 createVoyager has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        window.createVoyager = (data: VoyagerData, el = 'voyager') => {
            createInertiaApp({
                resolve: name => {
                    // This is necessary so webpack doesn't load ALL components (by using require(`@components/${name}`))
                    let component = require(`@components/Generic.vue`).default;
        Severity: Minor
        Found in resources/assets/js/voyager.ts - 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 boot has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function boot(Router $router): void
            {
                $router->aliasMiddleware('voyager.admin', VoyagerAdminMiddleware::class);
        
                $this->registerResources();
        Severity: Minor
        Found in src/VoyagerServiceProvider.php - About 1 hr to fix

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

          window.createVoyager = (data: VoyagerData, el = 'voyager') => {
              createInertiaApp({
                  resolve: name => {
                      // This is necessary so webpack doesn't load ALL components (by using require(`@components/${name}`))
                      let component = require(`@components/Generic.vue`).default;
          Severity: Minor
          Found in resources/assets/js/voyager.ts - About 1 hr to fix

            Function update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public function update(Request $request, $table)
                {
                    $bread = $request->bread;
                    $exists = $this->breadmanager->getBread($table);
            
            
            Severity: Minor
            Found in src/Http/Controllers/BreadBuilderController.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 registerActions has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function registerActions()
                {
                    $breadmanager = $this->breadmanager;
            
                    $read_action = (new Action('voyager::generic.read', 'book-open', null, 'accent'))
            Severity: Minor
            Found in src/VoyagerServiceProvider.php - About 1 hr to fix

              Method update has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function update(Request $request, $table)
                  {
                      $bread = $request->bread;
                      $exists = $this->breadmanager->getBread($table);
              
              
              Severity: Minor
              Found in src/Http/Controllers/BreadBuilderController.php - About 1 hr to fix

                Method addPlugin has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function addPlugin(string|GenericPlugin $plugin): void
                    {
                        $start = round(microtime(true) * 1000);
                        if (!$this->enabled_plugins) {
                            $this->loadEnabledPlugins();
                Severity: Minor
                Found in src/Manager/Plugins.php - About 1 hr to fix

                  Method getThumbnailDefinitions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function getThumbnailDefinitions()
                      {
                          $thumbs = collect(VoyagerFacade::setting('thumbnails'));
                  
                          return $thumbs->map(function ($thumb, $name) {
                  Severity: Minor
                  Found in src/Http/Controllers/MediaController.php - About 1 hr to fix

                    Method getViewData has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getViewData(): array
                        {
                            // This data gets directly written to the store and can be accessed through `this.$store` everywhere
                            $viewData = [
                                'localization'          => $this->getLocalization(),
                    Severity: Minor
                    Found in src/Voyager.php - About 1 hr to fix

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

                          public function applyCustomScope(Bread $bread, Layout $layout, mixed $filter, mixed $query, array &$warnings): mixed
                          {
                              if (!is_null($filter) && is_array($filter)) {
                                  // Validate filter exists in layout
                                  if (collect($layout->options->filters)->where('column', $filter['column'])->where('operator', $filter['operator'])->where('value', $filter['value'])->count() > 0) {
                      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

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

                          protected function processUploadedFile($file, $path)
                          {
                              $name = '';
                              $count = 0;
                              $thumbnails = 0;
                      Severity: Minor
                      Found in src/Http/Controllers/MediaController.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 edit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function edit(Request $request, mixed $id): InertiaResponse
                          {
                              $bread = $this->getBread($request, true);
                              $layout = $this->breadmanager->getLayoutForAction($bread, 'edit');
                      
                      
                      Severity: Minor
                      Found in src/Http/Controllers/BreadController.php - About 1 hr to fix

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

                            mounted(el, binding) {
                                el.addEventListener('click', (e) => {
                                    let content = document.getElementById('content');
                                    let element = document.getElementById('top');
                                    if (binding.value !== '') {
                        Severity: Minor
                        Found in resources/assets/js/directives/scroll-to.js - About 1 hr to fix

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

                              private function setSettings(SettingManager $settingsmanager): void
                              {
                                  $path = realpath(__DIR__.'/../../resources/presets/settings.json');
                                  if ($path !== false) {
                                      $content = file_get_contents($path);
                          Severity: Minor
                          Found in src/Commands/InstallCommand.php - About 1 hr to fix

                            Method updateStoreData has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function updateStoreData(Collection $formfields, mixed $data, mixed $model, bool $update = true): mixed
                                {
                                    $formfields->each(function ($formfield) use ($data, &$model, $update) {
                                        $value = $data[$formfield->column->column] ?? '';
                            
                            
                            Severity: Minor
                            Found in src/Traits/Bread/Saveable.php - About 1 hr to fix

                              Method validateData has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  protected function validateData(Collection $formfields, array|Collection $data, bool $all_locales = false): array
                                  {
                                      $errors = [];
                              
                                      $formfields->each(function ($formfield) use (&$errors, $data, $all_locales) {
                              Severity: Minor
                              Found in src/Http/Controllers/Controller.php - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language