davide-casiraghi/laravel-events-calendar

View on GitHub
src/Models/Event.php

Summary

Maintainability
D
1 day
Test Coverage

File Event.php has 265 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace DavideCasiraghi\LaravelEventsCalendar\Models;

use Carbon\Carbon;
Severity: Minor
Found in src/Models/Event.php - About 2 hrs to fix

    Method getEvents has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function getEvents(array $filters, $itemPerPage)
        {
            if (! array_key_exists('startDate', $filters) || ! $filters['startDate']) {
                $filters['startDate'] = Carbon::now()->format('Y-m-d');
            }
    Severity: Major
    Found in src/Models/Event.php - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

              if ($filters['keywords'] || $filters['category'] || $filters['city'] || $filters['country'] || $filters['region'] || $filters['continent'] || $filters['teacher'] || $filters['venue'] || $filters['endDate']) {
      
              //$start = microtime(true);
                  //DB::enableQueryLog();
                  $ret = self::
      Severity: Critical
      Found in src/Models/Event.php - About 1 hr to fix

        Method getActiveEventsMapGeoJSON has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getActiveEventsMapGeoJSON()
            {
                $cacheExpireMinutes = 1440; // Set the duration time of the cache (1 day - 1440 minutes) - this cache tag get invalidates also on event save
        
                $eventsMapGeoJSONArrayCached = Cache::remember('active_events_map_markers_json', $cacheExpireMinutes, function () {
        Severity: Minor
        Found in src/Models/Event.php - About 1 hr to fix

          Method preSave has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function preSave(array $requestArray, $eventPicture): void
              {
                  $teachers = Teacher::pluck('name', 'id');
          
                  $this->title = $requestArray['title'];
          Severity: Minor
          Found in src/Models/Event.php - About 1 hr to fix

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

                public static function getActiveEventsMapMarkersDataFromDb()
                {
                    $seconds = 86400; // One day (this cache tag get invalidates also on event save)
            
                    $ret = Cache::remember('active_events_map_markers_db_data', $seconds, function () {
            Severity: Minor
            Found in src/Models/Event.php - About 1 hr to fix

              Function preSave has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function preSave(array $requestArray, $eventPicture): void
                  {
                      $teachers = Teacher::pluck('name', 'id');
              
                      $this->title = $requestArray['title'];
              Severity: Minor
              Found in src/Models/Event.php - About 55 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 setEventRepeatFields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function setEventRepeatFields(array $requestArray)
                  {
                      // Set Repeat Until
                      $this->repeat_type = $requestArray['repeat_type'];
                      if (isset($requestArray['repeat_until']) && array_key_exists('repeat_until', $requestArray)) {
              Severity: Minor
              Found in src/Models/Event.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

              Avoid too many return statements within this method.
              Open

                                      return $query->where('event_venues.region_id', '=', $region);
              Severity: Major
              Found in src/Models/Event.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                        return $query->where('event_venues.name', 'like', '%'.$venue.'%');
                Severity: Major
                Found in src/Models/Event.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                          return $query->where('event_venues.continent_id', '=', $continent);  //sc_continent_id
                  Severity: Major
                  Found in src/Models/Event.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $ret;
                    Severity: Major
                    Found in src/Models/Event.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                              return $query->where('event_venues.city', 'like', '%'.$city.'%');
                      Severity: Major
                      Found in src/Models/Event.php - About 30 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status