AppStateESS/InternshipInventory

View on GitHub
class/InternshipInventory.php

Summary

Maintainability
D
3 days
Test Coverage

handleRequest accesses the super-global variable $_REQUEST.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

handleRequest accesses the super-global variable $_REQUEST.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

handleRequest accesses the super-global variable $_REQUEST.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method handleRequest has 274 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Major
Found in class/InternshipInventory.php - About 1 day to fix

Function handleRequest has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php - About 1 day 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

The class InternshipInventory has an overall complexity of 71 which is very high. The configured complexity threshold is 50.
Open

class InternshipInventory {

    private $content;

    public function __construct()
Severity: Minor
Found in class/InternshipInventory.php by phpmd

File InternshipInventory.php has 290 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This file is part of Internship Inventory.
 *
 * Internship Inventory is free software: you can redistribute it and/or modify
Severity: Minor
Found in class/InternshipInventory.php - About 2 hrs to fix

The method handleRequest() has an NPath complexity of 780. The configured NPath complexity threshold is 200.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

The method handleRequest() has 289 lines of code. Current threshold is set to 100. Avoid really long methods.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

The method handleRequest() has a Cyclomatic Complexity of 69. The configured cyclomatic complexity threshold is 10.
Open

    public function handleRequest()
    {
        // Check if it is time to add more term. If so, show a warning to admins.
        $futureTerms = TermFactory::getFutureTermsAssoc();
        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.php by phpmd

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

class InternshipInventory {

    private $content;

    public function __construct()
Severity: Minor
Found in class/InternshipInventory.php by phpmd

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

                if (!\Current_User::allow('intern', 'special_host')) {
Severity: Minor
Found in class/InternshipInventory.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 'handleRequest'.
Open

                if (!\Current_User::allow('intern', 'edit_terms')) {
Severity: Minor
Found in class/InternshipInventory.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 '\NQ' in method 'handleRequest'.
Open

            \NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "There are less than three future terms available. It's probably time to add a new term.");
Severity: Minor
Found in class/InternshipInventory.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

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

        } else {
            $req = $_REQUEST['action'];
            $transactionName = $req;
        }
Severity: Minor
Found in class/InternshipInventory.php by phpmd

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

                if (!\Current_User::allow('intern', 'edit_state')) {
Severity: Minor
Found in class/InternshipInventory.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\TermFactory' in method 'handleRequest'.
Open

        $futureTerms = TermFactory::getFutureTermsAssoc();
Severity: Minor
Found in class/InternshipInventory.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\InternshipFactory' in method 'handleRequest'.
Open

                $i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
Severity: Minor
Found in class/InternshipInventory.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\TermFactory' in method 'handleRequest'.
Open

                $term = \Intern\TermFactory::getTermByTermCode($i->getTerm());
Severity: Minor
Found in class/InternshipInventory.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 'handleRequest'.
Open

        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Minor
Found in class/InternshipInventory.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 'handleRequest'.
Open

                if (!\Current_User::allow('intern', 'edit_courses')) {
Severity: Minor
Found in class/InternshipInventory.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 'handleRequest'.
Open

                if (!\Current_User::allow('intern', 'edit_level')) {
Severity: Minor
Found in class/InternshipInventory.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 'handleRequest'.
Open

                if (!\Current_User::allow('intern', 'edit_terms')) {
Severity: Minor
Found in class/InternshipInventory.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\EmergencyContactFactory' in method 'handleRequest'.
Open

                $emgContacts = EmergencyContactFactory::getContactsForInternship($i);
Severity: Minor
Found in class/InternshipInventory.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

The method handleRequest() contains an exit expression.
Open

                exit;
Severity: Minor
Found in class/InternshipInventory.php by phpmd

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

Source https://phpmd.org/rules/design.html#exitexpression

The method handleRequest() contains an exit expression.
Open

                exit();
Severity: Minor
Found in class/InternshipInventory.php by phpmd

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

Source https://phpmd.org/rules/design.html#exitexpression

Call to method simple from undeclared class \NQ
Open

            \NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "There are less than three future terms available. It's probably time to add a new term.");
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'edit_terms')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method output from undeclared class \Intern\FPDI
Open

                $pdf->output();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared method \Intern\Command\MajorRest::execute
Open

                $ctrl->execute();
Severity: Critical
Found in class/InternshipInventory.php by phan

Reference to undeclared constant \PHPWS_SOURCE_DIR
Open

                readfile(\PHPWS_SOURCE_DIR . 'mod/intern/pdf/Internship_Example.pdf');
Severity: Minor
Found in class/InternshipInventory.php by phan

Cannot assign void return value
Open

                $this->content = $ctrl->execute();
Severity: Info
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'edit_terms')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

Possibly zero references to use statement for classlike/namespace NotifyUI (\Intern\UI\NotifyUI)
Open

use Intern\UI\NotifyUI;
Severity: Minor
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'edit_courses')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'edit_state')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to undeclared function \disallow()
Open

                    disallow();
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'special_host')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

Call to method isDeity from undeclared class \Current_User
Open

        if(sizeof($futureTerms) < 3 && \Current_User::isDeity()){
Severity: Critical
Found in class/InternshipInventory.php by phan

Argument 1 (termCode) is int but \Intern\TermFactory::getTermByTermCode() takes string defined at /code/class/TermFactory.php:32
Open

                $term = \Intern\TermFactory::getTermByTermCode($i->getTerm());
Severity: Minor
Found in class/InternshipInventory.php by phan

Call to method allow from undeclared class \Current_User
Open

                if (!\Current_User::allow('intern', 'edit_level')) {
Severity: Critical
Found in class/InternshipInventory.php by phan

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

                $i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
Severity: Minor
Found in class/InternshipInventory.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