Skip to content

Commit

Permalink
Strict types declaration
Browse files Browse the repository at this point in the history
Types fixes
  • Loading branch information
trasher committed May 19, 2024
1 parent f78d410 commit 282d0de
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 36 deletions.
1 change: 1 addition & 0 deletions .composer-require-checker.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"GALETTE_CARD_ROWS",
"GALETTE_CARD_WIDTH",
"GALETTE_COMPAT_VERSION",
"GALETTE_SYSCONFIG_PATH",
"GALETTE_CONFIG_PATH",
"GALETTE_DATA_PATH",
"GALETTE_DB_VERSION",
Expand Down
2 changes: 2 additions & 0 deletions _config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

define('LEND_PREFIX', 'lend_');
2 changes: 2 additions & 0 deletions _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

$this->register(
'Galette Objects Lend', //Name
'Manage rent/lend of object', //Short description
Expand Down
2 changes: 2 additions & 0 deletions _routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

use Analog\Analog;
use Galette\Entity\ContributionsTypes;
use Galette\Entity\Adherent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers\Crud;

use Analog\Analog;
Expand Down Expand Up @@ -240,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
6 changes: 4 additions & 2 deletions lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers\Crud;

use Analog\Analog;
Expand Down Expand Up @@ -541,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 @@ -1003,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
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Controllers/Crud/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers\Crud;

use DI\Attribute\Inject;
Expand Down
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Controllers/ImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers;

use Galette\Controllers\ImagesController as GImagesController;
Expand Down
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers;

use DI\Attribute\Inject;
Expand Down
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Controllers;

use Galette\Controllers\PdfController as GPdfController;
Expand Down
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Entity/CategoryPicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down
14 changes: 8 additions & 6 deletions lib/GaletteObjectsLend/Entity/LendCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down Expand Up @@ -128,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 @@ -152,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 @@ -164,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 @@ -266,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
6 changes: 4 additions & 2 deletions lib/GaletteObjectsLend/Entity/LendObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down Expand Up @@ -335,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
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Entity/LendPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Galette\Core\Preferences as CorePreferences;
Expand Down
15 changes: 11 additions & 4 deletions lib/GaletteObjectsLend/Entity/LendRent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down Expand Up @@ -68,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 @@ -155,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 @@ -196,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 @@ -371,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
12 changes: 7 additions & 5 deletions lib/GaletteObjectsLend/Entity/LendStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down Expand Up @@ -122,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 @@ -134,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 @@ -283,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
2 changes: 2 additions & 0 deletions lib/GaletteObjectsLend/Entity/ObjectPicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down
10 changes: 6 additions & 4 deletions lib/GaletteObjectsLend/Entity/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace GaletteObjectsLend\Entity;

use Analog\Analog;
Expand Down Expand Up @@ -237,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 @@ -260,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
Loading

0 comments on commit 282d0de

Please sign in to comment.