timegridio/timegrid

View on GitHub
app/Http/Controllers/User/AgendaController.php

Summary

Maintainability
C
7 hrs
Test Coverage

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

    public function postStore(Request $request)
    {
        logger()->info(__METHOD__);

        //////////////////
Severity: Major
Found in app/Http/Controllers/User/AgendaController.php - About 2 hrs to fix

Method getAvailability has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getAvailability(Business $business, Request $request)
    {
        logger()->info(__METHOD__);

        if (auth()->user()) {
Severity: Minor
Found in app/Http/Controllers/User/AgendaController.php - About 1 hr to fix

Function postStore has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function postStore(Request $request)
    {
        logger()->info(__METHOD__);

        //////////////////
Severity: Minor
Found in app/Http/Controllers/User/AgendaController.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

Function getAvailability has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function getAvailability(Business $business, Request $request)
    {
        logger()->info(__METHOD__);

        if (auth()->user()) {
Severity: Minor
Found in app/Http/Controllers/User/AgendaController.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

Avoid too many return statements within this method.
Open

            return view('guest.appointment.show', compact('appointment'));
Severity: Major
Found in app/Http/Controllers/User/AgendaController.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return redirect()->route('user.agenda', '#'.$appointment->code);
Severity: Major
Found in app/Http/Controllers/User/AgendaController.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return redirect()->route('manager.business.agenda.index', compact('business'));
Severity: Major
Found in app/Http/Controllers/User/AgendaController.php - About 30 mins to fix

The class AgendaController has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
Open

class AgendaController extends Controller
{
    /**
     * Concierge service implementation.
     *

Since: PHPMD 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example:

class Foo {
      /**
       * @var \foo\bar\X
       */
      private $x = null;

      /**
       * @var \foo\bar\Y
       */
      private $y = null;

      /**
       * @var \foo\bar\Z
       */
      private $z = null;

      public function setFoo(\Foo $foo) {}
      public function setBar(\Bar $bar) {}
      public function setBaz(\Baz $baz) {}

      /**
       * @return \SplObjectStorage
       * @throws \OutOfRangeException
       * @throws \InvalidArgumentException
       * @throws \ErrorException
       */
      public function process(\Iterator $it) {}

      // ...
  }

Source: http://phpmd.org/rules/design.txt

The method getAvailability uses an else expression. Else is never necessary and you can simplify the code to work without else.
Open

            } else {
                if (!$contact = auth()->user()->getContactSubscribedTo($business->id)) {
                    logger()->info('  [ADVICE] User not subscribed to Business');

                    flash()->warning(trans('user.booking.msg.you_are_not_subscribed_to_business'));

Since: PHPMD 1.4.0

An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example:

class Foo
  {
      public function bar($flag)
      {
          if ($flag) {
              // one branch
          } else {
              // another branch
          }
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

Avoid using static access to class '\Timegridio\Concierge\Models\Business' in method 'postStore'.
Open

        $business = Business::findOrFail($request->input('businessId'));

Since: PHPMD 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example:

class Foo
  {
      public function bar()
      {
          Bar::baz();
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

Avoid using static access to class '\Carbon' in method 'sanitizeDate'.
Open

            $date = Carbon::now();

Since: PHPMD 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example:

class Foo
  {
      public function bar()
      {
          Bar::baz();
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

The method postStore uses an else expression. Else is never necessary and you can simplify the code to work without else.
Open

        } else {
            $contact = $this->getContact($business, $email);

            if (!$contact) {
                logger()->info('[ADVICE] Not subscribed');

Since: PHPMD 1.4.0

An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example:

class Foo
  {
      public function bar($flag)
      {
          if ($flag) {
              // one branch
          } else {
              // another branch
          }
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

The method getContact uses an else expression. Else is never necessary and you can simplify the code to work without else.
Open

        } else {
            $contact = $business->addressbook()->getSubscribed($email);
        }

Since: PHPMD 1.4.0

An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements. To achieve this you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example:

class Foo
  {
      public function bar($flag)
      {
          if ($flag) {
              // one branch
          } else {
              // another branch
          }
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

Avoid using static access to class '\Carbon' in method 'sanitizeDate'.
Open

            $date = Carbon::parse($dateString);

Since: PHPMD 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example:

class Foo
  {
      public function bar()
      {
          Bar::baz();
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

Avoid using static access to class '\JavaScript' in method 'getAvailability'.
Open

        JavaScript::put([
            'language'  => $this->getActiveLanguage($business->locale),
            'startDate' => $startFromDate->toDateString(),
            'endDate'   => $startFromDate->addDays($days)->toDateString(),
        ]);

Since: PHPMD 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example:

class Foo
  {
      public function bar()
      {
          Bar::baz();
      }
  }

Source: http://phpmd.org/rules/cleancode.txt

There are no issues that match your filters.

Category
Status