davide-casiraghi/laravel-events-calendar

View on GitHub
src/Http/Controllers/EventController.php

Summary

Maintainability
D
2 days
Test Coverage

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;
Severity: Minor
Found in src/Http/Controllers/EventController.php - About 5 hrs to fix

    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()
    Severity: Minor
    Found in src/Http/Controllers/EventController.php - About 2 hrs to fix

      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.
      Severity: Minor
      Found in src/Http/Controllers/EventController.php - About 1 hr to fix

        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
        
        
        Severity: Minor
        Found in src/Http/Controllers/EventController.php - About 1 hr to fix

          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();
          Severity: Minor
          Found in src/Http/Controllers/EventController.php - About 1 hr to fix

            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
            Severity: Minor
            Found in src/Http/Controllers/EventController.php - About 1 hr to fix

              Method eventsValidator has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function eventsValidator(Request $request)
                  {
                      $rules = [
                          'title' => 'required',
                          'description' => 'required',
              Severity: Minor
              Found in src/Http/Controllers/EventController.php - About 1 hr to fix

                Avoid too many return statements within this method.
                Open

                                    return $query->where('created_by', $authorUserId);
                Severity: Major
                Found in src/Http/Controllers/EventController.php - About 30 mins to fix

                  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)
                  Severity: Major
                  Found in src/Http/Controllers/EventController.php - About 30 mins to fix

                    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)
                    Severity: Minor
                    Found in src/Http/Controllers/EventController.php and 1 other location - About 55 mins to fix
                    src/Http/Controllers/EventController.php on lines 186..195

                    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

                    Further Reading

                    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)
                    Severity: Minor
                    Found in src/Http/Controllers/EventController.php and 1 other location - About 55 mins to fix
                    src/Http/Controllers/EventController.php on lines 238..247

                    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

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status