Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add or improve logs #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add or improve logs #157

wants to merge 1 commit into from

Conversation

netojoaobatista
Copy link
Contributor

This add or improve existing logs

@AleBark
Copy link

AleBark commented Nov 8, 2021

@netojoaobatista thanks for your PR, I noticed some points that I believe we could improve for better future maintenance, here they are:

  • In most validators, there's a list of available currencies in each scope, how about creating a centralization mechanism, and then only invoking it in these validators? I believe that an Enum would make it much easier in case of adding new currencies to these validators in the future.

  • Also, some validation methods have a try-catch and others use simple if logic in a variable called $isValid, is there any reason for this? I think it would be nice, if possible, to also standardize the validation methods.

  • In case the last scenario is not possible, I think it is possible to simplify the validation code, instead of testing the $isValid variable more than once, something like this could be done:

Taken from CountryValidator.php

public function validate(array $validationSubject)
    {
        $available_currencies = ['COP','USD','EUR']; //This could be in a Enum class

        $isValid =
            $validationSubject['country'] == 'CO'
            && in_array($this->storeManager->getStore()->getBaseCurrencyCode(), $available_currencies);

        if(!$isValid){
            $this->_logger->info('Country is not CO or the store base currency is not in the available currencies');
        }

        return $this->createResult($isValid);
    }

..or even better, separate isValid logic to a separate function, should work fine as well

  • This one is not related to the PR itself, but I noticed it when I was reading the updates on PaymentDataBuilder.php
if(isset($additionalData[DataAssignObserver::USE_SAVED_CC]) && $additionalData[DataAssignObserver::USE_SAVED_CC] && $this->_session->getQuote()->getCustomerId()){}

could be replaced with:

 if(!empty($additionalData[DataAssignObserver::USE_SAVED_CC]) && $this->_session->getQuote()->getCustomerId())

There are some files in this PR that could be a little more succinct with this change

  • There are some files that are "coming up" with commented lines, could you remove those lines, please?
    Example: // $this->_logger->info('AuthorizationHandler :: response', [$response['payment_result']]);

Copy link

@AleBark AleBark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion are commented above

@netojoaobatista
Copy link
Contributor Author

The suggestions are good, but out of the scope of this PR. A new PR for the validators will be made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants