Skip to content

Commit

Permalink
codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterjan.eilers committed Aug 19, 2024
1 parent 4b3bd8d commit c099919
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 173 deletions.
14 changes: 10 additions & 4 deletions modules/registrars/realtimeregister/additionalfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
$tlds = [];

if (isset($_SESSION['cart']['domains'])) {
$tlds = array_map(function ($domain) { return MetadataService::getTld($domain['domain']); }, $_SESSION['cart']['domains']);
$tlds = array_map(
function ($domain) {
return MetadataService::getTld($domain['domain']);
}, $_SESSION['cart']['domains']
);
}

if (!empty($_POST['domain']) && is_string($_POST['domain'])) {
Expand Down Expand Up @@ -56,9 +60,11 @@
$fields = $additional['fields'] ?? [];

if ($tld !== 'aero') {
$fields = array_filter($fields, function ($field) {
return !in_array($field['Name'], ['AeroId', 'AeroKey']);
});
$fields = array_filter(
$fields, function ($field) {
return !in_array($field['Name'], ['AeroId', 'AeroKey']);
}
);
}

if (empty($fields)) {
Expand Down
3 changes: 2 additions & 1 deletion modules/registrars/realtimeregister/src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected function metadata(Request $request): TLDMetaData
return (new MetadataService($request->domain->tld))->getMetadata();
}

protected function tldInfo(Request $request) : TLDInfo {
protected function tldInfo(Request $request) : TLDInfo
{
return (new MetadataService($request->domain->tld))->getAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ public function __invoke(Request $request): array
{
$domain = $this->domainInfo($request);

$handles = json_encode([
$handles = json_encode(
[
ContactModel::ROLE_REGISTRANT => $this->fetchId($domain, DomainContactRoleEnum::ROLE_REGISTRANT),
ContactModel::ROLE_ADMIN => $this->fetchId($domain, DomainContactRoleEnum::ROLE_ADMIN),
ContactModel::ROLE_TECH => $this->fetchId($domain, DomainContactRoleEnum::ROLE_TECH),
ContactModel::ROLE_BILLING => $this->fetchId($domain, DomainContactRoleEnum::ROLE_BILLING)
]);
]
);

App::assets()->prependHead("<script>let contact_ids = $handles;</script>");

return array_filter([
return array_filter(
[
ContactModel::ROLE_REGISTRANT => $this->fetchContact($domain, DomainContactRoleEnum::ROLE_REGISTRANT),
ContactModel::ROLE_ADMIN => $this->fetchContact($domain, DomainContactRoleEnum::ROLE_ADMIN),
ContactModel::ROLE_TECH => $this->fetchContact($domain, DomainContactRoleEnum::ROLE_TECH),
ContactModel::ROLE_BILLING => $this->fetchContact($domain, DomainContactRoleEnum::ROLE_BILLING)
]);
]
);
}

protected function fetchId(DomainDetails $domain, string $role): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public function __invoke(Request $request)
$key = $role === DomainContactRoleEnum::ROLE_REGISTRANT
? 'registrant' : sprintf('%sContacts', strtolower($role));

/** @var bool $organizationAllowed */
/**
* @var bool $organizationAllowed
*/
$organizationAllowed = $metadata->{$key}->organizationAllowed;

$currentHandle = $domain->registrant;
Expand All @@ -63,9 +65,11 @@ public function __invoke(Request $request)
);
if ($request->input('wc.' . $whmcsRole) === 'custom') {
if (App::contacts()->handleHasMapping($currentHandle)) {
DB::transaction(function () use ($request) {
App::localApi()->createContact();
});
DB::transaction(
function () use ($request) {
App::localApi()->createContact();
}
);

// First create a new contact in whmcs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ public function __invoke(Request $request)

$searchResult = new SearchResult($request->get('searchTerm'), $tld);

$searchResult->setStatus(match ($result->getStatus()) {
$searchResult->setStatus(
match ($result->getStatus()) {
IsProxyDomain::STATUS_AVAILABLE => SearchResult::STATUS_NOT_REGISTERED,
IsProxyDomain::STATUS_NOT_AVAILABLE => SearchResult::STATUS_REGISTERED,
default => SearchResult::STATUS_UNKNOWN
});
}
);

$extra = $result->getExtras();

if (isset($extra['type'], $extra['price'], $extra['currency']) && $extra['type'] === 'premium') {
$searchResult->setPremiumDomain(true);
$searchResult->setPremiumCostPricing([
$searchResult->setPremiumCostPricing(
[
'register' => number_format(($extra['price'] / 100), 2, '.', ''),
'renew' => number_format(($extra['price'] / 100), 2, '.', ''),
'CurrencyCode' => $extra['currency']
]);
]
);
}

$results->append($searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
use SandwaveIo\RealtimeRegister\Domain\TLDInfo;
use SandwaveIo\RealtimeRegister\Domain\TLDMetaData;

trait DomainContactTrait {
trait DomainContactTrait
{

/**
* Add properties to contact if necessary
* @param Request $request
* @param string $handle
* @param TLDInfo $tldInfo
*
* @param Request $request
* @param string $handle
* @param TLDInfo $tldInfo
* @return void
*/

protected static function addProperties(Request $request, string $handle, TLDInfo $tldInfo): void
{
$customer = App::registrarConfig()->customerHandle();
Expand All @@ -38,7 +39,7 @@ protected static function addProperties(Request $request, string $handle, TLDInf
}

/**
* @param MetadataService $metadata
* @param MetadataService $metadata
* @return array
*/
protected static function getNewProperties(Request $request, TLDMetaData $metadata) : array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ protected function getDomainNameservers(array $params, string $type = 'register'
}
}

return array_merge($params, [
return array_merge(
$params, [
'ns1' => Configuration::query()->where('setting', 'DefaultNameserver1')->value('value'),
'ns2' => Configuration::query()->where('setting', 'DefaultNameserver2')->value('value'),
'ns3' => Configuration::query()->where('setting', 'DefaultNameserver3')->value('value'),
'ns4' => Configuration::query()->where('setting', 'DefaultNameserver4')->value('value'),
'ns5' => Configuration::query()->where('setting', 'DefaultNameserver5')->value('value')
]);
]
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __invoke(Request $request)
}

/**
* @param \SandwaveIo\RealtimeRegister\Domain\DomainDetails $domain
* @param \SandwaveIo\RealtimeRegister\Domain\DomainDetails $domain
* @return string
*/
public function getWhmcsDomainStatus(\SandwaveIo\RealtimeRegister\Domain\DomainDetails $domain): string
Expand All @@ -66,7 +66,7 @@ public function getWhmcsDomainStatus(\SandwaveIo\RealtimeRegister\Domain\DomainD
}

/**
* @param string $handle
* @param string $handle
* @return bool
*/
public function hasPendingChanges(string $handle): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function __invoke(Request $request): array|string
];
}

/** @var DomainRegistration $registeredDomain */
/**
* @var DomainRegistration $registeredDomain
*/
$registeredDomain = App::client()->domains->register(
domainName: $request->domain->domainName(),
customer: App::registrarConfig()->customerHandle(),
Expand All @@ -97,7 +99,9 @@ private function buildBillables(DomainQuote $quote): array
{
$billables = [];
if (!empty($quote->quote->billables) && $quote->quote->billables->count() > 1) {
/** @var Billable $billable */
/**
* @var Billable $billable
*/
foreach ($quote->quote->billables as $billable) {
$billables[] = [
'action' => $billable->action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function __invoke(Request $request)

$status = WhmcsDomainStatus::fromDomainDetails($domain);

if (
!in_array($status, [WhmcsDomainStatus::Active, WhmcsDomainStatus::Expired, WhmcsDomainStatus::Redemption])
if (!in_array($status, [WhmcsDomainStatus::Active, WhmcsDomainStatus::Expired, WhmcsDomainStatus::Redemption])
) {
throw new Exception(sprintf("Domain status %s", $status->value));
}
Expand All @@ -72,8 +71,7 @@ protected function syncDueDate(string $date): string

protected function parseDomainStatus(array $statuses): string
{
if (
array_intersect([DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], $statuses)
if (array_intersect([DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD], $statuses)
) {
return 'Fraud';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function __invoke(Request $request)
$pricesSLD = [];

if (App::registrarConfig()->customerHandle() !== '') {
/** @var Price $priceItem */
/**
* @var Price $priceItem
*/
foreach (App::client()->customers->priceList(App::registrarConfig()->customerHandle()) as $priceItem) {
if (!str_starts_with($priceItem->product, "domain_")) {
continue;
Expand Down
100 changes: 53 additions & 47 deletions modules/registrars/realtimeregister/src/Assets/Js/checkCredentials.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
$(document).ready(function () {
const moduleName = 'realtimeregister';
// Container
const config_container = $('#' + moduleName + 'config');
$(document).ready(
function () {
const moduleName = 'realtimeregister';
// Container
const config_container = $('#' + moduleName + 'config');

// Credentials
const handleField = config_container.find('[name="customer_handle"]');
const apiField = config_container.find('[name="rtr_api_key"]');
const oteField = config_container.find('[type="checkbox"][name="test_mode"]');
const ignoreSslField = config_container.find('[type="checkbox"][name="ignore_ssl"]');
// Credentials
const handleField = config_container.find('[name="customer_handle"]');
const apiField = config_container.find('[name="rtr_api_key"]');
const oteField = config_container.find('[type="checkbox"][name="test_mode"]');
const ignoreSslField = config_container.find('[type="checkbox"][name="ignore_ssl"]');

config_container.on('click', '.check-connection', function (e) {
e.preventDefault();
config_container.on(
'click', '.check-connection', function (e) {
e.preventDefault();

const btn = $(this);
const text = btn.html();
const result = config_container.find('.credentials-result');
const btn = $(this);
const text = btn.html();
const result = config_container.find('.credentials-result');

btn.css({'width': btn.outerWidth()});
btn.html("<i class=\"fa fa-spin fa-spinner\"></i>");
btn.addClass("disabled");
btn.attr("disabled", "disabled");
$.post(
window.location.href,
{
action: 'checkConnection',
module: moduleName,
handle: handleField.val(),
apiKey: apiField.val(),
ote: oteField.is(":checked"),
ignore_ssl: ignoreSslField.is(":checked"),
},
function (response) {
btn.html(text);
btn.removeClass("disabled");
if (response.connection === "true") {
result.html('<span class="status success">SUCCESSFUL</span>');
} else {
result.html('<span class="status error"><strong>FAILED:</strong> ' + response.msg + '</span>');
}
btn.attr("disabled", false);
},
"json"
).fail(function (e) {
btn.html(text);
btn.removeClass("disabled");
btn.attr("disabled", false);
result.html('<span class="status error"><strong>FAILED:</strong> Something went wrong!</span>');
});
});
});
btn.css({'width': btn.outerWidth()});
btn.html("<i class=\"fa fa-spin fa-spinner\"></i>");
btn.addClass("disabled");
btn.attr("disabled", "disabled");
$.post(
window.location.href,
{
action: 'checkConnection',
module: moduleName,
handle: handleField.val(),
apiKey: apiField.val(),
ote: oteField.is(":checked"),
ignore_ssl: ignoreSslField.is(":checked"),
},
function (response) {
btn.html(text);
btn.removeClass("disabled");
if (response.connection === "true") {
result.html('<span class="status success">SUCCESSFUL</span>');
} else {
result.html('<span class="status error"><strong>FAILED:</strong> ' + response.msg + '</span>');
}
btn.attr("disabled", false);
},
"json"
).fail(
function (e) {
btn.html(text);
btn.removeClass("disabled");
btn.attr("disabled", false);
result.html('<span class="status error"><strong>FAILED:</strong> Something went wrong!</span>');
}
);
}
);
}
);
6 changes: 4 additions & 2 deletions modules/registrars/realtimeregister/src/Entities/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public static function fromWhmcs(array $params): static
return new static(
name: $params['sld'],
tld: $params['tld'],
nameservers: array_filter([
nameservers: array_filter(
[
$params['ns1'] ?? null,
$params['ns2'] ?? null,
$params['ns3'] ?? null,
$params['ns4'] ?? null,
$params['ns5'] ?? null,
]),
]
),
registrant: Contact::fromWhmcs(ContactType::Registrant, $params),
admin: Contact::fromWhmcs(ContactType::Admin, $params),
tech: Contact::fromWhmcs(ContactType::Tech, $params),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ protected function getRegistrarConfig(string $key, $default = null)
protected function loadRegistrarConfig(): void
{
if ($this->registrarConfig === null) {
/** @noinspection PhpUndefinedConstantInspection */
require_once ROOTDIR . "/includes/registrarfunctions.php";
/**
* @noinspection PhpUndefinedConstantInspection
*/
include_once ROOTDIR . "/includes/registrarfunctions.php";
$this->registrarConfig = array_merge(
[
'SyncStatus' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ enum WhmcsDomainStatus: string

public static function fromDomainDetails(DomainDetails $domain): WhmcsDomainStatus
{
if (
array_intersect(
[DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD],
$domain->status
)
if (array_intersect(
[DomainStatusEnum::STATUS_SERVER_HOLD, DomainStatusEnum::STATUS_REGISTRAR_HOLD],
$domain->status
)
) {
return self::Fraud;
}
Expand Down
Loading

0 comments on commit c099919

Please sign in to comment.