Skip to content

Commit

Permalink
Types fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 19, 2024
1 parent 30eb0a0 commit ff45eb4
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function doEdit(Request $request, Response $response, int $id = null, str
$error_detected = [];

$category->name = $post['name'];
$category->is_active = $post['is_active'] == true;
$category->is_active = ($post['is_active'] ?? false) == true;
if ($category->store()) {
// picture upload
if (isset($_FILES['picture'])) {
Expand Down
4 changes: 2 additions & 2 deletions lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function doClone(Request $request, Response $response, int $id): Response
'success_detected',
str_replace(
'%id',
$id,
(string)$id,
_T('Successfully cloned from #%id.<br/>You can now edit it.', 'objectslend')
)
);
Expand Down Expand Up @@ -1005,7 +1005,7 @@ public function formUri(array $args): string
protected function getIdsToRemove(array &$args, ?array $post): array|int|null
{
if (isset($args['id'])) {
return $args['id'];
return (int)$args['id'];
} else {
$filters = $this->session->objectslend_filter_objects;
return $filters->selected;
Expand Down
12 changes: 6 additions & 6 deletions lib/GaletteObjectsLend/Entity/LendCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function loadFromRS(ArrayObject $r): void
}

if (property_exists($r, 'objects_price_sum')) {
$this->objects_price_sum = $r->objects_price_sum;
$this->objects_price_sum = $r->objects_price_sum ?? 0.0;
}


Expand All @@ -154,7 +154,7 @@ public function store(): bool
//Handle booleans for postgres ; bugs #18899 and #19354
$values[$k] = $this->zdb->isPostgres() ? 'false' : 0;
} else {
$values[$k] = $this->$k;
$values[$k] = $this->$k ?? null;
}
}

Expand All @@ -166,11 +166,11 @@ public function store(): bool
if ($result->count() > 0) {
if ($this->zdb->isPostgres()) {
/** @phpstan-ignore-next-line */
$this->category_id = $this->zdb->driver->getLastGeneratedValue(
$this->category_id = (int)$this->zdb->driver->getLastGeneratedValue(
PREFIX_DB . 'lend_category_id_seq'
);
} else {
$this->category_id = $this->zdb->driver->getLastGeneratedValue();
$this->category_id = (int)$this->zdb->driver->getLastGeneratedValue();
}
} else {
throw new \RuntimeException('Unable to add category!');
Expand Down Expand Up @@ -268,11 +268,11 @@ public function __get(string $name): mixed
* Global setter method
*
* @param string $name name of the property we want to assign a value to
* @param object $value a relevant value for the property
* @param mixed $value a relevant value for the property
*
* @return void
*/
public function __set(string $name, object $value): void
public function __set(string $name, mixed $value): void
{
$this->$name = $value;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/GaletteObjectsLend/Entity/LendObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ public function store(): bool
if ($result->count() > 0) {
if ($this->zdb->isPostgres()) {
/** @phpstan-ignore-next-line */
$this->object_id = $this->zdb->driver->getLastGeneratedValue(
$this->object_id = (int)$this->zdb->driver->getLastGeneratedValue(
PREFIX_DB . 'lend_objects_id_seq'
);
} else {
$this->object_id = $this->zdb->driver->getLastGeneratedValue();
$this->object_id = (int)$this->zdb->driver->getLastGeneratedValue();
}

if ($this->deps['picture'] === true) {
Expand Down
13 changes: 9 additions & 4 deletions lib/GaletteObjectsLend/Entity/LendRent.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LendRent
private string $date_begin;
private ?string $date_forecast;
private ?string $date_end;
private int $status_id;
private ?int $status_id;
private ?int $adherent_id;
private string $comments = '';
private bool $in_stock;
Expand Down Expand Up @@ -157,11 +157,11 @@ public function store(): bool
$result = $zdb->execute($insert);
if ($result->count() > 0) {
if ($zdb->isPostgres()) {
$this->rent_id = $zdb->driver->getLastGeneratedValue(
$this->rent_id = (int)$zdb->driver->getLastGeneratedValue(
PREFIX_DB . 'lend_rents_id_seq'
);
} else {
$this->rent_id = $zdb->driver->getLastGeneratedValue();
$this->rent_id = (int)$zdb->driver->getLastGeneratedValue();
}
Analog::log(
'Rent #' . $this->rent_id . ' added.',
Expand Down Expand Up @@ -198,7 +198,7 @@ public function store(): bool
}

/**
* Get rent histroy for a given object sorted
* Get rent history for a given object sorted
*
* @param integer $object_id Object ID
* @param boolean $only_last Only retrieve last rent (for list display)
Expand Down Expand Up @@ -373,6 +373,11 @@ public function __set(string $name, mixed $value): void
$this->$name = null;
}
break;
case 'status_id':
if ((int)$value > 0) {
$this->$name = (int)$value;
}
break;
case 'date_forecast':
case 'date_begin':
case 'date_end':
Expand Down
10 changes: 5 additions & 5 deletions lib/GaletteObjectsLend/Entity/LendStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function store(): bool
//Handle booleans for postgres ; bugs #18899 and #19354
$values[$k] = $this->zdb->isPostgres() ? 'false' : 0;
} else {
$values[$k] = $this->$k;
$values[$k] = $this->$k ?? null;
}
}

Expand All @@ -136,11 +136,11 @@ public function store(): bool
if ($result->count() > 0) {
if ($this->zdb->isPostgres()) {
/** @phpstan-ignore-next-line */
$this->status_id = $this->zdb->driver->getLastGeneratedValue(
$this->status_id = (int)$this->zdb->driver->getLastGeneratedValue(
PREFIX_DB . 'lend_status_id_seq'
);
} else {
$this->status_id = $this->zdb->driver->getLastGeneratedValue();
$this->status_id = (int)$this->zdb->driver->getLastGeneratedValue();
}
} else {
throw new \Exception(_T("Status has not been added :(", "objectslend"));
Expand Down Expand Up @@ -285,11 +285,11 @@ public function __get(string $name): mixed
* Global setter method
*
* @param string $name name of the property we want to assign a value to
* @param object $value a relevant value for the property
* @param mixed $value a relevant value for the property
*
* @return void
*/
public function __set(string $name, object $value): void
public function __set(string $name, mixed $value): void
{
$this->$name = $value;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/GaletteObjectsLend/Entity/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ private function createThumb(string $source, string $ext, string $dest = null):
public function delete(bool $transaction = true): bool
{
//find and delete any thumb
$ext = strlen(pathinfo($this->file_path, PATHINFO_EXTENSION)) + 1;
$filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext));
$ext = pathinfo($this->file_path, PATHINFO_EXTENSION);
$filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext) - 1);

$thumb = $filename . '_th.' . $ext;

Expand All @@ -262,8 +262,8 @@ public function delete(bool $transaction = true): bool
*/
public function store(array $file, bool $ajax = false, array $cropping = null): bool|int
{
$ext = strlen(pathinfo($this->file_path, PATHINFO_EXTENSION)) + 1;
$filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext));
$ext = pathinfo($this->file_path, PATHINFO_EXTENSION);
$filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext) - 1);
$thumb = $filename . '_th.' . $ext;

if (is_file($thumb)) {
Expand Down
16 changes: 7 additions & 9 deletions lib/GaletteObjectsLend/Entity/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public function getPreferences(): array
*
* @param string $name name of the property we want to retrieve
*
* @return false|object the called property
* @return mixed the called property
*/
public function __get(string $name): false|object
public function __get(string $name): mixed
{
$forbidden = array();

Expand Down Expand Up @@ -240,10 +240,8 @@ public function store(array $data, array &$errors): bool
)->where->equalTo(self::PK, ':' . self::PK);
$stmt = $this->zdb->sql->prepareStatementForSqlObject($update);

unset($data['csrf_value'], $data['csrf_name'], $data['GENERATED_CONTRIB_INFO_TEXT']);
foreach ($data as $key => $value) {
if ($key === 'GENERATED_CONTRIB_INFO_TEXT') {
continue;
}
$stmt->execute(
[
'value_numeric' => $value,
Expand Down Expand Up @@ -305,7 +303,7 @@ public function load(): bool
*/
public function getThumbWidth(): int
{
return $this->prefs['THUMB_MAX_WIDTH'];
return (int)$this->prefs['THUMB_MAX_WIDTH'];
}

/**
Expand All @@ -315,7 +313,7 @@ public function getThumbWidth(): int
*/
public function getThumbHeight(): int
{
return $this->prefs['THUMB_MAX_HEIGHT'];
return (int)$this->prefs['THUMB_MAX_HEIGHT'];
}

/**
Expand All @@ -325,7 +323,7 @@ public function getThumbHeight(): int
*/
public function imagesInLists(): bool
{
return $this->prefs['VIEW_THUMBNAIL'];
return (bool)$this->prefs['VIEW_THUMBNAIL'];
}

/**
Expand All @@ -337,6 +335,6 @@ public function imagesInLists(): bool
*/
public function showFullsize(): bool
{
return $this->prefs['VIEW_FULLSIZE'];
return (bool)$this->prefs['VIEW_FULLSIZE'];
}
}
2 changes: 1 addition & 1 deletion lib/GaletteObjectsLend/Filters/CategoriesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function __set(string $name, mixed $value): void
case Categories::ALL_CATEGORIES:
case Categories::ACTIVE_CATEGORIES:
case Categories::INACTIVE_CATEGORIES:
$this->active_filter = $value;
$this->active_filter = (int)$value;
break;
default:
Analog::log(
Expand Down

0 comments on commit ff45eb4

Please sign in to comment.