AppStateESS/InternshipInventory

View on GitHub
class/WorkflowController.php

Summary

Maintainability
A
2 hrs
Test Coverage

Function doTransition has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function doTransition($note = null)
    {
        // Make sure the transition makes sense based on the current state of the internship
        $currStateName = $this->internship->getStateName();

Severity: Minor
Found in class/WorkflowController.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

Method doTransition has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTransition($note = null)
    {
        // Make sure the transition makes sense based on the current state of the internship
        $currStateName = $this->internship->getStateName();

Severity: Minor
Found in class/WorkflowController.php - About 1 hr to fix

Missing class import via use statement (line '46', column '23').
Open

            throw new \InvalidArgumentException('Invalid transition source state.');
Severity: Minor
Found in class/WorkflowController.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

Missing class import via use statement (line '43', column '27').
Open

                throw new \InvalidArgumentException('Invalid transition source state.');
Severity: Minor
Found in class/WorkflowController.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

Avoid using static access to class '\Current_User' in method 'doTransition'.
Open

        $changeHistory = new ChangeHistory($this->internship, \Current_User::getUserObj(), time(), $sourceState, $destState, $note);
Severity: Minor
Found in class/WorkflowController.php by phpmd

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 '\Current_User' in method 'doTransition'.
Open

                $changeHistory = new ChangeHistory($this->internship, \Current_User::getUserObj(), time(), $sourceState, $sourceState, $note);
Severity: Minor
Found in class/WorkflowController.php by phpmd

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 'Intern\WorkflowStateFactory' in method 'doTransition'.
Open

        $destState = WorkflowStateFactory::getState($destStateName);
Severity: Minor
Found in class/WorkflowController.php by phpmd

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 'Intern\WorkflowStateFactory' in method 'doTransition'.
Open

        $sourceState = WorkflowStateFactory::getState($currStateName);
Severity: Minor
Found in class/WorkflowController.php by phpmd

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

Call to method getUserObj from undeclared class \Current_User
Open

        $changeHistory = new ChangeHistory($this->internship, \Current_User::getUserObj(), time(), $sourceState, $destState, $note);
Severity: Critical
Found in class/WorkflowController.php by phan

Call to method __construct from undeclared class \Intern\Exception (Did you mean class \Exception)
Open

            throw new Exception("You do not have permission to set the internship to the requested status.");
Severity: Critical
Found in class/WorkflowController.php by phan

Call to method getUserObj from undeclared class \Current_User
Open

                $changeHistory = new ChangeHistory($this->internship, \Current_User::getUserObj(), time(), $sourceState, $sourceState, $note);
Severity: Critical
Found in class/WorkflowController.php by phan

Avoid variables with short names like $t. Configured minimum length is 3.
Open

    private $t;
Severity: Minor
Found in class/WorkflowController.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $t. Configured minimum length is 3.
Open

    public function __construct(Internship $i, WorkflowTransition $t)
Severity: Minor
Found in class/WorkflowController.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $i. Configured minimum length is 3.
Open

    public function __construct(Internship $i, WorkflowTransition $t)
Severity: Minor
Found in class/WorkflowController.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

There are no issues that match your filters.

Category
Status