Skip to content

Commit

Permalink
Stronger PHP types, and update PHP devs (#7155)
Browse files Browse the repository at this point in the history
# Description & Issue number it closes 
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. -->

improving type safety in the codebase where I see it.
DAcodedBEAT authored Sep 21, 2024
2 parents b0a9c6d + f231e85 commit bbd08ac
Showing 18 changed files with 74 additions and 598 deletions.
2 changes: 1 addition & 1 deletion src/ChurchCRM/Reports/PDF_Directory.php
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ public function sGetCustomString($rsCustomFields, $aRow): string
}
}

public function getBirthdayString(bool $bDirBirthday, $per_BirthMonth, $per_BirthDay, $per_BirthYear, $per_Flags): string
public function getBirthdayString(bool $bDirBirthday, $per_BirthMonth, $per_BirthDay, $per_BirthYear, ?bool $per_Flags): string
{
if ($bDirBirthday && $per_BirthDay > 0 && $per_BirthMonth > 0) {
return MiscUtils::formatBirthDate($per_BirthYear, $per_BirthMonth, $per_BirthDay, $per_Flags);
2 changes: 1 addition & 1 deletion src/ChurchCRM/SQLUtils.php
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ private static function clearSQL($sql, &$isMultiComment)
while (preg_match('{--\s|#|/\*[^!]}sUi', $sql, $matched, PREG_OFFSET_CAPTURE, $offset)) {
[$comment, $foundOn] = $matched[0];
if (self::isQuoted($foundOn, $sql)) {
$offset = (int) $foundOn + strlen($comment);
$offset = $foundOn + strlen($comment);
} else {
if (mb_substr($comment, 0, 2) == '/*') {
$closedOn = strpos($sql, '*/', $foundOn);
8 changes: 4 additions & 4 deletions src/ChurchCRM/dto/Photo.php
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ class Photo
private $photoURI;
private ?string $photoThumbURI = null;
private ?string $thumbnailPath = null;
private $photoContentType;
private $thumbnailContentType;
private $photoContentType = null;
private $thumbnailContentType = null;
private bool $remotesEnabled;

public static $validExtensions = ['png', 'jpeg', 'jpg'];
@@ -208,12 +208,12 @@ public function getThumbnailBytes(): string
return $content;
}

public function getPhotoBytes()
public function getPhotoBytes(): string
{
$content = file_get_contents($this->photoURI);
MiscUtils::throwIfFailed($content);

return $content;
return (string) $content;
}

public function getPhotoContentType()
2 changes: 1 addition & 1 deletion src/ChurchCRM/model/ChurchCRM/Person.php
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public function isFemale(): bool
return $this->getGender() == 2;
}

public function getGenderName()
public function getGenderName(): string
{
switch (strtolower($this->getGender())) {
case 1:
2 changes: 0 additions & 2 deletions src/ChurchCRM/utils/RedirectUtils.php
Original file line number Diff line number Diff line change
@@ -9,8 +9,6 @@ class RedirectUtils
/**
* Convert a relative URL into an absolute URL and redirect the browser there.
*
* @param string $sRelativeURL
*
* @throws \Exception
*/
public static function redirect(string $sRelativeURL): void
216 changes: 0 additions & 216 deletions src/Include/alphaAPI.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/PeopleDashboard.php
Original file line number Diff line number Diff line change
@@ -285,9 +285,9 @@
<th style="width: 40px"><?= gettext('Count') ?></th>
</tr>
<?php
foreach(array_keys($familyRoleStats) as $key){
$genderId = $familyRoleStats[$key]['genderId'];;
$roleId = $familyRoleStats[$key]['roleId'];;
foreach (array_keys($familyRoleStats) as $key) {
$genderId = $familyRoleStats[$key]['genderId'];
$roleId = $familyRoleStats[$key]['roleId'];
$roldGenderName = $key;
$roleGenderCount = $familyRoleStats[$key]['count'];

2 changes: 1 addition & 1 deletion src/api/routes/people/people-families.php
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@
$currentStatus = (empty($family->getDateDeactivated()) ? 'true' : 'false');

//update only if the value is different
if ($currentStatus != $newStatus) {
if ($currentStatus !== $newStatus) {
if ($newStatus == 'false') {
$family->setDateDeactivated(date('YmdHis'));
} elseif ($newStatus == 'true') {
6 changes: 3 additions & 3 deletions src/api/routes/people/people-person.php
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@

$group->delete('', function (Request $request, Response $response, array $args): Response {
$person = $request->getAttribute('person');
if (AuthenticationManager::getCurrentUser()->getId() == $person->getId()) {
if (AuthenticationManager::getCurrentUser()->getId() === (int) $person->getId()) {
throw new HttpForbiddenException($request, gettext("Can't delete yourself"));
}
$person->delete();
@@ -73,14 +73,14 @@ function setPersonRoleAPI(Request $request, Response $response, array $args): Re
{
$person = $request->getAttribute('person');

$roleId = $args['roleId'];
$roleId = (int) $args['roleId'];
$role = ListOptionQuery::create()->filterByOptionId($roleId)->findOne();

if (empty($role)) {
throw new HttpNotFoundException($request, gettext('The role could not be found.'));
}

if ($person->getFmrId() == $roleId) {
if ((int) $person->getFmrId() === $roleId) {
return SlimUtils::renderJSON($response, ['success' => true, 'msg' => gettext('The role is already assigned.')]);
}

4 changes: 2 additions & 2 deletions src/api/routes/people/people-properties.php
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ function getFamilyProperties(Request $request, Response $response, array $args):
return getProperties($response, 'f', $family->getId());
}

function getProperties(Response $response, $type, $id): Response
function getProperties(Response $response, string $type, int $id): Response
{
$properties = RecordPropertyQuery::create()
->filterByRecordId($id)
@@ -87,7 +87,7 @@ function getProperties(Response $response, $type, $id): Response

foreach ($properties as $property) {
$rawProp = $property->getProperty();
if ($rawProp->getProClass() == $type) {
if ($rawProp->getProClass() === $type) {
$tempProp = [];
$tempProp['id'] = $property->getPropertyId();
$tempProp['name'] = $rawProp->getProName();
4 changes: 2 additions & 2 deletions src/api/routes/system/system-database.php
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ function exportChMeetings(Request $request, Response $response, array $args): Re
$family = $person->getFamily();
$anniversary = ($family ? $family->getWeddingdate(SystemConfig::getValue('sDateFormatLong')) : '');
$familyRole = $person->getFamilyRoleName();
if ($familyRole == 'Head of Household') {
if ($familyRole === 'Head of Household') {
$familyRole = 'Primary';
}

@@ -229,7 +229,7 @@ function resetDatabase(Request $request, Response $response): Response
$dbTablesSQLs = $statement->fetchAll();

foreach ($dbTablesSQLs as $dbTable) {
if ($dbTable[1] == 'VIEW') {
if ($dbTable[1] === 'VIEW') {
$alterSQL = 'DROP VIEW ' . $dbTable[0] . ' ;';
} else {
$alterSQL = 'DROP TABLE ' . $dbTable[0] . ' ;';
2 changes: 1 addition & 1 deletion src/bin/google-map/GoogleMap.php
Original file line number Diff line number Diff line change
@@ -865,7 +865,7 @@ public function addDirections($start_address = '', $dest_address = '', $dom_id =
$elevation_dom_id = 'elevation' . $dom_id;
}

if ($start_address != '' && $dest_address != '' && $dom_id != '') {
if ($start_address !== '' && $dest_address !== '' && $dom_id !== '') {
$this->_directions[$dom_id] = [
'dom_id' => $dom_id,
'start' => $start_address,
8 changes: 7 additions & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
@@ -67,6 +67,12 @@
"rector/rector": "^1.0",
"squizlabs/php_codesniffer": "^3.7"
},
"replace": {
"symfony/polyfill-mbstring": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
},
"repositories": {
"packagist": {
"type": "composer",
@@ -100,4 +106,4 @@
"@orm-gen"
]
}
}
}
Loading

0 comments on commit bbd08ac

Please sign in to comment.