Function testBanks
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function testBanks()
{
$dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
->from('vtiger_currency_info')
->where(['currency_status' => 'Active', 'deleted' => 0])
- 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
Missing class import via use statement (line '46', column '22'). Open
$dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
- 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 '\Settings_CurrencyUpdate_Module_Model' in method 'testModuleModel'. Open
$this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
- 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_CurrencyUpdate_Module_Model' in method 'testModuleModel'. Open
$moduleModel = \Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- 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
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsInt
Open
$this->assertIsInt($moduleModel->getCurrencyNum(), 'Expected currency number as integer');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open
$this->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsNumeric
Open
$this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsBool
Open
$this->assertIsBool($moduleModel->fetchCurrencyRates(date('Y-m-d')), 'Expected boolean result.');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open
$this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return array');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNull
Open
$this->assertNull($moduleModel->refreshBanks(), 'Method should return nothing');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open
$this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open
$this->assertNotEmpty($moduleModel->getActiveBankName(), 'Active bank name should be not empty');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open
$this->assertNotEmpty($bank->getMainCurrencyCode(), 'Main bank currency should be not empty');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsInt
Open
$this->assertIsInt($moduleModel->getActiveBankId(), 'Expected active bank id as integer');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open
$this->assertNotEmpty($bank->getName(), 'Bank name should be not empty');
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNull
Open
$this->assertNull($bank->getRates($currencyList, date('Y-m-d'), true), 'Expected nothing/null');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertTrue
Open
$this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsNumeric
Open
$this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open
$this->assertNotEmpty($bank->getSource(), 'Bank source should be not empty');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::markTestSkipped
Open
$this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open
$this->assertIsArray($bank->getSupportedCurrencies(), 'Expected array of currencies');
- Exclude checks
Call to undeclared method \Tests\Settings\CurrencyUpdate::markTestSkipped
Open
$this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
$this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (['CBR', 'ECB', 'NBR', 'NBP'] as $bankCode) {
- 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
* Testing module model methods.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testBanks()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_currency_info')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['currency_status' => 'Active', 'deleted' => 0])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 137 characters Open
$this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNotEmpty($moduleModel->getActiveBankName(), 'Active bank name should be not empty');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing external bank interfaces.
- 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->assertNotEmpty($bank->getName(), 'Bank name should be not empty');
- 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->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testModuleModel()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currencyList = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNotEmpty($bank->getMainCurrencyCode(), 'Main bank currency should be not empty');
- 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->assertIsInt($moduleModel->getCurrencyNum(), 'Expected currency number as integer');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsBool($moduleModel->fetchCurrencyRates(date('Y-m-d')), 'Expected boolean result.');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// @codeCoverageIgnoreStart
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->andWhere(['<>', 'defaultid', -11])->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Exception $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$this->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNull($moduleModel->refreshBanks(), 'Method should return nothing');
- 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->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Exception $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// @codeCoverageIgnoreEnd
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currencyList[$row['currency_code']] = $row['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNull($bank->getRates($currencyList, date('Y-m-d'), true), 'Expected nothing/null');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// @codeCoverageIgnoreStart
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = \Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsInt($moduleModel->getActiveBankId(), 'Expected active bank id as integer');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankClass = '\Settings_CurrencyUpdate_' . $bankCode . '_BankModel';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsArray($bank->getSupportedCurrencies(), 'Expected array of currencies');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
$this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return 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
echo "$bankCode - Disabled due to data source instability\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bank = new $bankClass();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($bankCode, ['CBR'])) {
- 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
// @codeCoverageIgnoreEnd
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertNotEmpty($bank->getSource(), 'Bank source should be not empty');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
- Exclude checks