Code clean up.

This commit is contained in:
James Cole
2017-11-15 12:25:49 +01:00
parent 57dcdfa0c4
commit ffca858b8d
476 changed files with 2055 additions and 4181 deletions

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
@@ -26,16 +25,13 @@ namespace FireflyIII\Import\Converter;
use Log;
/**
* Class RabobankDebetCredit
*
* @package FireflyIII\Import\Converter
* Class RabobankDebetCredit.
*/
class Amount implements ConverterInterface
{
/**
* Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
* - Jamie Zawinski
* - Jamie Zawinski.
*
*
* @param $value
@@ -46,7 +42,7 @@ class Amount implements ConverterInterface
*/
public function convert($value): string
{
if (is_null($value)) {
if (null === $value) {
return '0';
}
$value = strval($value);
@@ -56,35 +52,35 @@ class Amount implements ConverterInterface
$altPosition = $len - 2;
$decimal = null;
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
if (($len > 2 && '.' === $value[$decimalPosition]) || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
$decimal = '.';
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
}
if ($len > 2 && $value{$decimalPosition} === ',') {
if ($len > 2 && ',' === $value[$decimalPosition]) {
$decimal = ',';
Log::debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
}
// decimal character is null? find out if "0.1" or ".1" or "0,1" or ",1"
if ($len > 1 && ($value{$altPosition} === '.' || $value{$altPosition} === ',')) {
$decimal = $value{$altPosition};
if ($len > 1 && ('.' === $value[$altPosition] || ',' === $value[$altPosition])) {
$decimal = $value[$altPosition];
Log::debug(sprintf('Alternate search resulted in "%s" for decimal sign.', $decimal));
}
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
if ($decimal === '.') {
if ('.' === $decimal) {
$search = [',', ' '];
$oldValue = $value;
$value = str_replace($search, '', $value);
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
}
if ($decimal === ',') {
if (',' === $decimal) {
$search = ['.', ' '];
$oldValue = $value;
$value = str_replace($search, '', $value);
$value = str_replace(',', '.', $value);
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
}
if (is_null($decimal)) {
if (null === $decimal) {
// replace all:
$search = ['.', ' ', ','];
$oldValue = $value;

View File

@@ -18,21 +18,17 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
/**
* Interface ConverterInterface
*
* @package FireflyIII\Import\Converter
* Interface ConverterInterface.
*/
interface ConverterInterface
{
/**
* @param $value
*
*/
public function convert($value);
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
@@ -26,13 +25,10 @@ namespace FireflyIII\Import\Converter;
use Log;
/**
* Class INGDebetCredit
*
* @package FireflyIII\Import\Converter
* Class INGDebetCredit.
*/
class INGDebetCredit implements ConverterInterface
{
/**
* @param $value
*
@@ -42,7 +38,7 @@ class INGDebetCredit implements ConverterInterface
{
Log::debug('Going to convert ing debet credit', ['value' => $value]);
if ($value === 'Af') {
if ('Af' === $value) {
Log::debug('Return -1');
return -1;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
@@ -26,13 +25,10 @@ namespace FireflyIII\Import\Converter;
use Log;
/**
* Class RabobankDebetCredit
*
* @package FireflyIII\Import\Converter
* Class RabobankDebetCredit.
*/
class RabobankDebetCredit implements ConverterInterface
{
/**
* @param $value
*
@@ -42,7 +38,7 @@ class RabobankDebetCredit implements ConverterInterface
{
Log::debug('Going to convert ', ['value' => $value]);
if ($value === 'D') {
if ('D' === $value) {
Log::debug('Return -1');
return -1;