YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/tasks/Webhook.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Function doTask has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
            return;
        }
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/Webhook.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 doTask has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
            return;
        }
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/Webhook.php - About 1 hr to fix

    The method doTask() has an NPath complexity of 224. The configured NPath complexity threshold is 200.
    Open

        public function doTask($recordModel)
        {
            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
                return;
            }

    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 doTask() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
    Open

        public function doTask($recordModel)
        {
            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
                return;
            }

    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

    Missing class import via use statement (line '62', column '9').
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    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 '\App\Log' in method 'doTask'.
    Open

                \App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');

    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 '\App\Log' in method 'doTask'.
    Open

                \App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);

    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 '41', column '22').
    Open

        public function doTask($recordModel)
        {
            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
                return;
            }

    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 using static access to class '\App\Log' in method 'doTask'.
    Open

                \App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');

    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 '\App\RequestHttp' in method 'doTask'.
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    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

    Reference to undeclared property \Webhook->url
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    Reference to undeclared property \Webhook->format
    Open

                "{$this->format}" => $data

    Reference to undeclared property \Webhook->login
    Open

                $params['auth'] = [$this->login, $this->password];

    Call to method __construct from undeclared class \GuzzleHttp\Client
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    Reference to undeclared property \Webhook->typedata
    Open

            foreach ($this->typedata as $type) {

    Call to method request from undeclared class \GuzzleHttp\Client
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    Reference to undeclared property \Webhook->url
    Open

                \App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);

    Reference to undeclared property \Webhook->typedata
    Open

            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {

    Reference to undeclared property \Webhook->password
    Open

                $params['auth'] = [$this->login, $this->password];

    Call to method endProfile from undeclared class \App\Log
    Open

                \App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');

    Call to method warning from undeclared class \App\Log
    Open

                \App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);

    Reference to undeclared property \Webhook->login
    Open

            if (!empty($this->login)) {

    Call to method beginProfile from undeclared class \App\Log
    Open

                \App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');

    Reference to undeclared property \Webhook->url
    Open

                \App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');

    Reference to undeclared property \Webhook->format
    Open

            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {

    Reference to undeclared property \Webhook->url
    Open

                \App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');

    Reference to undeclared property \Webhook->fields
    Open

            $fields = $this->fields ?: array_keys($recordModel->getModule()->getFields());

    Reference to undeclared property \Webhook->url
    Open

            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {

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

    class Webhook extends VTTask

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** @var bool Performs the task immediately after saving. */

    Spaces must be used for alignment; tabs are not allowed
    Open

            return ['url', 'login', 'password', 'fields', 'typedata', 'format'];

    Spaces must be used for alignment; tabs are not allowed
    Open

                "{$this->format}" => $data

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                return false;

    Spaces must be used for alignment; tabs are not allowed
    Open

            $data = ['date' => date('Y-m-d H:i:s (T P)')];

    Spaces must be used for alignment; tabs are not allowed
    Open

                            $data[$type][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);

    Spaces must be used for alignment; tabs are not allowed
    Open

                            $data[$type][$fieldName] = $recordModel->get($fieldName);

    Spaces must be used for alignment; tabs are not allowed
    Open

                    }

    Spaces must be used for alignment; tabs are not allowed
    Open

        public function getFieldNames()

    Spaces must be used for alignment; tabs are not allowed
    Open

                return;

    Spaces must be used for alignment; tabs are not allowed
    Open

                            if (false !== ($previousValue = $recordModel->getPreviousValue($fieldName))) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

                        default:

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

     * @package     WorkflowTask

    Spaces must be used for alignment; tabs are not allowed
    Open

                foreach ($fields as $fieldName) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                        case 'data':

    Spaces must be used for alignment; tabs are not allowed
    Open

                            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            try {

    Spaces must be used for alignment; tabs are not allowed
    Open

        public function doTask($recordModel)

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

                        case 'rawData':

    Spaces must be used for alignment; tabs are not allowed
    Open

            ];

    Spaces must be used for alignment; tabs are not allowed
    Open

                $params['auth'] = [$this->login, $this->password];

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

                (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            $params = [

    Spaces must be used for alignment; tabs are not allowed
    Open

                \App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used for alignment; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (empty($this->url) || empty($this->format) || empty($this->typedata)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            $fields = $this->fields ?: array_keys($recordModel->getModule()->getFields());

    Spaces must be used for alignment; tabs are not allowed
    Open

                    switch ($type) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                                $data[$type][$fieldName] = ['before' => $previousValue, 'after' => $recordModel->get($fieldName)];

    Spaces must be used for alignment; tabs are not allowed
    Open

                            break;

    Spaces must be used for alignment; tabs are not allowed
    Open

                'verify' => false,

    Spaces must be used for alignment; tabs are not allowed
    Open

                        case 'changes':

    Spaces must be used for alignment; tabs are not allowed
    Open

                \App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');

    Spaces must be used for alignment; tabs are not allowed
    Open

            } catch (\Throwable $ex) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                \App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            foreach ($this->typedata as $type) {

    Spaces must be used for alignment; tabs are not allowed
    Open

        public $executeImmediately = true;

    Spaces must be used for alignment; tabs are not allowed
    Open

                            break;

    Spaces must be used for alignment; tabs are not allowed
    Open

                            break;

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (!empty($this->login)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                            break;

    Line exceeds 120 characters; contains 126 characters
    Open

                                $data[$type][$fieldName] = ['before' => $previousValue, 'after' => $recordModel->get($fieldName)];

    Line exceeds 120 characters; contains 122 characters
    Open

                            $data[$type][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);

    There are no issues that match your filters.

    Category
    Status