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;
}
- Read upRead up
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;
}
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;
}
- Read upRead up
- Exclude checks
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;
}
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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__);
- Read upRead up
- Exclude checks
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;
}
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Exclude checks
Reference to undeclared property \Webhook->format
Open
"{$this->format}" => $data
- Exclude checks
Reference to undeclared property \Webhook->login
Open
$params['auth'] = [$this->login, $this->password];
- Exclude checks
Call to method __construct
from undeclared class \GuzzleHttp\Client
Open
(new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);
- Exclude checks
Reference to undeclared property \Webhook->typedata
Open
foreach ($this->typedata as $type) {
- Exclude checks
Call to method request
from undeclared class \GuzzleHttp\Client
Open
(new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);
- Exclude checks
Reference to undeclared property \Webhook->url
Open
\App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);
- Exclude checks
Reference to undeclared property \Webhook->typedata
Open
if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
- Exclude checks
Reference to undeclared property \Webhook->password
Open
$params['auth'] = [$this->login, $this->password];
- Exclude checks
Call to method endProfile
from undeclared class \App\Log
Open
\App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Call to method warning
from undeclared class \App\Log
Open
\App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);
- Exclude checks
Reference to undeclared property \Webhook->login
Open
if (!empty($this->login)) {
- Exclude checks
Call to method beginProfile
from undeclared class \App\Log
Open
\App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Reference to undeclared property \Webhook->url
Open
\App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Reference to undeclared property \Webhook->format
Open
if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
- Exclude checks
Reference to undeclared property \Webhook->url
Open
\App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Reference to undeclared property \Webhook->fields
Open
$fields = $this->fields ?: array_keys($recordModel->getModule()->getFields());
- Exclude checks
Reference to undeclared property \Webhook->url
Open
if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Webhook extends VTTask
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** @var bool Performs the task immediately after saving. */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return ['url', 'login', 'password', 'fields', 'typedata', 'format'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
"{$this->format}" => $data
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$data = ['date' => date('Y-m-d H:i:s (T P)')];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$data[$type][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$data[$type][$fieldName] = $recordModel->get($fieldName);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function getFieldNames()
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (false !== ($previousValue = $recordModel->getPreviousValue($fieldName))) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @package WorkflowTask
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($fields as $fieldName) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
case 'data':
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function doTask($recordModel)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
case 'rawData':
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$params['auth'] = [$this->login, $this->password];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
(new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('POST', $this->url, $params);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$params = [
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
\App\Log::beginProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (empty($this->url) || empty($this->format) || empty($this->typedata)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$fields = $this->fields ?: array_keys($recordModel->getModule()->getFields());
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
switch ($type) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$data[$type][$fieldName] = ['before' => $previousValue, 'after' => $recordModel->get($fieldName)];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'verify' => false,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
case 'changes':
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
\App\Log::endProfile("POST|{$this->url}", 'Workflow|Webhook');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
} catch (\Throwable $ex) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
\App\Log::warning('Error: ' . $this->url . ' | ' . $ex->__toString(), __CLASS__);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($this->typedata as $type) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public $executeImmediately = true;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!empty($this->login)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$data[$type][$fieldName] = ['before' => $previousValue, 'after' => $recordModel->get($fieldName)];
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$data[$type][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);
- Exclude checks