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\Object;
@@ -32,17 +31,17 @@ class ImportCurrency
{
/** @var array */
private $code = [];
/** @var TransactionCurrency */
/** @var TransactionCurrency */
private $currency;
/** @var array */
private $id = [];
/** @var array */
private $name = [];
/** @var CurrencyRepositoryInterface */
/** @var CurrencyRepositoryInterface */
private $repository;
/** @var array */
private $symbol = [];
/** @var User */
/** @var User */
private $user;
/**
@@ -59,14 +58,14 @@ class ImportCurrency
*/
public function getTransactionCurrency(): TransactionCurrency
{
if (!is_null($this->currency->id)) {
if (null !== $this->currency->id) {
return $this->currency;
}
Log::debug('In createCurrency()');
// check if any of them is mapped:
$mapped = $this->findMappedObject();
if (!is_null($mapped->id)) {
if (null !== $mapped->id) {
Log::debug('Mapped existing currency.', ['new' => $mapped->toArray()]);
$this->currency = $mapped;
@@ -74,7 +73,7 @@ class ImportCurrency
}
$searched = $this->findExistingObject();
if (!is_null($searched->id)) {
if (null !== $searched->id) {
Log::debug('Found existing currency.', ['found' => $searched->toArray()]);
$this->currency = $searched;
@@ -86,7 +85,7 @@ class ImportCurrency
'name' => $this->name['value'] ?? null,
'decimal_places' => 2,
];
if (is_null($data['code'])) {
if (null === $data['code']) {
Log::debug('Need at least a code to create currency, return nothing.');
return new TransactionCurrency();
@@ -97,7 +96,6 @@ class ImportCurrency
$this->currency = $currency;
Log::info('Made new currency.', ['input' => $data, 'new' => $currency->toArray()]);
return $currency;
}
@@ -156,11 +154,11 @@ class ImportCurrency
];
foreach ($search as $field => $function) {
$value = $this->$field['value'] ?? null;
if (!is_null($value)) {
if (null !== $value) {
Log::debug(sprintf('Searching for %s using function %s and value %s', $field, $function, $value));
$currency = $this->repository->$function($value);
if (!is_null($currency->id)) {
if (null !== $currency->id) {
return $currency;
}
}
@@ -181,7 +179,7 @@ class ImportCurrency
Log::debug(sprintf('Find mapped currency based on field "%s" with value', $field), $array);
// check if a pre-mapped object exists.
$mapped = $this->getMappedObject($array);
if (!is_null($mapped->id)) {
if (null !== $mapped->id) {
Log::debug(sprintf('Found currency #%d!', $mapped->id));
return $mapped;
@@ -200,13 +198,13 @@ class ImportCurrency
private function getMappedObject(array $array): TransactionCurrency
{
Log::debug('In getMappedObject()');
if (count($array) === 0) {
if (0 === count($array)) {
Log::debug('Array is empty, nothing will come of this.');
return new TransactionCurrency;
}
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
return new TransactionCurrency;
@@ -217,8 +215,7 @@ class ImportCurrency
$search = intval($array['mapped']);
$currency = $this->repository->find($search);
if (is_null($currency->id)) {
if (null === $currency->id) {
Log::error(sprintf('There is no currency with id #%d. Invalid mapping will be ignored!', $search));
return new TransactionCurrency;