YetiForceCompany/YetiForceCRM

View on GitHub
tests/Settings/CurrencyUpdate.php

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

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])
Severity: Minor
Found in tests/Settings/CurrencyUpdate.php - About 25 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 '46', column '22').
Open

        $dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
Severity: Minor
Found in tests/Settings/CurrencyUpdate.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 '\Settings_CurrencyUpdate_Module_Model' in method 'testModuleModel'.
Open

        $this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
Severity: Minor
Found in tests/Settings/CurrencyUpdate.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 using static access to class '\Settings_CurrencyUpdate_Module_Model' in method 'testModuleModel'.
Open

        $moduleModel = \Settings_CurrencyUpdate_Module_Model::getCleanInstance();
Severity: Minor
Found in tests/Settings/CurrencyUpdate.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

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsInt
Open

        $this->assertIsInt($moduleModel->getCurrencyNum(), 'Expected currency number as integer');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open

            $this->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsNumeric
Open

            $this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsBool
Open

            $this->assertIsBool($moduleModel->fetchCurrencyRates(date('Y-m-d')), 'Expected boolean result.');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open

            $this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return array');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNull
Open

            $this->assertNull($moduleModel->refreshBanks(), 'Method should return nothing');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open

        $this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open

        $this->assertNotEmpty($moduleModel->getActiveBankName(), 'Active bank name should be not empty');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open

                $this->assertNotEmpty($bank->getMainCurrencyCode(), 'Main bank currency should be not empty');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsInt
Open

        $this->assertIsInt($moduleModel->getActiveBankId(), 'Expected active bank id as integer');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open

                $this->assertNotEmpty($bank->getName(), 'Bank name should be not empty');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \App\Db\Query::select
Open

        $dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNull
Open

                $this->assertNull($bank->getRates($currencyList, date('Y-m-d'), true), 'Expected nothing/null');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertTrue
Open

        $this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsNumeric
Open

            $this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertNotEmpty
Open

                $this->assertNotEmpty($bank->getSource(), 'Bank source should be not empty');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::markTestSkipped
Open

            $this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::assertIsArray
Open

                $this->assertIsArray($bank->getSupportedCurrencies(), 'Expected array of currencies');
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

Call to undeclared method \Tests\Settings\CurrencyUpdate::markTestSkipped
Open

            $this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());
Severity: Critical
Found in tests/Settings/CurrencyUpdate.php by phan

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

        $this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');

Line exceeds 120 characters; contains 127 characters
Open

            $this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');

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

        try {

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

            foreach (['CBR', 'ECB', 'NBR', 'NBP'] as $bankCode) {

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

    }

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

     * Testing module model methods.

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

            $this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');

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

    public function testBanks()

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

            ->from('vtiger_currency_info')

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

            ->where(['currency_status' => 'Active', 'deleted' => 0])

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

        }

Line exceeds 120 characters; contains 137 characters
Open

            $this->assertIsNumeric($moduleModel->getCRMConversionRate('PLN', 'USD'), 'getCRMConversionRate should always return number');

Line exceeds 120 characters; contains 132 characters
Open

        $this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');

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

        $this->assertNotEmpty($moduleModel->getActiveBankName(), 'Active bank name should be not empty');

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

     * Testing external bank interfaces.

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->assertNotEmpty($bank->getName(), 'Bank name should be not empty');

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

    /**

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

    {

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->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());

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

    public function testModuleModel()

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

            $this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return array');

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

    }

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

            }

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

        $currencyList = [];

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

                $this->assertNotEmpty($bank->getMainCurrencyCode(), 'Main bank currency should be not empty');

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->assertIsInt($moduleModel->getCurrencyNum(), 'Expected currency number as integer');

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

        try {

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

            $this->assertIsBool($moduleModel->fetchCurrencyRates(date('Y-m-d')), 'Expected boolean result.');

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

            // @codeCoverageIgnoreStart

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

        $this->assertTrue($moduleModel->setActiveBankById($moduleModel->getActiveBankId()), 'setActiveBankById should return true');

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

            ->andWhere(['<>', 'defaultid', -11])->createCommand()->query();

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

        } catch (\Exception $e) {

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

     */

Line exceeds 120 characters; contains 122 characters
Open

        $this->assertNotEmpty(\Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName('PLN'), 'Expected currency name');

Line exceeds 120 characters; contains 126 characters
Open

            $this->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');

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

            $this->assertNull($moduleModel->refreshBanks(), 'Method should return nothing');

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->assertIsArray($moduleModel->getSupportedCurrencies(), 'getSupportedCurrencies should always return array');

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

        } catch (\Exception $e) {

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

        // @codeCoverageIgnoreEnd

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

        $dataReader = (new \App\Db\Query())->select(['id', 'currency_code'])

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

            $currencyList[$row['currency_code']] = $row['id'];

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');

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

            // @codeCoverageIgnoreStart

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

        $moduleModel = \Settings_CurrencyUpdate_Module_Model::getCleanInstance();

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

        $this->assertIsInt($moduleModel->getActiveBankId(), 'Expected active bank id as integer');

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

        while ($row = $dataReader->read()) {

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

                $bankClass = '\Settings_CurrencyUpdate_' . $bankCode . '_BankModel';

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

                $this->assertIsArray($bank->getSupportedCurrencies(), 'Expected array of currencies');

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

            $this->assertIsNumeric($moduleModel->convertFromTo(12, 'PLN', 'USD'), 'convertFromTo should always return number');

Line exceeds 120 characters; contains 130 characters
Open

            $this->assertIsArray($moduleModel->getUnSupportedCurrencies(), 'getUnSupportedCurrencies should always return array');

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

    /**

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

                    echo "$bankCode - Disabled due to data source instability\n";

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

                    continue;

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

                $bank = new $bankClass();

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

                if (\in_array($bankCode, ['CBR'])) {

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

        }

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

        // @codeCoverageIgnoreEnd

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

                $this->assertNotEmpty($bank->getSource(), 'Bank source should be not empty');

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

            $this->markTestSkipped('Possibly connection error from integration:' . $e->getMessage());

There are no issues that match your filters.

Category
Status