marcelog/PAMI

View on GitHub
doc/examples/asyncagi/example.php

Summary

Maintainability
A
1 hr
Test Coverage

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

    public function handle(EventMessage $event)
    {
        if ($event instanceof \PAMI\Message\Event\AsyncAGIEvent) {
            if ($event->getSubEvent() == 'Start') {
                switch($pid = pcntl_fork())
Severity: Minor
Found in doc/examples/asyncagi/example.php - About 1 hr to fix

    Function handle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function handle(EventMessage $event)
        {
            if ($event instanceof \PAMI\Message\Event\AsyncAGIEvent) {
                if ($event->getSubEvent() == 'Start') {
                    switch($pid = pcntl_fork())
    Severity: Minor
    Found in doc/examples/asyncagi/example.php - About 35 mins 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

    Missing class import via use statement (line '73', column '36').
    Open

                            $agi = new \PAMI\AsyncAgi\AsyncClientImpl(array(
    Severity: Minor
    Found in doc/examples/asyncagi/example.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 '77', column '36').
    Open

                            $app = new MyPAGIApplication(array(
    Severity: Minor
    Found in doc/examples/asyncagi/example.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 '\Logger' in method 'handle'.
    Open

                            $logger = \Logger::getLogger(__CLASS__);
    Severity: Minor
    Found in doc/examples/asyncagi/example.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 unused local variables such as '$logger'.
    Open

                            $logger = \Logger::getLogger(__CLASS__);
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Avoid unused local variables such as '$pid'.
    Open

                    switch($pid = pcntl_fork())
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Avoid unused local variables such as '$status'.
    Open

                pcntl_wait($status);
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    The method handle() contains an exit expression.
    Open

                            exit(0);
    Severity: Minor
    Found in doc/examples/asyncagi/example.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

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class ListenerTest implements IEventListener

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 57 and the first side effect is on line 30.
    Open

    <?php

    The property $_pamiOptions is not named in camelCase.
    Open

    class ListenerTest implements IEventListener
    {
        private $_client;
        private $_id;
        private $_pamiOptions;
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $_client is not named in camelCase.
    Open

    class ListenerTest implements IEventListener
    {
        private $_client;
        private $_id;
        private $_pamiOptions;
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $_id is not named in camelCase.
    Open

    class ListenerTest implements IEventListener
    {
        private $_client;
        private $_id;
        private $_pamiOptions;
    Severity: Minor
    Found in doc/examples/asyncagi/example.php by phpmd

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    Property name "$_id" should not be prefixed with an underscore to indicate visibility
    Open

        private $_id;

    Property name "$_client" should not be prefixed with an underscore to indicate visibility
    Open

        private $_client;

    Property name "$_pamiOptions" should not be prefixed with an underscore to indicate visibility
    Open

        private $_pamiOptions;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->_client->close();

    Spaces must be used to indent lines; tabs are not allowed
    Open

        $listener = new ListenerTest($options);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        echo $e->getMessage() . "\n";

    Spaces must be used to indent lines; tabs are not allowed
    Open

                usleep(1000);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->_client->process();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            while(true)

    Spaces must be used to indent lines; tabs are not allowed
    Open

        $listener->run();

    Expected 1 space after closing parenthesis; found 17
    Open

                    switch($pid = pcntl_fork())

    Expected 1 space after TRY keyword; newline found
    Open

    try

    Space before opening parenthesis of function call prohibited
    Open

        exit (254);

    Expected 1 space after SWITCH keyword; 0 found
    Open

                    switch($pid = pcntl_fork())

    Expected 1 space after WHILE keyword; 0 found
    Open

            while(true)

    Expected 1 space after closing parenthesis; found 9
    Open

            while(true)

    There are no issues that match your filters.

    Category
    Status