Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronger PHP types, and update PHP devs #7155

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ChurchCRM/Reports/PDF_Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/SQLUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/ChurchCRM/dto/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/model/ChurchCRM/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/ChurchCRM/utils/RedirectUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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'];

Expand Down
2 changes: 1 addition & 1 deletion src/api/routes/people/people-families.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
6 changes: 3 additions & 3 deletions src/api/routes/people/people-person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.')]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/routes/people/people-properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/api/routes/system/system-database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down Expand Up @@ -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] . ' ;';
Expand Down
2 changes: 1 addition & 1 deletion src/bin/google-map/GoogleMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -100,4 +106,4 @@
"@orm-gen"
]
}
}
}
Loading
Loading