Method getFieldInstances
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFieldInstances(): array
{
$company = \App\Company::getCompany();
$fields = [];
foreach (self::COMPANY_FORM_FIELDS as $fieldName) {
Function getFieldInstances
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getFieldInstances(): array
{
$company = \App\Company::getCompany();
$fields = [];
foreach (self::COMPANY_FORM_FIELDS as $fieldName) {
- 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
Avoid using static access to class '\App\Fields\Country' in method 'getFieldInstances'. Open
foreach (\App\Fields\Country::getAll() as $country) {
- 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\Json' in method 'send'. Open
}
- 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 '\Settings_Vtiger_Field_Model' in method 'getFieldInstances'. Open
$fields[$fieldName] = \Settings_Vtiger_Field_Model::init('Vtiger', $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
Avoid using static access to class '\App\Language' in method 'getFieldInstances'. Open
$params['picklistValues'][$country['name']] = \App\Language::translateSingleMod(
$country['name'],
'Other.Country'
);
- 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\Company' in method 'getFieldInstances'. Open
$company = \App\Company::getCompany();
- 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 '121', column '25'). Open
public function send(): bool
{
$this->success = false;
$client = new ApiClient();
$client->send(self::URL, 'POST', ['form_params' => $this->getData()]);
- 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
syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST)
Open
public ?string $error = null;
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
private ?string $id;
- Read upRead up
- Exclude checks
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 $id. Configured minimum length is 3. Open
private function setId(string $id): self
- Read upRead up
- Exclude checks
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
CASE statements must be defined using a colon Open
case 'city':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'city',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields[$fieldName] = \Settings_Vtiger_Field_Model::init('Vtiger', $params);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->success = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set product package ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private array $data = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'typeofdata' => 'V~M',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['maximumlength'] = '100';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'maximumlength' => '255',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->data[$key] = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->success = \in_array($code, [200, 201]) && $content;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getId()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->packageId = $packageId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getData(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_' . strtoupper($fieldName),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'city':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->id = $id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'uitype' => 1,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'fieldvalue' => $company[$fieldName] ?? null,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'isEditableReadOnly' => false,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name' => $fieldName,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function send(): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = $client->getResponseBody();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get order ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vat_id',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Order ID */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function determines fields available in payment view.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Send order data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vatId' => $this->data['vat_id'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'post_code',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'postCode' => $this->data['post_code'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const URL = 'https://api.yetiforce.eu/registrations/orders';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'country',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'displaytype' => 1,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['picklistValues'][$country['name']] = \App\Language::translateSingleMod(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$country['name'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $fields;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get last error.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'packageId' => $this->packageId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private const COMPANY_FORM_FIELDS = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'column' => $fieldName,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->error ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'country' => $this->data['country'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string URL */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'address',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Array of company form fields.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Last error. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private bool $success;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['picklistValues'] = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->success) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$client->send(self::URL, 'POST', ['form_params' => $this->getData()]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->error = $client->getError();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->setId(\App\Json::decode($content)['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $packageId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var array Raw data */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \Settings_Vtiger_Field_Model[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldInstances(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$company = \App\Company::getCompany();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['maximumlength'] = '100';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (\App\Fields\Country::getAll() as $country) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var bool Response result */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::COMPANY_FORM_FIELDS as $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'purifyType' => \App\Purifier::TEXT
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['uitype'] = 16;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Other.Country'
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$client = new ApiClient();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getError(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'company' => $this->data['name'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private ?string $id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->error && ($code = $client->getStatusCode())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->success;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->id ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setPackageId(string $packageId): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public ?string $error = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var Product package ID */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function set(string $key, $value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function setId(string $id): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'city' => $this->data['city'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'address' => $this->data['address'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private string $packageId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'presence' => '',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'country':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* set order ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get registration data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks