- Issue created by @shashank5563
- Assigned to shashank5563
- Assigned to Nishant
- 🇮🇹Italy apaderno Brescia, 🇮🇹
Actually, this issue is about dependency injection, not coding standards.
- @nishant opened merge request.
- Status changed to Needs review
over 1 year ago 12:00pm 18 May 2023 - Issue was unassigned.
- Status changed to Needs work
over 1 year ago 4:59pm 18 May 2023 - 🇮🇹Italy apaderno Brescia, 🇮🇹
+ /** + * Config Factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Messenger. + * + * @var \Drupal\Core\Messenger\Messenger + */ + protected $messenger; + + /** + * Logger. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected $loggerFactory;
The descriptions are each missing a definite article.
+ * Class Constructor. + * @param \Drupal\Core\Config\ConfigFactory $configFactory + * Config Factory. + * @param \Drupal\Core\Messenger\Messenger $messenger + * Messenger. + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory + * Logger. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack.
The description for a constructor must start with
Constructs a new
followed by the class name (including its namespace), and end withobject.
There must be an empty line between the short description and the list of parameters.+ public function __construct( + ConfigFactory $configFactory, + Messenger $messenger, + LoggerChannelFactoryInterface $loggerFactory, + RequestStack $request_stack + ) { + $this->configFactory = $configFactory; + $this->messenger = $messenger; + $this->loggerFactory = $loggerFactory; + $this->requestStack = $request_stack; + }
Method declarations are written on a single line.
+ public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('messenger'), + $container->get('logger.factory'), + $container->get('request_stack') + ); + }
As per Drupal coding standards, indentation is two spaces.
- Assigned to Nishant
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 9:04am 19 May 2023 - 🇮🇳India Nishant
@apaderno,
Pushed the latest changes as per your comment, Also I have run phpcbf commands to fix some automatic changes. Please review.
- Status changed to Needs work
over 1 year ago 10:52am 19 May 2023 - 🇮🇹Italy apaderno Brescia, 🇮🇹
+ /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\Messenger + */ + protected $messenger;
In both the cases, there is no need to say it is a service.
+ /** + * A logger instance. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected $loggerFactory; +
It is sufficient to say The logger.
+ /** + * Constructs a new AutoWebhook object. + * + * @param \Drupal\Core\Config\ConfigFactory $configFactory + * Config Factory. + * @param \Drupal\Core\Messenger\Messenger $messenger + * Messenger. + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory + * Logger.
The class name is missing the namespace.
The parameter descriptions are each missing a definite article.+ protected $supportedWebhookEvents = [ + 'payment.authorized' => TRUE, + 'payment.failed' => TRUE, + 'refund.created' => TRUE ];
The indentation is not correct. Anyway, since this issue is for using dependency injection where possible, that change is off-topic.
+ protected function generateWebhookSecret() { + $alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz'; - return substr(str_shuffle($alphanumericString), 0, 20); - } + return substr(str_shuffle($alphanumericString), 0, 20); + }
This change is not replacing calls to
\Drupal
methods, and it is off-topic.+ /** + * Constructs a new RazorpayCheckout object.
The class namespace is missing.
+ $form['display_label']['#prefix'] = 'First <a href="https://easy.razorpay.com/onboarding?recommended_product=payment_gateway&source=drupal" target="_blank">signup</a> for a Razorpay account or + <a href="https://dashboard.razorpay.com/signin?screen=sign_in&source=drupal" target="_blank">login</a> if you have an existing account.</p>';
Strings shown in the user interface must be translatable.
+ /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + parent::validateConfigurationForm($form, $form_state); + + if ($form_state->getErrors()) { + return;
+ public function onReturn(OrderInterface $order, Request $request) { + $keyId = $this->configuration['key_id']; + $keySecret = $this->configuration['key_secret']; + $api = new Api($keyId, $keySecret); + + // Validate Rzp signature. + try { + $attributes = [ + 'razorpay_order_id' => $request->get('razorpay_order_id'), + 'razorpay_payment_id' => $request->get('razorpay_payment_id'), + 'razorpay_signature' => $request->get('razorpay_signature')
None of those lines have been changed to avoid calls to
\Drupal
methods.+ if (substr($values['key_id'], 0, 8) !== 'rzp_' . $values['mode']) { + $this->messenger()->addError($this->t('Invalid Key ID or Key Secret for ' . $values['mode'] . ' mode.')); + $form_state->setError($form['mode']);
Translatable strings must use placeholders.
- First commit to issue fork.
- Status changed to Needs review
over 1 year ago 11:35am 19 May 2023 - Status changed to Needs work
over 1 year ago 3:29pm 19 May 2023 - 🇮🇹Italy apaderno Brescia, 🇮🇹
Also, the MR changes three files, but the issue summary says four files should be changed.
- 🇮🇳India Nishant
Hi @apaderno,
I have fixed all the dependency injection related issues raised by you.
Please review.Thanks
- Status changed to Needs review
over 1 year ago 11:30am 22 May 2023 - Status changed to Needs work
over 1 year ago 1:24pm 22 May 2023 - Status changed to Needs review
over 1 year ago 10:31am 24 May 2023