voyager-admin/voyager

View on GitHub

Showing 125 of 127 total issues

Function mounted has 57 lines of code (exceeds 25 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: Major
Found in resources/assets/js/directives/tooltip.ts - About 2 hrs to fix

    Method launchPlugins has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function launchPlugins(?bool $protected = null): void
        {
            $this->getAllPlugins()->each(function (GenericPlugin $plugin) use ($protected) {
                $start = round(microtime(true) * 1000);
                $plugin->stats = [
    Severity: Major
    Found in src/Manager/Plugins.php - About 2 hrs to fix

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

          public function handle(PluginManager $pluginmanager)
          {
              $name = $this->argument('plugin');
      
              if (!is_string($name)) {
      Severity: Major
      Found in src/Commands/PluginsCommand.php - About 2 hrs to fix

        Method getModelRelationships has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getModelRelationships(\ReflectionClass $reflection, Model $model, bool $resolve = false): Collection
            {
                $single = [
                    BelongsTo::class,
                    HasOne::class,
        Severity: Major
        Found in src/Manager/Breads.php - About 2 hrs to fix

          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

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

                Array.prototype.whereNot = function (prop, value = undefined) {
                    return this.filter(function (el) {
                        if (value !== undefined) {
                            return el[prop] !== value;
                        }
                Severity: Major
                Found in resources/assets/js/helper/array.ts and 1 other location - About 1 hr to fix
                resources/assets/js/helper/array.ts on lines 18..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 72.

                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

                Array.prototype.where = function (prop, value = undefined) {
                    return this.filter(function (el) {
                        if (value !== undefined) {
                            return el[prop] == value;
                        }
                Severity: Major
                Found in resources/assets/js/helper/array.ts and 1 other location - About 1 hr to fix
                resources/assets/js/helper/array.ts on lines 28..36

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

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

                              Severity
                              Category
                              Status
                              Source
                              Language