Function getRates
has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- 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 getRates
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
The method getRates() has an NPath complexity of 42336. The configured NPath complexity threshold is 200. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- 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 getRates() has 113 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Exclude checks
The method getRates() has a Cyclomatic Complexity of 29. The configured cyclomatic complexity threshold is 10. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- 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
Refactor this function to reduce its Cognitive Complexity from 74 to the 15 allowed. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The method getRates has a boolean flag argument $cron, which is a certain sign of a Single Responsibility Principle violation. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class 'Settings_CurrencyUpdate_Module_Model' in method 'getRates'. 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
Avoid using static access to class '\App\Fields\Currency' in method 'getRates'. 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
The method getRates uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$moduleModel->addCurrencyRate($mainCurrencyId, $datePublicationOfFile, $exchange, $selectedBank);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method getRates uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$moduleModel->addCurrencyRate($currId, $datePublicationOfFile, $exchange, $selectedBank);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Settings_CurrencyUpdate_Module_Model' in method 'getSupportedCurrencies'. Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($currencyCode)] = $currencyCode;
- 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 'vtlib\Functions' in method 'getRates'. Open
$lastWorkingDay = vtlib\Functions::getLastWorkingDay($yesterday);
- 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
The method getRates uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$sourceURL = $source[0];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Settings_CurrencyUpdate_Module_Model' in method 'getSupportedCurrencies'. Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($this->getMainCurrencyCode())] = $this->getMainCurrencyCode();
- 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
Define a constant instead of duplicating this literal "currency" 3 times. Open
$currencyCode = (string) $currency['currency'];
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Expected @param annotation for dateParam
to be before the @param annotation for cron
Open
* @param bool $cron - if true then it is fired by server and crms currency conversion rates are updated
- Exclude checks
Reference to instance property Cube
from undeclared class \SimpleXMLElement
Open
foreach ($XML->Cube->Cube as $time) {
- Exclude checks
Saw unextractable annotation for comment '* @param <date> $date - date for which exchange is fetched'</date>
Open
* @param <Date> $date - date for which exchange is fetched
- Exclude checks
Reference to instance property Cube
from undeclared class \SimpleXMLElement
Open
foreach ($XML->Cube->Cube as $time) {
- Exclude checks
Saw unextractable annotation for comment '* @param <array> $currencies - list of systems active currencies'</array>
Open
* @param <Array> $currencies - list of systems active currencies
- Exclude checks
Reference to instance property Cube
from undeclared class \SimpleXMLElement
Open
foreach ($XML->Cube->Cube[0] as $currency) {
- Exclude checks
Similar blocks of code found in 4 locations. Consider refactoring. Open
if ($mainCurrencyId) {
if (true === $cron || ((strtotime($dateParam) == strtotime($today)) || (strtotime($dateParam) == strtotime($lastWorkingDay)))) {
$moduleModel->setCRMConversionRate($this->getMainCurrencyCode(), $yfRate);
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 137.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $datePublicationOfFile. Keep variable name length under 20. Open
$datePublicationOfFile = $dateParam;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_CurrencyUpdate_ECB_BankModel extends Settings_CurrencyUpdate_AbstractBank_Model
- Exclude checks
The class Settings_CurrencyUpdate_ECB_BankModel is not named in CamelCase. Open
class Settings_CurrencyUpdate_ECB_BankModel extends Settings_CurrencyUpdate_AbstractBank_Model
{
// Returns bank name
public function getName()
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Spaces must be used to indent lines; tabs are not allowed Open
return 'ECB';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($this->getMainCurrencyCode())] = $this->getMainCurrencyCode();
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($this->getMainCurrencyCode())] = $this->getMainCurrencyCode();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
- 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
Line exceeds 120 characters; contains 122 characters Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($currencyCode)] = $currencyCode;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param <Array> $currencies - list of systems active currencies
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
return ['https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml', 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml'];
- 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
* Fetch exchange rates.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Returns url sources from where exchange rates are taken from
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Returns list of currencies supported by this bank
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$supportedCurrencies = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $otherCurrencyCode
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$source = $this->getSource();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currencyCode = (string) $currency['currency'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($currencyCode)] = $currencyCode;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param <Date> $date - date for which exchange is fetched
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// source, ECB has 2 sources for older rates
- 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
$XML = simplexml_load_file($source[0]);
- 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
$selectedBank = $moduleModel->getActiveBankId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lastWorkingDay = vtlib\Functions::getLastWorkingDay($yesterday);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mainCurrency = \App\Fields\Currency::getDefault()['currency_code'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getSource()
- 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 'EUR';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $supportedCurrencies;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$today = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// 0 - last 90 days
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($XML->Cube->Cube[0] as $currency) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getMainCurrencyCode()
- 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 bool $cron - if true then it is fired by server and crms currency conversion rates are updated
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Returns bank name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$source = $this->getSource();
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
* @param bool $cron - if true then it is fired by server and crms currency conversion rates are updated
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// we speed script choosing the smaller file for our needs
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rateDay = strtotime($dateParam);
- Exclude checks
Line exceeds 120 characters; contains 156 characters Open
if (true === $cron || ((strtotime($dateParam) == strtotime($today)) || (strtotime($dateParam) == strtotime($lastWorkingDay)))) {
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getName()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getSupportedCurrencies()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// check if data is correct, currency rates can be retrieved only for working days
- 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 ($foundRate) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($key == $currency && $currency != $mainCurrency) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mainCurrencyId = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml', 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Returns banks main currency
- 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
foreach ($otherCurrencyCode as $key => $currId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exchangeVtiger = (float) $exchange / (float) $exchangeRate;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->setCRMConversionRate($currency, $exchangeVtiger);
- 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
// currency diffrent than EUR, we need to add manually EUR rates
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($existingId > 0) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->addCurrencyRate($mainCurrencyId, $datePublicationOfFile, $exchange, $selectedBank);
- 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
$foundRate = false;
- 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
foreach ($XML->Cube->Cube as $time) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
for ($i = 0; $i < $num; ++$i) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currency = (string) $time->Cube[$i]['currency']; // currency code
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exchange = $time->Cube[$i]['rate'];
- 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
break;
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
if (true === $cron || ((strtotime($dateParam) == strtotime($today)) || (strtotime($dateParam) == strtotime($lastWorkingDay)))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->updateCurrencyRate($existingId, $exchange);
- 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
$foundRate = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->setCRMConversionRate($this->getMainCurrencyCode(), $yfRate);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($mainCurrency != $this->getMainCurrencyCode()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $dateParam
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// 1 - historical data from year 1999
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// how old is the currency rate
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$datediff = $now - $rateDay;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (floor($datediff / (60 * 60 * 24)) >= 90) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$datePublicationOfFile = $dateParam;
- 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
if ($code == $this->getMainCurrencyCode()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (true === $cron || ((strtotime($dateParam) == strtotime($today)) || (strtotime($dateParam) == strtotime($lastWorkingDay)))) {
- 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 (false === $XML) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($time->Cube as $rate) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exchangeRate = $rate['rate'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$existingId = $moduleModel->getCurrencyRateId($currId, $datePublicationOfFile, $selectedBank);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($foundRate) {
- 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
$now = time(); // or your date as well
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($mainCurrency != $this->getMainCurrencyCode()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (true === $cron || ((strtotime($dateParam) == strtotime($today)) || (strtotime($dateParam) == strtotime($lastWorkingDay)))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($otherCurrencyCode as $code => $id) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceURL = $source[1];
- 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
$num = \count($time->Cube);
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$existingId = $moduleModel->getCurrencyRateId($currId, $datePublicationOfFile, $selectedBank);
- 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 false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$foundRate = true;
- 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
$exchange = (float) $exchangeRate;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($foundRate) {
- 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
$mainCurrencyId = $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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$foundRate = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->addCurrencyRate($currId, $datePublicationOfFile, $exchange, $selectedBank);
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($XML->Cube->Cube as $time) {
- 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 ($time['time'] == $dateParam) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($existingId > 0) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$yfRate = 1.00000 / (float) $exchangeRate;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$existingId = $moduleModel->getCurrencyRateId($mainCurrencyId, $datePublicationOfFile, $selectedBank);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceURL = $source[0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$XML = simplexml_load_file($sourceURL); // European Central Bank xml only contains business days! oh well....
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// if currency is diffrent than EUR we need to calculate rate for converting other currencies to this one from EUR
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
// if currency is diffrent than EUR we need to calculate rate for converting other currencies to this one from EUR
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($rate['currency'] == $mainCurrency) {
- 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
$moduleModel->updateCurrencyRate($existingId, $exchange);
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$moduleModel->addCurrencyRate($currId, $datePublicationOfFile, $exchange, $selectedBank);
- 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
$exchangeRate = 1.0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($time['time'] == $dateParam) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exchange = (float) $exchangeRate / (float) $exchange;
- 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 ($mainCurrencyId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Settings_CurrencyUpdate_ECB_BankModel" is not in camel caps format Open
class Settings_CurrencyUpdate_ECB_BankModel extends Settings_CurrencyUpdate_AbstractBank_Model
- Exclude checks
The variable $XML is not named in camelCase. Open
public function getSupportedCurrencies()
{
$supportedCurrencies = [];
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($this->getMainCurrencyCode())] = $this->getMainCurrencyCode();
$source = $this->getSource();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $XML is not named in camelCase. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $XML is not named in camelCase. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $XML is not named in camelCase. Open
public function getSupportedCurrencies()
{
$supportedCurrencies = [];
$supportedCurrencies[Settings_CurrencyUpdate_Module_Model::getCRMCurrencyName($this->getMainCurrencyCode())] = $this->getMainCurrencyCode();
$source = $this->getSource();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $XML is not named in camelCase. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $XML is not named in camelCase. Open
public function getRates($otherCurrencyCode, $dateParam, $cron = false)
{
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
$selectedBank = $moduleModel->getActiveBankId();
$yesterday = date('Y-m-d', strtotime('-1 day'));
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}