Skip to content

Commit

Permalink
Fix multi-line function calls
Browse files Browse the repository at this point in the history
- opening parenthesis at end of line
- one argument per line
- closing parenthesis on own line
- indentation fixes
- spaces after closing parenthesis before an opening parenthesis
- some issue fixes suggested by codeclimate
  • Loading branch information
rowan04 authored and gregcorbett committed Nov 29, 2023
1 parent 4c65eb4 commit e6e053d
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 120 deletions.
16 changes: 10 additions & 6 deletions lib/Doctrine/deploy/AddDowntimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
// Create a new downtime, add the SE to it
$downtime = newDowntime($downtimeXml);
// Finds one or more SEs by hostname and service type
$services = findSEs((string) $downtimeXml->HOSTNAME,
(string) $downtimeXml->SERVICE_TYPE);
$services = findSEs(
(string) $downtimeXml->HOSTNAME,
(string) $downtimeXml->SERVICE_TYPE
);

// There are some edge cases where findSEs returns
// more than one SE (see the comment at the top of this file)
Expand All @@ -93,8 +95,10 @@
$GLOBALS['allDowntimes'][$promId] = $downtime;
} else {
// Find the SE and link it to the downtime
$services = findSEs((string) $downtimeXml->HOSTNAME,
(string) $downtimeXml->SERVICE_TYPE);
$services = findSEs(
(string) $downtimeXml->HOSTNAME,
(string) $downtimeXml->SERVICE_TYPE
);

if (!isset($services[0])) {
throw new Exception("No SE found with hostname " .
Expand All @@ -110,7 +114,7 @@
// duplicate SEs (the duplicate SE count is tested for the expected
// 2 duplicates below in catch block).
$els = $services[0]->getEndpointLocations();
if (count($els) > 1){
if (count($els) > 1) {
throw new LogicException('Coding error - there should only ' .
'be one EL per Service');
}
Expand Down Expand Up @@ -212,7 +216,7 @@ function newDowntime($downtimeXml) {
// Get the largest v4 downtime PK which is an integer appended by
// the string 'G0' slice off the 'G0' and get the integer value.
$v4pk = (int)substr($primaryKey, 0, strlen($primaryKey)-2);
if ($v4pk > $GLOBALS['largestV4DowntimePK']){
if ($v4pk > $GLOBALS['largestV4DowntimePK']) {
$GLOBALS['largestV4DowntimePK'] = $v4pk;
}

Expand Down
37 changes: 25 additions & 12 deletions lib/Doctrine/deploy/AddNGIRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
// get roletype entity
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(':roleType',
(string) $role->USER_ROLE)
->setParameter(
':roleType',
(string) $role->USER_ROLE
)
->getResult();
// /* Error checking: ensure each role type refers to exactly
// * one role type*/
Expand All @@ -40,8 +42,10 @@
$dql = "SELECT u FROM User u JOIN u.userIdentifiers " .
"up WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue',
trim((string) $user->CERTDN))
->setParameter(
'keyValue',
trim((string) $user->CERTDN)
)
->getResult();

// /* Error checking: ensure each "user" refers to exactly
Expand All @@ -57,17 +61,24 @@

// Check for invalid NGIs and skip
// typically these are decomissioned ROCs
if ($role->ON_ENTITY == 'GridIreland' || $role->ON_ENTITY == 'NGS'
|| $role->ON_ENTITY == 'LondonT2' || $role->ON_ENTITY == 'Tier1A'
|| $role->ON_ENTITY == 'Tier1A') {
if (
$role->ON_ENTITY == 'GridIreland'
|| $role->ON_ENTITY == 'NGS'
|| $role->ON_ENTITY == 'LondonT2'
|| $role->ON_ENTITY == 'Tier1A'
|| $role->ON_ENTITY == 'Tier1A'
) {
continue;
}

// get ngi entity
$ngiName = (string) $role->ON_ENTITY;
$dql = "SELECT n FROM NGI n WHERE n.name = :ngi";
$ngis = $entityManager->createQuery($dql)
->setParameter('ngi', $ngiName)
->setParameter(
'ngi',
$ngiName
)
->getResult();
// /* Error checking: ensure each "ngi" refers to exactly
// * one ngi */
Expand All @@ -83,15 +94,17 @@
//check that the role is not a duplicate (v4 data contaisn duplicates)
$ExistingUserRoles = $doctrineUser->getRoles();
$thisIsADuplicateRole=false;
foreach ($ExistingUserRoles as $role){
if ($role->getRoleType() == $roleType
foreach ($ExistingUserRoles as $role) {
if (
$role->getRoleType() == $roleType
and $role->getOwnedEntity() == $ngi
and $role->getStatus() == 'STATUS_GRANTED') {
and $role->getStatus() == 'STATUS_GRANTED'
) {
$thisIsADuplicateRole = true;
}
}

if (!$thisIsADuplicateRole){
if (!$thisIsADuplicateRole) {
$doctrineRole = new Role(
$roleType,
$doctrineUser,
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/deploy/AddNGIs.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@

//convert to date time
$creationDate = DateTime::createFromFormat(
'd-M-y G.i.s.u', $cdateonString,
new DateTimeZone('UTC'));
'd-M-y G.i.s.u',
$cdateonString,
new DateTimeZone('UTC')
);

if ($creationDate == false) {
throw new LogicException("Datetime in unexpected " .
"format. datetime: '" . $cdateonString . "'");
throw new LogicException("Datetime in unexpected " .
"format. datetime: '" . $cdateonString . "'");
}
}

Expand Down
23 changes: 16 additions & 7 deletions lib/Doctrine/deploy/AddProjectRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
// get roletype entity
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(':roleType',
(string) $role->USER_ROLE)
->getResult();
->setParameter(
':roleType',
(string) $role->USER_ROLE
)
->getResult();
// /* Error checking: ensure each role type refers to exactly
// * one role type*/
if (count($roleTypes) !== 1) {
Expand All @@ -49,8 +51,10 @@
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up " .
"WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue',
trim((string) $user->CERTDN))
->setParameter(
'keyValue',
trim((string) $user->CERTDN)
)
->getResult();

// /* Error checking: ensure each "user" refers to exactly
Expand All @@ -70,7 +74,10 @@
// Querying the project entity
$dql = "SELECT p FROM Project p WHERE p.name = :project";
$projects = $entityManager->createQuery($dql)
->setParameter('project', $projectName)
->setParameter(
'project',
$projectName
)
->getResult();

// Error check: ensure each 'project' refers to exactly one project
Expand All @@ -81,7 +88,9 @@

// Finding the project object and adding the role to it
$getProject = $entityManager->getRepository('Project')
->findOneBy(array("name" => $projectName));
->findOneBy(
array("name" => $projectName)
);
$doctrineRole = new Role(
$roleType,
$doctrineUser,
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/deploy/AddRoleTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
foreach ($roleTypeArray as $key => $value) {
$rt = new RoleType($value);
//echo $value;
if ($value != RoleTypeName::GOCDB_ADMIN){
if ($value != RoleTypeName::GOCDB_ADMIN) {
$entityManager->persist($rt);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/deploy/AddScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$name = (string) $value;
break;
case "reserved":
$reserved = ( $value == 1 );
$reserved = ($value == 1);
break;
}
}
Expand Down
17 changes: 11 additions & 6 deletions lib/Doctrine/deploy/AddServiceEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* XML file and inserts them into the doctrine prototype.
* XML format is the output from get_service_endpoints PI query.
*/
$seFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceEndpoints.xml";
$seFileName = __DIR__ . "/" . $GLOBALS['dataDir'] .
"/ServiceEndpoints.xml";
$ses = simplexml_load_file($seFileName);

// Get EGI scope entity to join to later
Expand Down Expand Up @@ -43,8 +44,10 @@
// get the hosting site entity
$dql = "SELECT s from Site s WHERE s.shortName = ?1";
$parentSites = $entityManager->createQuery($dql)
->setParameter(1,
(string) $xmlSe->SITENAME)
->setParameter(
1,
(string) $xmlSe->SITENAME
)
->getResult();

/* Error checking: ensure each SE's "parent site" refers to exactly
Expand All @@ -64,8 +67,10 @@
// get the hosting service type
$dql = "SELECT s from ServiceType s WHERE s.name = ?1";
$sts = $entityManager->createQuery($dql)
->setParameter(1,
(string) $xmlSe->SERVICE_TYPE)
->setParameter(
1,
(string) $xmlSe->SERVICE_TYPE
)
->getResult();

/* Error checking: ensure each SE's "SERVICE_TYPE" refers to exactly
Expand Down Expand Up @@ -105,7 +110,7 @@
// Set the scope
if ((string) $xmlSe->SCOPE == "EGI") {
$doctrineSe->addScope($egiScope);
} else if ((String) $xmlSe->SCOPE == 'Local') {
} elseif ((string) $xmlSe->SCOPE == 'Local') {
$doctrineSe->addScope($localScope);
} else {
throw new Exception("Unknown scope " . $xmlSe->SCOPE .
Expand Down
16 changes: 12 additions & 4 deletions lib/Doctrine/deploy/AddServiceGroupRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
$userRole = (string) $role->USER_ROLE;
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(':roleType', $userRole)
->setParameter(
':roleType',
$userRole
)
->getResult();

/*
Expand All @@ -44,7 +47,10 @@
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up " .
"WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue', trim($userDN))
->setParameter(
'keyValue',
trim($userDN)
)
->getResult();

/*
Expand All @@ -64,8 +70,10 @@
$dql = "SELECT sg FROM ServiceGroup sg WHERE " .
"sg.name = :service_group";
$serviceGroups = $entityManager->createQuery($dql)
->setParameter('service_group',
$sgName)
->setParameter(
'service_group',
$sgName
)
->getResult();

/*
Expand Down
28 changes: 18 additions & 10 deletions lib/Doctrine/deploy/AddSiteRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
// get the roletype entity
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = ?1";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(1,
(string) $role->USER_ROLE)
->setParameter(
1,
(string) $role->USER_ROLE
)
->getResult();
// /* Error checking: ensure each role type refers to exactly
// * one role type */
Expand All @@ -50,8 +52,10 @@
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up " .
"WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue',
trim((string) $user->CERTDN))
->setParameter(
'keyValue',
trim((string) $user->CERTDN)
)
->getResult();

// /* Error checking: ensure each "user" refers to exactly
Expand Down Expand Up @@ -79,8 +83,10 @@
// get the site entity
$dql = "SELECT s FROM Site s WHERE s.shortName = ?1";
$sites = $entityManager->createQuery($dql)
->setParameter(1,
(string) $role->ON_ENTITY)
->setParameter(
1,
(string) $role->ON_ENTITY
)
->getResult();
// /* Error checking: ensure each "site" refers to exactly
// * one site */
Expand All @@ -100,15 +106,17 @@
//check that the role is not a duplicate (v4 data contaisn duplicates)
$ExistingUserRoles = $doctrineUser->getRoles();
$thisIsADuplicateRole=false;
foreach ($ExistingUserRoles as $role){
if ($role->getRoleType() == $roleType
foreach ($ExistingUserRoles as $role) {
if (
$role->getRoleType() == $roleType
and $role->getOwnedEntity() == $doctrineSite
and $role->getStatus() == 'STATUS_GRANTED'){
and $role->getStatus() == 'STATUS_GRANTED'
) {
$thisIsADuplicateRole = true;
}
}

if (!$thisIsADuplicateRole){
if (!$thisIsADuplicateRole) {
$doctrineRole = new Role(
$roleType,
$doctrineUser,
Expand Down
Loading

0 comments on commit e6e053d

Please sign in to comment.