File EventController.php
has 399 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace DavideCasiraghi\LaravelEventsCalendar\Http\Controllers;
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar;
EventController
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
class EventController extends Controller
{
/***************************************************************************/
/* Restrict the access to this resource just to logged in users except show view */
public function __construct()
Method calculateMonthlySelectOptions
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function calculateMonthlySelectOptions(Request $request)
{
$monthlySelectOptions = [];
$date = implode('-', array_reverse(explode('/', $request->day))); // Our YYYY-MM-DD date string
$unixTimestamp = strtotime($date); // Convert the date string into a unix timestamp.
Method index
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function index(Request $request)
{
// To show just the events created by the the user - If admin or super admin is set to null show all the events
$authorUserId = ($this->getLoggedAuthorId()) ? $this->getLoggedAuthorId() : null; // if is 0 (super admin or admin) it's setted to null to avoid include it in the query
Method edit
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function edit(Event $event)
{
//if (Auth::user()->id == $event->created_by || Auth::user()->isSuperAdmin() || Auth::user()->isAdmin()) {
if (Auth::user()->id == $event->created_by || Auth::user()->group == 1 || Auth::user()->group == 2) {
$authorUserId = $this->getLoggedAuthorId();
Method saveEventRepetitions
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function saveEventRepetitions(Request $request, int $eventId): void
{
EventRepetition::deletePreviousRepetitions($eventId);
// Saving repetitions - If it's a single event will be stored with just one repetition
Method eventsValidator
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function eventsValidator(Request $request)
{
$rules = [
'title' => 'required',
'description' => 'required',
Avoid too many return
statements within this method. Open
return $query->where('created_by', $authorUserId);
Avoid too many return
statements within this method. Open
return view('laravel-events-calendar::events.index', compact('events'))
->with('i', (request()->input('page', 1) - 1) * 20)
->with('eventCategories', $eventCategories)
->with('countries', $countries)
->with('venues', $venues)
Similar blocks of code found in 2 locations. Consider refactoring. Open
return view('laravel-events-calendar::events.edit', compact('event'))
->with('eventCategories', $eventCategories)
->with('users', $users)
->with('teachers', $teachers)
->with('multiple_teachers', $multiple_teachers)
- Read upRead up
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 99.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
return view('laravel-events-calendar::events.show', compact('event'))
->with('category', $category)
->with('teachers', $teachers)
->with('organizers', $organizers)
->with('venue', $venue)
- Read upRead up
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 99.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76