Skip to content

Commit

Permalink
CS fixer and rector
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Apr 13, 2021
1 parent 4640878 commit 8fe6b05
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 45 deletions.
8 changes: 3 additions & 5 deletions Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
],
'mautic.form.validation.inttel.subscriber' => [
'class' => \MauticPlugin\MauticInternationalPhoneInputBundle\EventListener\FormValidationSubscriber::class,
'arguments' => [
'arguments' => [
'translator',
'request_stack'
]
'request_stack',
],
],
],
'forms' => [
Expand All @@ -38,7 +38,6 @@
],
],
'models' => [

],
'integrations' => [
'mautic.integration.internationalphoneinput' => [
Expand Down Expand Up @@ -74,6 +73,5 @@
],
],
'parameters' => [

],
];
9 changes: 3 additions & 6 deletions Controller/JsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class JsController extends CommonController

/**
* PublicController constructor.
*
* @param IpLookupHelper $ipLookupHelper
* @param AssetsHelper $assetsHelper
*/
public function __construct(IpLookupHelper $ipLookupHelper, AssetsHelper $assetsHelper)
{
Expand All @@ -50,10 +47,10 @@ public function generateCountryCodeAction($formName)
{
$ip = $this->ipLookupHelper->getIpAddress();
include_once __DIR__.'/../countries.php';
$country = ArrayHelper::getValue('country', $ip->getIpDetails() ?? []);
$countryCode = array_search(strtolower($country), array_map('strtolower', $countries)); ## easy version
$country = ArrayHelper::getValue('country', $ip->getIpDetails() ?? []);
$countryCode = array_search(strtolower($country), array_map('strtolower', $countries)); //# easy version
$realFormName = ltrim($formName, '_');
$utilsUrl = $this->assetsHelper->getUrl('plugins/MauticInternationalPhoneInputBundle/Assets/lib/js/utils.js', null, null, true
$utilsUrl = $this->assetsHelper->getUrl('plugins/MauticInternationalPhoneInputBundle/Assets/lib/js/utils.js', null, null, true
);
$js = <<<JS
if(!window.{$formName}){
Expand Down
15 changes: 4 additions & 11 deletions EventListener/FormSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ class FormSubscriber implements EventSubscriberInterface
protected $secretKey;

/**
* @var boolean
* @var bool
*/
private $internationalphoneinputIsConfigured = false;

/**
* @param IntegrationHelper $integrationHelper
*/
public function __construct(
IntegrationHelper $integrationHelper
) {
$integrationObject = $integrationHelper->getIntegrationObject(InternationalPhoneInputIntegration::INTEGRATION_NAME);
if ($integrationObject instanceof AbstractIntegration && $integrationObject->getIntegrationSettings()->getIsPublished()) {
$this->internationalphoneinputIsConfigured = true;
$this->internationalphoneinputIsConfigured = true;
}
}

Expand All @@ -56,26 +53,22 @@ public function __construct(
public static function getSubscribedEvents()
{
return [
FormEvents::FORM_ON_BUILD => ['onFormBuild', 0],
FormEvents::FORM_ON_BUILD => ['onFormBuild', 0],
InternationalPhoneInputEvents::ON_FORM_VALIDATE => ['onFormValidate', 0],
];
}

/**
* @param FormBuilderEvent $event
*/
public function onFormBuild(FormBuilderEvent $event)
{
if (!$this->internationalphoneinputIsConfigured) {
return;
}
$event->addFormField(self::FIELD_NAME, [
'label' => 'mautic.plugin.actions.internationalphoneinput',
'formType' => InternationalPhoneInputType::class,
'formType' => InternationalPhoneInputType::class,
'template' => 'MauticInternationalPhoneInputBundle:Integration:internationalphoneinput.html.php',
'builderOptions' => [
],
]);

}
}
17 changes: 4 additions & 13 deletions EventListener/FormValidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

class FormValidationSubscriber implements EventSubscriberInterface
{

/**
* @var TranslatorInterface
*/
Expand All @@ -37,10 +36,9 @@ class FormValidationSubscriber implements EventSubscriberInterface
public function __construct(TranslatorInterface $translator, RequestStack $requestStack)
{
$this->translator = $translator;
$this->request = $requestStack->getCurrentRequest();
$this->request = $requestStack->getCurrentRequest();
}


/**
* {@inheritdoc}
*/
Expand All @@ -54,8 +52,6 @@ public static function getSubscribedEvents()

/**
* Add a simple email form.
*
* @param Events\FormBuilderEvent $event
*/
public function onFormBuilder(Events\FormBuilderEvent $event)
{
Expand All @@ -71,15 +67,13 @@ public function onFormBuilder(Events\FormBuilderEvent $event)

/**
* Custom validation *.
*
*@param Events\ValidationEvent $event
*/
public function onFormValidate(Events\ValidationEvent $event)
{
$field = $event->getField();
$phoneNumber = $event->getValue();
$field = $event->getField();
$phoneNumber = $event->getValue();
$fullPhoneNumber = ArrayHelper::getValue($field->getAlias(), $this->request ? $this->request->request->get('mauticform') : []);
if (!empty($phoneNumber) && $field->getType() === FormSubscriber::FIELD_NAME && !empty($field->getValidation()['international'])) {
if (!empty($phoneNumber) && FormSubscriber::FIELD_NAME === $field->getType() && !empty($field->getValidation()['international'])) {
$phoneUtil = PhoneNumberUtil::getInstance();
try {
$parsedPhone = $phoneUtil->parse($fullPhoneNumber, PhoneNumberUtil::UNKNOWN_REGION);
Expand All @@ -92,9 +86,6 @@ public function onFormValidate(Events\ValidationEvent $event)
}
}

/**
* @param Events\ValidationEvent $event
*/
private function setFailedValidation(Events\ValidationEvent $event)
{
$field = $event->getField();
Expand Down
5 changes: 0 additions & 5 deletions Form/Type/InternationalPhoneInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@

class InternationalPhoneInputType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
}


/**
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions Views/Integration/internationalphoneinput.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
echo str_replace('<input', '<input data-field-alias="'.$field['alias'].'"', $input);
$elementId = 'mauticform_input'.$formName.'_'.$field['alias'];

if(!$inBuilder) {
if (!$inBuilder) {
echo <<<HTML
<link rel="stylesheet" href="{$view['assets']->getUrl(
'plugins/MauticInternationalPhoneInputBundle/Assets/lib/css/intlTelInput.min.css',
Expand All @@ -49,4 +49,4 @@
true
)}"></script>
HTML;
}
}
5 changes: 2 additions & 3 deletions countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
*
* Do not modify this file directly!
*/

$countries = array (
$countries = [
'AC' => 'Ascension Island',
'AD' => 'Andorra',
'AE' => 'United Arab Emirates',
Expand Down Expand Up @@ -263,4 +262,4 @@
'ZA' => 'South Africa',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
);
];

0 comments on commit 8fe6b05

Please sign in to comment.