src/Models/Event.php
File Event.php
has 265 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
<?php
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
use Carbon\Carbon;
Method getEvents
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static function getEvents(array $filters, $itemPerPage)
{
if (! array_key_exists('startDate', $filters) || ! $filters['startDate']) {
$filters['startDate'] = Carbon::now()->format('Y-m-d');
}
Consider simplifying this complex logical expression. Open
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::
Method getActiveEventsMapGeoJSON
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
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 () {
Method preSave
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function preSave(array $requestArray, $eventPicture): void
{
$teachers = Teacher::pluck('name', 'id');
$this->title = $requestArray['title'];
Method getActiveEventsMapMarkersDataFromDb
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
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 () {
Function preSave
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
public function preSave(array $requestArray, $eventPicture): void
{
$teachers = Teacher::pluck('name', 'id');
$this->title = $requestArray['title'];
- Read upRead up
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
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)) {
- Read upRead up
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
Open
return $query->where('event_venues.region_id', '=', $region);
Avoid too many return
statements within this method. Open
Open
return $query->where('event_venues.name', 'like', '%'.$venue.'%');
Avoid too many return
statements within this method. Open
Open
return $query->where('event_venues.continent_id', '=', $continent); //sc_continent_id
Avoid too many return
statements within this method. Open
Open
return $ret;
Avoid too many return
statements within this method. Open
Open
return $query->where('event_venues.city', 'like', '%'.$city.'%');