Skip to content

Commit

Permalink
add return types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Jan 16, 2025
1 parent f1006f4 commit ac10011
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 122 deletions.
50 changes: 22 additions & 28 deletions src/Controller/Component/StringComponent.php

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/Model/Entity/FormField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Model\Entity;

use Cake\ORM\Entity;

class FormField extends Entity
{
}
9 changes: 9 additions & 0 deletions src/Model/Entity/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Model\Entity;

use Cake\ORM\Entity;

class Page extends Entity
{
}
2 changes: 1 addition & 1 deletion src/Model/Table/BlogsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function initialize(array $config): void
]);
}

public function getForDropdown()
public function getForDropdown(): array
{
$blogs = $this->find('all', order: [
'Blogs.name' => 'ASC'
Expand Down
30 changes: 11 additions & 19 deletions src/Model/Table/CategoriesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
use Cake\Validation\Validator;
use Cake\ORM\Query\SelectQuery;

class CategoriesTable extends Table
{
Expand Down Expand Up @@ -48,13 +49,13 @@ public function initialize(array $config): void
]);
}

public function validationDefault(Validator $validator): \Cake\Validation\Validator
public function validationDefault(Validator $validator): Validator
{
$validator->notEmptyString('name', 'Bitte trage den Namen ein.');
return $validator;
}

public function getInfoSheetCount($categoryId)
public function getInfoSheetCount($categoryId): int
{
$infoSheetTable = TableRegistry::getTableLocator()->get('InfoSheets');
$result = $infoSheetTable->find('all',
Expand All @@ -66,9 +67,8 @@ public function getInfoSheetCount($categoryId)
return $result;
}

public function getMaterialFootprintByParentCategoryId($parentCategoryId)
public function getMaterialFootprintByParentCategoryId($parentCategoryId): float
{

$category = $this->find('all', conditions: [
'Categories.parent_id' => $parentCategoryId
])->first();
Expand All @@ -81,9 +81,8 @@ public function getMaterialFootprintByParentCategoryId($parentCategoryId)
return $result;
}

public function getCarbonFootprintByParentCategoryId($parentCategoryId)
public function getCarbonFootprintByParentCategoryId($parentCategoryId): float
{

$category = $this->find('all', conditions: [
'Categories.parent_id' => $parentCategoryId
])->first();
Expand All @@ -96,12 +95,8 @@ public function getCarbonFootprintByParentCategoryId($parentCategoryId)
return $result;
}

/**
* @return array
*/
public function getForSubcategoryDropdown()
public function getForSubcategoryDropdown(): array
{

$categories = $this->find('threaded',
conditions: [
'Categories.visible_on_platform' => APP_ON,
Expand Down Expand Up @@ -134,19 +129,19 @@ public function getForSubcategoryDropdown()

}

public function calculateMaterialFootprint($repairedCount, $materialFootprintFactor)
public function calculateMaterialFootprint($repairedCount, $materialFootprintFactor): float
{
$savedEnergyPart = 0.3;
return $repairedCount * $materialFootprintFactor * $savedEnergyPart;
}

public function calculateCarbonFootprint($repairedCount, $carbonFootprintFactor)
public function calculateCarbonFootprint($repairedCount, $carbonFootprintFactor): float
{
$savedEnergyPart = 0.3;
return $repairedCount * $carbonFootprintFactor * $savedEnergyPart;
}

public function getCategoriesForStatisticsGlobal()
public function getCategoriesForStatisticsGlobal(): array
{

$categories = [];
Expand Down Expand Up @@ -182,7 +177,7 @@ public function getCategoriesForStatisticsGlobal()
return $categories;
}

public function getMainCategoriesForFrontend()
public function getMainCategoriesForFrontend(): SelectQuery
{
$categories = $this->find('all',
conditions: [
Expand All @@ -195,10 +190,7 @@ public function getMainCategoriesForFrontend()
return $categories;
}

/**
* @return array
*/
public function getForDropdown($visibleOnPlatform)
public function getForDropdown($visibleOnPlatform): array
{

$categories = $this->find('all',
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/CountriesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function initialize(array $config): void
$this->setPrimaryKey('code');
}

public function getForDropdown()
public function getForDropdown(): array
{
$countries = $this->find('all', order: [
'rank' => 'ASC',
Expand Down
18 changes: 11 additions & 7 deletions src/Model/Table/EventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function initialize(array $config): void
]);
}

public function validationDefault(Validator $validator): \Cake\Validation\Validator
public function validationDefault(Validator $validator): Validator
{
$geoService = new GeoService();
$validator = $geoService->getGeoCoordinatesValidator($validator);
Expand All @@ -65,8 +65,8 @@ public function validationDefault(Validator $validator): \Cake\Validation\Valida
return $validator;
}

public function getKeywordSearchConditions($keyword, $negate) {

public function getKeywordSearchConditions(string $keyword, bool $negate): mixed
{
$changeableOrConditions = [
'Workshops.name LIKE' => "%{$keyword}%",
'Events.ort LIKE' => "%{$keyword}%",
Expand All @@ -88,7 +88,8 @@ public function getKeywordSearchConditions($keyword, $negate) {
};
}

public function getProvinceCounts() {
public function getProvinceCounts(): array
{

$query = $this->find('all')
->select([
Expand All @@ -107,15 +108,17 @@ public function getProvinceCounts() {
return $provincesMap;
}

public function getListConditions() {
public function getListConditions(): array
{
return [
'Events.status' => APP_ON,
'Workshops.status' => APP_ON,
'DATE(Events.datumstart) >= DATE(NOW())'
];
}

public function getListFields() {
public function getListFields(): array
{
return [
'Events.uid',
'Events.lat',
Expand All @@ -139,7 +142,8 @@ public function getListFields() {
];
}

public function getListOrder() {
public function getListOrder(): array
{
return [
'Events.datumstart' => 'ASC',
'Events.uhrzeitstart' => 'ASC'
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Table/FormFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Model\Table;

use Cake\ORM\Table;
use App\Model\Entity\FormField;

class FormFieldsTable extends Table
{
Expand All @@ -15,7 +16,7 @@ public function initialize(array $config): void
]);
}

public function getForForm($formFieldId)
public function getForForm($formFieldId): FormField
{
$formField = $this->find('all',
conditions: [
Expand Down
12 changes: 8 additions & 4 deletions src/Model/Table/FundingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Cake\Validation\Validator;
use Laminas\Diactoros\UploadedFile;
use Cake\ORM\TableRegistry;
use App\Model\Entity\Funding;

class FundingsTable extends AppTable
{
Expand Down Expand Up @@ -106,7 +107,7 @@ public function validationDefault(Validator $validator): Validator
return $validator;
}

public function validateFileTypeAndSize($value, $context)
public function validateFileTypeAndSize($value, $context): true|string
{
$allowedMimeTypes = ['application/pdf', 'image/jpeg', 'image/png'];
$maxSize = 5 * 1024 * 1024; // 5 MB in bytes
Expand Down Expand Up @@ -136,7 +137,8 @@ public function validateFileTypeAndSize($value, $context)
return true;
}

public function getUnprivatizedFundingWithAllAssociations($fundingUid) {
public function getUnprivatizedFundingWithAllAssociations($fundingUid): Funding
{
$funding = $this->find(contain: [
'Workshops',
'OwnerUsers',
Expand All @@ -153,7 +155,8 @@ public function getUnprivatizedFundingWithAllAssociations($fundingUid) {
return $funding;
}

public function deleteCustom($fundingUid) {
public function deleteCustom($fundingUid): void
{

$funding = $this->find()->where([
$this->aliasField('uid') => $fundingUid,
Expand Down Expand Up @@ -181,7 +184,8 @@ public function deleteCustom($fundingUid) {

}

public function findOrCreateCustom($workshopUid) {
public function findOrCreateCustom($workshopUid): Funding
{

$funding = $this->find()->where([
$this->aliasField('workshop_uid') => $workshopUid,
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/FundinguploadsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function initialize(array $config): void
]);
}

public function beforeSave($event, $entity, $options)
public function beforeSave($event, $entity, $options): void
{
if ($entity->isNew() && !$entity->id) {
$entity->id = Text::uuid();
Expand Down
12 changes: 5 additions & 7 deletions src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class GroupsTable extends Table
{

public function isAdmin($user)
public function isAdmin($user): bool
{
if (empty($user['groups']))
return false;
Expand All @@ -19,7 +19,7 @@ public function isAdmin($user)
return false;
}

public function isOrga($user)
public function isOrga($user): bool
{
if (empty($user['groups']))
return false;
Expand All @@ -31,7 +31,7 @@ public function isOrga($user)
return false;
}

public function isRepairhelper($user)
public function isRepairhelper($user): bool
{
if (empty($user['groups']))
return false;
Expand All @@ -43,8 +43,8 @@ public function isRepairhelper($user)
return false;
}

public function isInGroup($user, $groupNames): bool {

public function isInGroup($user, $groupNames): bool
{
if (empty($user['groups'])) {
return false;
}
Expand All @@ -59,8 +59,6 @@ public function isInGroup($user, $groupNames): bool {
}

return false;

}

}
?>
Loading

0 comments on commit ac10011

Please sign in to comment.