timegridio/timegrid

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

Summary

Maintainability
C
7 hrs
Test Coverage
B
89%

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 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

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

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 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('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.
     *

CouplingBetweenObjects

Since: 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 https://phpmd.org/rules/design.html#couplingbetweenobjects

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(),
        ]);

StaticAccess

Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

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

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

StaticAccess

Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

The method postStore uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

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

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

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

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

            $date = Carbon::now();

StaticAccess

Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

The method getAvailability uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
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'));

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

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

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

StaticAccess

Since: 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 https://phpmd.org/rules/cleancode.html#staticaccess

Avoid assigning values to variables in if clauses and the like (line '66', column '17').
Open

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

        if (auth()->user()) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Avoid assigning values to variables in if clauses and the like (line '71', column '22').
Open

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

        if (auth()->user()) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

The method getContact uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

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

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though 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 https://phpmd.org/rules/cleancode.html#elseexpression

There are no issues that match your filters.

Category
Status