From 0369afd85cb2095d26d71509aa9cdf446208c880 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 11 Nov 2026 22:52:55 +0100 Subject: [PATCH 1/2] Apply Galette core rector rules --- .../Crud/AbstractListController.php | 4 +- .../Controllers/Crud/CategoriesController.php | 11 +- .../Controllers/Crud/ObjectsController.php | 71 ++-- .../Controllers/Crud/StatusController.php | 11 +- .../Controllers/MainController.php | 4 +- .../Controllers/PdfController.php | 25 +- .../Entity/LendCategory.php | 10 +- lib/GaletteObjectsLend/Entity/LendObject.php | 4 +- lib/GaletteObjectsLend/Entity/LendRent.php | 8 +- lib/GaletteObjectsLend/Entity/LendStatus.php | 6 +- .../Filters/ListFilters.php | 4 +- .../Filters/ObjectsList.php | 6 +- lib/GaletteObjectsLend/IO/PdfObject.php | 113 ++++-- lib/GaletteObjectsLend/IO/PdfObjects.php | 340 +++++++++++++++--- lib/GaletteObjectsLend/LendPreferences.php | 4 +- lib/GaletteObjectsLend/LendService.php | 68 ++-- .../Repository/AbstractRepository.php | 11 +- .../Repository/Categories.php | 28 +- lib/GaletteObjectsLend/Repository/Objects.php | 46 +-- lib/GaletteObjectsLend/Repository/Rents.php | 10 +- lib/GaletteObjectsLend/Repository/Status.php | 14 +- lib/GaletteObjectsLend/SampleData.php | 22 +- .../tests/units/CategoriesController.php | 19 +- .../tests/units/ObjectsController.php | 76 ++-- .../tests/units/StatusController.php | 31 +- .../Entity/tests/units/LendCategory.php | 8 +- .../Entity/tests/units/LendObject.php | 32 +- .../Entity/tests/units/LendRent.php | 14 +- .../Entity/tests/units/LendStatus.php | 12 +- .../Entity/tests/units/Picture.php | 7 +- .../IO/tests/units/PdfObject.php | 2 +- .../Repository/tests/units/Categories.php | 41 ++- .../Repository/tests/units/Objects.php | 95 +++-- .../Repository/tests/units/Status.php | 61 ++-- .../tests/units/LendService.php | 31 +- .../tests/units/SampleData.php | 6 +- 36 files changed, 846 insertions(+), 409 deletions(-) diff --git a/lib/GaletteObjectsLend/Controllers/Crud/AbstractListController.php b/lib/GaletteObjectsLend/Controllers/Crud/AbstractListController.php index dad2a5a..2e3d9a1 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/AbstractListController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/AbstractListController.php @@ -161,7 +161,7 @@ abstract public static function getDefaultFilterName(): string; */ public function add(Request $request, Response $response): Response { - return $this->edit($request, $response, null, 'add'); + return $this->edit(request: $request, response: $response, id: null, action: 'add'); } /** @@ -172,7 +172,7 @@ public function add(Request $request, Response $response): Response */ public function doAdd(Request $request, Response $response): Response { - return $this->doEdit($request, $response, null, 'add'); + return $this->doEdit(request: $request, response: $response, id: null, action: 'add'); } // /CRUD - Create diff --git a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php index f12f052..84d700f 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php @@ -70,8 +70,13 @@ protected function createFilters(): CategoriesList */ protected function getListView(Pagination $filters): array { - $categories = new Categories($this->zdb, $this->preferences, $this->login, $filters); - $list = $categories->getCategoriesList(true); + $categories = new Categories( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + $list = $categories->getCategoriesList(as_cat: true); return [ 'categories_list', @@ -185,7 +190,7 @@ public function confirmRemoveTitle(array $args): string { return sprintf( _T('Remove category %1$s', 'objectslend'), - $this->loadEntity((int)$args['id'])->getName(false) + $this->loadEntity((int)$args['id'])->getName(count: false) ); } } diff --git a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php index cee752e..22dd521 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php @@ -80,7 +80,7 @@ private function getFilters(): ObjectsList */ public function add(Request $request, Response $response): Response { - return $this->edit($request, $response, null, 'add'); + return $this->edit(request: $request, response: $response, id: null, action: 'add'); } /** @@ -91,7 +91,7 @@ public function add(Request $request, Response $response): Response */ public function doAdd(Request $request, Response $response): Response { - return $this->doEdit($request, $response, null, 'add'); + return $this->doEdit(request: $request, response: $response, id: null, action: 'add'); } // /CRUD - Create @@ -127,14 +127,20 @@ public function list(Request $request, Response $response, ?string $option = nul } $lendsprefs = new LendPreferences($this->preferences); - $objects = new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs, $filters); - $list = $objects->getObjectsList(true); + $objects = new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $lendsprefs, + filters: $filters + ); + $list = $objects->getObjectsList(as_objects: true); $this->session->{$this->getFiltersKey()} = $filters; //assign pagination variables to the template and add pagination links $filters->setViewCommonsFilters($lendsprefs, $this->view); - $filters->setViewPagination($this->routeparser, $this->view, false); + $filters->setViewPagination($this->routeparser, $this->view, restricted: false); $cat_filters = new CategoriesList(); $cat_filters->active_filter = Categories::ACTIVE_CATEGORIES; //retrieve only active categories @@ -143,8 +149,13 @@ public function list(Request $request, Response $response, ?string $option = nul $objects_filters = clone $filters; $objects_filters->category_filter = null; $cat_filters->setObjectsFilter($objects_filters); - $categories = new Categories($this->zdb, $this->preferences, $this->login, $cat_filters); - $categories_list = $categories->getCategoriesList(true, false, false); + $categories = new Categories( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $cat_filters + ); + $categories_list = $categories->getCategoriesList(as_cat: true, count: false, limit: false); // display page $this->view->render( @@ -301,7 +312,7 @@ public function edit(Request $request, Response $response, ?int $id = null, stri unset($this->session->objectslend_object_data); $categories = new Categories($this->zdb, $this->preferences, $this->login); - $categories_list = $categories->getCategoriesList(true); + $categories_list = $categories->getCategoriesList(as_cat: true); if ($object->getId() !== null) { $title = _T("Edit object", "objectslend"); @@ -311,8 +322,13 @@ public function edit(Request $request, Response $response, ?int $id = null, stri $sfilter = new StatusList(); $sfilter->active_filter = \GaletteObjectsLend\Repository\Status::ACTIVE; - $statuses = new Status($this->zdb, $this->preferences, $this->login, $sfilter); - $slist = $statuses->getStatusList(true); + $statuses = new Status( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $sfilter + ); + $slist = $statuses->getStatusList(as_stt: true); $lendsprefs = new LendPreferences($this->preferences); $params = [ @@ -492,10 +508,10 @@ public function doUpdateStatus(Request $request, Response $response, ?int $id = try { $this->getLendService()->changeStatus( - $object, - (int)($post['new_status'] ?? 0), - empty($post['new_adh']) ? null : (int)$post['new_adh'], - $post['new_comment'] ?? '' + object: $object, + status_id: (int)($post['new_status'] ?? 0), + member_id: empty($post['new_adh']) ? null : (int)$post['new_adh'], + comments: $post['new_comment'] ?? '' ); $this->flash->addMessage( 'success_detected', @@ -729,15 +745,15 @@ public function doTake(Request $request, Response $response, int $id): Response try { $contribution = $service->take( - $object, - (int)($post['status'] ?? 0), - $post['expected_return'] ?? null, - empty($post[Adherent::PK]) ? null : (int)$post[Adherent::PK], - empty($post['rent_price']) + object: $object, + status_id: (int)($post['status'] ?? 0), + date_forecast: $post['expected_return'] ?? null, + member_id: empty($post[Adherent::PK]) ? null : (int)$post[Adherent::PK], + rent_price: empty($post['rent_price']) ? null //FIXME: better currency format handler : (float)str_replace([' ', ','], ['', '.'], $post['rent_price']), - empty($post['payment_type']) ? null : (int)$post['payment_type'] + payment_type: empty($post['payment_type']) ? null : (int)$post['payment_type'] ); } catch (LendException $e) { $this->flash->addMessage('error_detected', $e->getMessage()); @@ -832,7 +848,12 @@ private function lendResponse(Request $request, Response $response): Response */ private function getLendService(?LendPreferences $lendsprefs = null): LendService { - return new LendService($this->zdb, $this->preferences, $this->login, $lendsprefs ?? new LendPreferences($this->preferences)); + return new LendService( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $lendsprefs ?? new LendPreferences($this->preferences) + ); } // /CRUD - Update @@ -918,7 +939,13 @@ protected function doDelete(array $args, array $post): bool { $filters = $this->getFilters(); $lendsprefs = new LendPreferences($this->preferences); - $objects = new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs, $filters); + $objects = new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $lendsprefs, + filters: $filters + ); if (!is_array($post['id'])) { $ids = (array)$post['id']; diff --git a/lib/GaletteObjectsLend/Controllers/Crud/StatusController.php b/lib/GaletteObjectsLend/Controllers/Crud/StatusController.php index 4f57797..7c64f11 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/StatusController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/StatusController.php @@ -79,8 +79,13 @@ protected function applyOwnFilters(Pagination $filters, array $post): void */ protected function getListView(Pagination $filters): array { - $statuses = new Status($this->zdb, $this->preferences, $this->login, $filters); - $list = $statuses->getStatusList(true); + $statuses = new Status( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + $list = $statuses->getStatusList(as_stt: true); if (count($statuses->getActiveStockStatuses()) == 0) { $this->flash->addMessage( @@ -128,7 +133,7 @@ protected function fillEntity(LendCategory|LendStatus $entity, array $post): voi ->setText($post['text']) ->setInStock(isset($post['in_stock'])) ->setActive(isset($post['is_active'])) - ->setRentDayNumber(strlen($days) > 0 ? (int)$days : null); + ->setRentDayNumber($days !== '' ? (int)$days : null); } /** diff --git a/lib/GaletteObjectsLend/Controllers/MainController.php b/lib/GaletteObjectsLend/Controllers/MainController.php index 7dc69d3..0bf3042 100644 --- a/lib/GaletteObjectsLend/Controllers/MainController.php +++ b/lib/GaletteObjectsLend/Controllers/MainController.php @@ -46,7 +46,7 @@ public function preferences(Request $request, Response $response): Response $params = [ 'page_title' => _T('ObjectsLend preferences', 'objectslend'), //a rent is not a membership fee - 'type_cotis_options' => $ctypes->getList(false), + 'type_cotis_options' => $ctypes->getList(extent: false), 'lendsprefs' => (new LendPreferences($this->preferences))->toArray(), 'sample_data' => !(new SampleData($this->zdb))->hasObjects() ]; @@ -81,7 +81,7 @@ public function storePreferences(Request $request, Response $response): Response $type_id = $post[LendPreferences::GENERATED_CONTRIBUTION_TYPE_ID] ?? null; if ( isset($post[LendPreferences::AUTO_GENERATE_CONTRIBUTION]) - && !isset((new ContributionsTypes($this->zdb))->getList(false)[(int)$type_id]) + && !isset((new ContributionsTypes($this->zdb))->getList(extent: false)[(int)$type_id]) ) { $stored = false; $errors[] = _T("Generated contributions must be of a donation type.", "objectslend"); diff --git a/lib/GaletteObjectsLend/Controllers/PdfController.php b/lib/GaletteObjectsLend/Controllers/PdfController.php index 046fffa..472e2de 100644 --- a/lib/GaletteObjectsLend/Controllers/PdfController.php +++ b/lib/GaletteObjectsLend/Controllers/PdfController.php @@ -38,7 +38,12 @@ class PdfController extends GPdfController public function printObject(Request $request, Response $response, int $id): Response { $lendsprefs = new LendPreferences($this->preferences); - $object = (new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs))->getWithCurrentRent($id); + $object = (new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $lendsprefs + ))->getWithCurrentRent($id); $pdf = new PdfObject( $this->zdb, @@ -65,14 +70,20 @@ public function printObjects(Request $request, Response $response): Response if ($filters->orderby !== Objects::ORDERBY_CATEGORY) { $filters->orderby = Objects::ORDERBY_CATEGORY; } - $objects = new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs, $filters); - $list = $objects->getObjectsList(true, true, false); + $objects = new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $lendsprefs, + filters: $filters + ); + $list = $objects->getObjectsList(as_objects: true, count: true, limit: false); $pdf = new PdfObjects( - $this->zdb, - $this->preferences, - $lendsprefs, - $this->login + zdb: $this->zdb, + prefs: $this->preferences, + lendsprefs: $lendsprefs, + login: $this->login ); $pdf->drawList($list); diff --git a/lib/GaletteObjectsLend/Entity/LendCategory.php b/lib/GaletteObjectsLend/Entity/LendCategory.php index ff19e17..e1a5fa3 100644 --- a/lib/GaletteObjectsLend/Entity/LendCategory.php +++ b/lib/GaletteObjectsLend/Entity/LendCategory.php @@ -43,8 +43,6 @@ class LendCategory 'picture' => true ]; - private Db $zdb; - /** * Default constructor * @@ -52,10 +50,8 @@ class LendCategory * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database * @param ?array $deps Dependencies configuration, see LendCategory::$deps */ - public function __construct(Db $zdb, int|ArrayObject|null $args = null, ?array $deps = null) + public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null, ?array $deps = null) { - $this->zdb = $zdb; - if ($deps !== null) { $this->deps = array_merge( $this->deps, @@ -156,7 +152,7 @@ public function delete(): void } //a picture file removed here comes back from the database on rollback $picture = new CategoryPicture($this->category_id); - if ($picture->hasPicture() && !$picture->delete(false)) { + if ($picture->hasPicture() && !$picture->delete(transaction: false)) { throw new \RuntimeException('Unable to remove picture'); } $select = $this->zdb->select(LEND_PREFIX . LendObject::TABLE) @@ -191,7 +187,7 @@ public function delete(): void */ public function getName(bool $count = true): string { - $name = $this->name !== null ? $this->name : _T("No category", "objectslend"); + $name = $this->name ?? _T("No category", "objectslend"); if ($count === true) { $name .= " ({$this->objects_nb})"; diff --git a/lib/GaletteObjectsLend/Entity/LendObject.php b/lib/GaletteObjectsLend/Entity/LendObject.php index 0239c00..d1a9d53 100644 --- a/lib/GaletteObjectsLend/Entity/LendObject.php +++ b/lib/GaletteObjectsLend/Entity/LendObject.php @@ -78,7 +78,7 @@ class LendObject * @param Db $zdb Database instance * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database */ - public function __construct(private Db $zdb, int|ArrayObject|null $args = null) + public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null) { if (is_int($args)) { $select = $this->zdb->select(LEND_PREFIX . self::TABLE) @@ -202,7 +202,7 @@ public function delete(): void } //a picture file removed here comes back from the database on rollback $picture = $this->getPicture(); - if ($picture->hasPicture() && !$picture->delete(false)) { + if ($picture->hasPicture() && !$picture->delete(transaction: false)) { throw new \RuntimeException('Unable to remove picture'); } //remove rents diff --git a/lib/GaletteObjectsLend/Entity/LendRent.php b/lib/GaletteObjectsLend/Entity/LendRent.php index 50c83ac..3a9c91d 100644 --- a/lib/GaletteObjectsLend/Entity/LendRent.php +++ b/lib/GaletteObjectsLend/Entity/LendRent.php @@ -57,7 +57,7 @@ class LendRent * @param Db $zdb Database instance * @param int|ArrayObject|null $args Either an int with rent id, null, or a resultset row */ - public function __construct(private Db $zdb, int|ArrayObject|null $args = null) + public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null) { $this->date_begin = date('Y-m-d H:i:s'); @@ -256,7 +256,7 @@ public function getDateBegin(): string */ public function setDateBegin(string $date): self { - $this->date_begin = $this->parseDate($date, true) ?? $this->date_begin; + $this->date_begin = $this->parseDate($date, datetime: true) ?? $this->date_begin; return $this; } @@ -275,7 +275,7 @@ public function getDateForecast(): string */ public function setDateForecast(string $date): self { - $this->date_forecast = $this->parseDate($date, false); + $this->date_forecast = $this->parseDate($date, datetime: false); return $this; } @@ -294,7 +294,7 @@ public function getDateEnd(): string */ public function setDateEnd(string $date): self { - $this->date_end = $this->parseDate($date, true); + $this->date_end = $this->parseDate($date, datetime: true); return $this; } diff --git a/lib/GaletteObjectsLend/Entity/LendStatus.php b/lib/GaletteObjectsLend/Entity/LendStatus.php index 8f4034c..64089fe 100644 --- a/lib/GaletteObjectsLend/Entity/LendStatus.php +++ b/lib/GaletteObjectsLend/Entity/LendStatus.php @@ -24,8 +24,6 @@ class LendStatus public const string TABLE = 'status'; public const string PK = 'status_id'; - private Db $zdb; - /** @var array */ private array $fields = [ 'status_id' => 'integer', @@ -46,10 +44,8 @@ class LendStatus * @param Db $zdb Database instance * @param int|ArrayObject|null $args Can be null, an ID or a database row */ - public function __construct(Db $zdb, int|ArrayObject|null $args = null) + public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null) { - $this->zdb = $zdb; - if (is_int($args)) { $select = $this->zdb->select(LEND_PREFIX . self::TABLE) ->where([self::PK => $args]); diff --git a/lib/GaletteObjectsLend/Filters/ListFilters.php b/lib/GaletteObjectsLend/Filters/ListFilters.php index e56de44..4c2c5ae 100644 --- a/lib/GaletteObjectsLend/Filters/ListFilters.php +++ b/lib/GaletteObjectsLend/Filters/ListFilters.php @@ -134,7 +134,7 @@ public function __set(string $name, mixed $value): void */ protected function toChoice(string $name, mixed $value, array $choices): ?int { - if (is_numeric($value) && in_array((int)$value, $choices, true)) { + if (is_numeric($value) && in_array((int)$value, $choices, strict: true)) { return (int)$value; } @@ -144,7 +144,7 @@ protected function toChoice(string $name, mixed $value, array $choices): ?int static::class, $name, implode(', ', $choices), - var_export($value, true) + var_export($value, return: true) ), Analog::WARNING ); diff --git a/lib/GaletteObjectsLend/Filters/ObjectsList.php b/lib/GaletteObjectsLend/Filters/ObjectsList.php index ef935ac..79b89c0 100644 --- a/lib/GaletteObjectsLend/Filters/ObjectsList.php +++ b/lib/GaletteObjectsLend/Filters/ObjectsList.php @@ -80,12 +80,12 @@ public function highlight(string $html, string $field): string }; $search = trim($this->filter_str ?? '', '%'); - if (!in_array($field, $fields, true) || $search === '') { + if (!in_array($field, $fields, strict: true) || $search === '') { return $html; } //highlight text only, never inside HTML tags - $parts = preg_split('/(<[^>]*>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split(pattern: '/(<[^>]*>)/', subject: $html, limit: -1, flags: PREG_SPLIT_DELIM_CAPTURE); if ($parts === false) { return $html; } @@ -120,7 +120,7 @@ protected function setOwnFilter(string $name, mixed $value): bool switch ($name) { case 'selected': if (is_array($value)) { - $this->selected = array_map('intval', $value); + $this->selected = array_map(intval(...), $value); } elseif ($value !== null) { $this->warnType($name, 'an array', $value); } diff --git a/lib/GaletteObjectsLend/IO/PdfObject.php b/lib/GaletteObjectsLend/IO/PdfObject.php index a1f109f..66eaf0c 100644 --- a/lib/GaletteObjectsLend/IO/PdfObject.php +++ b/lib/GaletteObjectsLend/IO/PdfObject.php @@ -30,9 +30,6 @@ class PdfObject extends Pdf 'li', 'ol', 'p', 's', 'span', 'strong', 'sub', 'sup', 'u', 'ul' ]; - private Db $zdb; - private LendPreferences $lprefs; - /** * Main constructor * @@ -40,14 +37,11 @@ class PdfObject extends Pdf * @param Preferences $prefs Preferences instance * @param LendPreferences $lprefs Plugin Preferences instance */ - public function __construct(Db $zdb, Preferences $prefs, LendPreferences $lprefs) + public function __construct(private readonly Db $zdb, Preferences $prefs, private readonly LendPreferences $lprefs) { parent::__construct($prefs); // Disable Auto Page breaks - $this->SetAutoPageBreak(false, $this->footer_height + 10); - - $this->zdb = $zdb; - $this->lprefs = $lprefs; + $this->SetAutoPageBreak(auto: false, margin: $this->footer_height + 10); //TRANS: this is a filename $this->filename = _T('object_card', 'objectslend') . '.pdf'; } @@ -122,7 +116,7 @@ public function drawCard(LendObject $object): void $hpic = (int)round($wpic / $ratio); } - $this->Image($pic->getThumb($this->lprefs), 10, 10, $wpic, $hpic); + $this->Image(file: $pic->getThumb($this->lprefs), x: 10, y: 10, w: $wpic, h: $hpic); } $this->addCell(_T("Name", "objectslend"), $object->getName(), $wpic); @@ -136,12 +130,22 @@ public function drawCard(LendObject $object): void $this->addCell(_T("Serial number", "objectslend"), $object->getSerialNumber(), $wpic); } if ($this->lprefs->isEnabled(LendPreferences::VIEW_PRICE)) { - $this->addCell(_T("Price", "objectslend"), number_format($object->getPrice(), 2, ',', ' '), $wpic); + $this->addCell(_T("Price", "objectslend"), number_format( + num: $object->getPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ), $wpic); } if ($this->lprefs->isEnabled(LendPreferences::VIEW_LEND_PRICE)) { $this->addCell( _T("Borrow price", "objectslend"), - number_format($object->getRentPrice(), 2, ',', ' ') . ' €' + number_format( + num: $object->getRentPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ) . ' €' . ($object->isPricePerDay() ? ' ' . _T("(per day)", "objectslend") : ''), $wpic ); @@ -150,7 +154,12 @@ public function drawCard(LendObject $object): void $this->addCell(_T("Dimensions", "objectslend"), $object->getDimension() . ' ' . _T('Cm', 'objectslend'), $wpic); } if ($this->lprefs->isEnabled(LendPreferences::VIEW_WEIGHT)) { - $this->addCell(_T("Weight", "objectslend"), number_format($object->getWeight(), 3, ',', ' ') . ' ' . _T('Kg', 'objectslend'), $wpic); + $this->addCell(_T("Weight", "objectslend"), number_format( + num: $object->getWeight(), + decimals: 3, + decimal_separator: ',', + thousands_separator: ' ' + ) . ' ' . _T('Kg', 'objectslend'), $wpic); } $this->addCell(_T("Active", "objectslend"), $object->isObjectActive() ? 'X' : '', $wpic); $this->addCell(_T("Location", "objectslend"), $object->getStatusText(), $wpic); @@ -175,24 +184,61 @@ public function drawCard(LendObject $object): void $col_comments = 40; $this->SetFont(Pdf::FONT, 'B', 10); - $this->Cell(0, 0, _T("History of object loans", "objectslend"), 0, 1, 'C'); + $this->Cell( + w: 0, + h: 0, + txt: _T("History of object loans", "objectslend"), + border: 0, + ln: 1, + align: 'C' + ); $this->Ln(); - $this->Cell($col_begin, 0, $this->stretchHead(_T("Begin", "objectslend"), $col_begin), 'B'); - $this->Cell($col_end, 0, $this->stretchHead(_T("End", "objectslend"), $col_end), 'B'); - $this->Cell($col_status, 0, $this->stretchHead(_T("Status", "objectslend"), $col_status), 'B'); - $this->Cell($col_stock, 0, $this->stretchHead(_T("In stock", "objectslend"), $col_stock), 'B'); - $this->Cell($col_adh, 0, $this->stretchHead(_T("Member", "objectslend"), $col_adh), 'B'); - $this->Cell($col_comments, 0, $this->stretchHead(_T("Comments", "objectslend"), $col_comments), 'B'); + $this->Cell( + w: $col_begin, + h: 0, + txt: $this->stretchHead(_T("Begin", "objectslend"), $col_begin), + border: 'B' + ); + $this->Cell( + w: $col_end, + h: 0, + txt: $this->stretchHead(_T("End", "objectslend"), $col_end), + border: 'B' + ); + $this->Cell( + w: $col_status, + h: 0, + txt: $this->stretchHead(_T("Status", "objectslend"), $col_status), + border: 'B' + ); + $this->Cell( + w: $col_stock, + h: 0, + txt: $this->stretchHead(_T("In stock", "objectslend"), $col_stock), + border: 'B' + ); + $this->Cell( + w: $col_adh, + h: 0, + txt: $this->stretchHead(_T("Member", "objectslend"), $col_adh), + border: 'B' + ); + $this->Cell( + w: $col_comments, + h: 0, + txt: $this->stretchHead(_T("Comments", "objectslend"), $col_comments), + border: 'B' + ); $this->Ln(); $this->SetFont(Pdf::FONT, '', 9); foreach ($rents as $rt) { - $this->Cell($col_begin, 0, $this->cut($rt->getDateBegin(), $col_begin), 'B'); - $this->Cell($col_end, 0, $this->cut($rt->getDateEnd(), $col_end), 'B'); - $this->Cell($col_status, 0, $this->cut($rt->getStatusText(), $col_status), 'B'); - $this->Cell($col_stock, 0, $rt->isInStock() ? ' X' : '', 'B'); - $this->Cell($col_adh, 0, $this->cut($rt->getMemberName(), $col_adh), 'B'); - $this->Cell($col_comments, 0, $this->cut($rt->getComments(), $col_comments), 'B'); + $this->Cell(w: $col_begin, h: 0, txt: $this->cut($rt->getDateBegin(), $col_begin), border: 'B'); + $this->Cell(w: $col_end, h: 0, txt: $this->cut($rt->getDateEnd(), $col_end), border: 'B'); + $this->Cell(w: $col_status, h: 0, txt: $this->cut($rt->getStatusText(), $col_status), border: 'B'); + $this->Cell(w: $col_stock, h: 0, txt: $rt->isInStock() ? ' X' : '', border: 'B'); + $this->Cell(w: $col_adh, h: 0, txt: $this->cut($rt->getMemberName(), $col_adh), border: 'B'); + $this->Cell(w: $col_comments, h: 0, txt: $this->cut($rt->getComments(), $col_comments), border: 'B'); $this->Ln(); } } @@ -221,7 +267,7 @@ private function addCell(string $title, string $value, int $width): void if ($i++ > 0) { $this->Cell($width + $padding, 0, ''); } - $this->MultiCell(0, 0, $w, 0, 'L'); + $this->MultiCell(w: 0, h: 0, txt: $w, border: 0, align: 'L'); } } @@ -247,6 +293,19 @@ private function addHtmlCell(string $title, string $html, int $width): void $this->Cell($padding, 0, $this->cut($title, $padding)); $this->SetFont(Pdf::FONT, '', 9); - $this->MultiCell(0, 0, $html, 0, 'L', false, 1, null, null, true, 0, true); + $this->MultiCell( + w: 0, + h: 0, + txt: $html, + border: 0, + align: 'L', + fill: false, + ln: 1, + x: null, + y: null, + reseth: true, + stretch: 0, + ishtml: true + ); } } diff --git a/lib/GaletteObjectsLend/IO/PdfObjects.php b/lib/GaletteObjectsLend/IO/PdfObjects.php index 99de8d5..4b4c272 100644 --- a/lib/GaletteObjectsLend/IO/PdfObjects.php +++ b/lib/GaletteObjectsLend/IO/PdfObjects.php @@ -28,10 +28,6 @@ class PdfObjects extends Pdf { public const int LIST_FONT = self::FONT_SIZE - 2; - private Db $zdb; - private LendPreferences $lendsprefs; - private Login $login; - /** * Main constructor, set creator and author * @@ -41,20 +37,17 @@ class PdfObjects extends Pdf * @param Login $login Login instance */ public function __construct( - Db $zdb, + private readonly Db $zdb, Preferences $prefs, - LendPreferences $lendsprefs, - Login $login, + private readonly LendPreferences $lendsprefs, + private readonly Login $login, ) { parent::__construct($prefs); // Enable Auto Page breaks - $this->SetAutoPageBreak(true, $this->footer_height + 10); + $this->SetAutoPageBreak(auto: true, margin: $this->footer_height + 10); //TRANS: this is a filename $this->filename = _T('objects_cards', 'objectslend') . '.pdf'; - $this->zdb = $zdb; - $this->lendsprefs = $lendsprefs; - $this->login = $login; } /** @@ -86,26 +79,39 @@ public function Header(): void // @phpcs:enable $this->SetFont(Pdf::FONT, 'B'); $x = $this->getX(); - $this->Cell(0, 10, _T("Objects list", "objectslend"), 0, 0, 'C', false, '', 0, false, 'M', 'M'); + $this->Cell( + w: 0, + h: 10, + txt: _T("Objects list", "objectslend"), + border: 0, + ln: 0, + align: 'C', + fill: false, + link: '', + stretch: 0, + ignore_min_height: false, + calign: 'M', + valign: 'M' + ); $this->SetFont(Pdf::FONT, '', self::LIST_FONT); $this->setX($x); $this->Cell( - 0, - 10, - str_replace( + w: 0, + h: 10, + txt: str_replace( '%date', date(_T("Y-m-d")), _T("Printed on %date", "objectslend") ), - 0, - 0, - 'R', - false, - '', - 0, - false, - 'M', - 'M' + border: 0, + ln: 0, + align: 'R', + fill: false, + link: '', + stretch: 0, + ignore_min_height: false, + calign: 'M', + valign: 'M' ); } @@ -132,18 +138,114 @@ public function drawList(array $objects): void $w_date = 22; $w_adherent = 26; - $this->Cell($w_checkbox, 0, $this->stretchHead('', $w_checkbox), 1, 0, 'C', true); - $this->Cell($w_name, 0, $this->stretchHead(_T("Name", "objectslend"), $w_name), 1, 0, 'C', true); - $this->Cell($w_description, 0, $this->stretchHead(_T("Description", "objectslend"), $w_description), 1, 0, 'C', true); - $this->Cell($w_serial, 0, $this->stretchHead(_T("Serial", "objectslend"), $w_serial), 1, 0, 'C', true); - $this->Cell($w_price, 0, $this->stretchHead(_T("Price", "objectslend"), $w_price), 1, 0, 'C', true); - $this->Cell($w_price, 0, $this->stretchHead(_T("Borrow price", "objectslend"), $w_price), 1, 0, 'C', true); - $this->Cell($w_dimension, 0, $this->stretchHead(_T("Dimensions", "objectslend"), $w_dimension), 1, 0, 'C', true); - $this->Cell($w_weight, 0, $this->stretchHead(_T("Weight", "objectslend"), $w_weight), 1, 0, 'C', true); - $this->Cell($w_status, 0, $this->stretchHead(_T("Status", "objectslend"), $w_status), 1, 0, 'C', true); - $this->Cell($w_date, 0, $this->stretchHead(_T("Since", "objectslend"), $w_date), 1, 0, 'C', true); - $this->Cell($w_adherent, 0, $this->stretchHead(_T("Member", "objectslend"), $w_adherent), 1, 0, 'C', true); - $this->Cell($w_date, 0, $this->stretchHead(_T("Return", "objectslend"), $w_date), 1, 1, 'C', true); + $this->Cell( + w: $w_checkbox, + h: 0, + txt: $this->stretchHead('', $w_checkbox), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_name, + h: 0, + txt: $this->stretchHead(_T("Name", "objectslend"), $w_name), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_description, + h: 0, + txt: $this->stretchHead(_T("Description", "objectslend"), $w_description), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_serial, + h: 0, + txt: $this->stretchHead(_T("Serial", "objectslend"), $w_serial), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_price, + h: 0, + txt: $this->stretchHead(_T("Price", "objectslend"), $w_price), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_price, + h: 0, + txt: $this->stretchHead(_T("Borrow price", "objectslend"), $w_price), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_dimension, + h: 0, + txt: $this->stretchHead(_T("Dimensions", "objectslend"), $w_dimension), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_weight, + h: 0, + txt: $this->stretchHead(_T("Weight", "objectslend"), $w_weight), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_status, + h: 0, + txt: $this->stretchHead(_T("Status", "objectslend"), $w_status), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_date, + h: 0, + txt: $this->stretchHead(_T("Since", "objectslend"), $w_date), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_adherent, + h: 0, + txt: $this->stretchHead(_T("Member", "objectslend"), $w_adherent), + border: 1, + ln: 0, + align: 'C', + fill: true + ); + $this->Cell( + w: $w_date, + h: 0, + txt: $this->stretchHead(_T("Return", "objectslend"), $w_date), + border: 1, + ln: 1, + align: 'C', + fill: true + ); $this->SetFont(''); @@ -164,7 +266,14 @@ public function drawList(array $objects): void if (($this->login->isAdmin() || $this->login->isStaff()) && $sum_price > 0) { $width = $w_checkbox + $w_name + $w_description + $w_serial + $w_price; - $this->Cell($width, 0, number_format($sum_price, 2, ',', ''), '', 0, 'R'); + $this->Cell( + w: $width, + h: 0, + txt: number_format(num: $sum_price, decimals: 2, decimal_separator: ',', thousands_separator: ''), + border: '', + ln: 0, + align: 'R' + ); $sum_price = 0; $this->Ln(); } @@ -173,13 +282,13 @@ public function drawList(array $objects): void $category = new LendCategory($this->zdb, $category_id); $text = str_replace( '%category', - $category->getName(false), + $category->getName(count: false), _T("Category: %category", "objectslend") ); } else { $text = _T("No category", "objectslend"); } - $this->Cell(0, 0, $text, 0, 1, 'C'); + $this->Cell(w: 0, h: 0, txt: $text, border: 0, ln: 1, align: 'C'); $current_category = $category_id; $this->SetFont(''); @@ -192,18 +301,121 @@ public function drawList(array $objects): void } $fill = !$object->inStock(); - $this->Cell($w_checkbox, 0, '□', 'B', 0, 'L', $fill); - $this->Cell($w_name, 0, $this->cut($object->getName(), $w_name), 'B', 0, 'L', $fill); - $this->Cell($w_description, 0, $this->cut($this->oneLine($object->getDescriptionHtml()), $w_description), 'B', 0, 'L', $fill); - $this->Cell($w_serial, 0, $this->cut($object->getSerialNumber(), $w_serial), 'B', 0, 'L', $fill); - $this->Cell($w_price, 0, $this->cut(number_format($object->getPrice(), 2, ',', ' '), $w_price), 'B', 0, 'R', $fill); - $this->Cell($w_price, 0, $this->cut(number_format($object->getRentPrice(), 2, ',', ' '), $w_price) . '€', 'B', 0, 'R', $fill); - $this->Cell($w_dimension, 0, $this->cut($object->getDimension(), $w_dimension), 'B', 0, 'L', $fill); - $this->Cell($w_weight, 0, $this->cut(number_format($object->getWeight(), 3, ',', ' '), $w_weight), 'B', 0, 'R', $fill); - $this->Cell($w_status, 0, $this->cut($object->getStatusText(), $w_status), 'B', 0, 'L', $fill); - $this->Cell($w_date, 0, $this->cut($object->getDateBegin(), $w_date), 'B', 0, 'L', $fill); - $this->Cell($w_adherent, 0, $this->cut($object->getMemberName(), $w_adherent), 'B', 0, 'L', $fill); - $this->Cell($w_date, 0, $this->cut($object->getDateForecast(), $w_date), 'B', 1, 'L', $fill); + $this->Cell(w: $w_checkbox, h: 0, txt: '□', border: 'B', ln: 0, align: 'L', fill: $fill); + $this->Cell( + w: $w_name, + h: 0, + txt: $this->cut($object->getName(), $w_name), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_description, + h: 0, + txt: $this->cut($this->oneLine($object->getDescriptionHtml()), $w_description), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_serial, + h: 0, + txt: $this->cut($object->getSerialNumber(), $w_serial), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_price, + h: 0, + txt: $this->cut(number_format( + num: $object->getPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ), $w_price), + border: 'B', + ln: 0, + align: 'R', + fill: $fill + ); + $this->Cell( + w: $w_price, + h: 0, + txt: $this->cut(number_format( + num: $object->getRentPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ), $w_price) . '€', + border: 'B', + ln: 0, + align: 'R', + fill: $fill + ); + $this->Cell( + w: $w_dimension, + h: 0, + txt: $this->cut($object->getDimension(), $w_dimension), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_weight, + h: 0, + txt: $this->cut(number_format( + num: $object->getWeight(), + decimals: 3, + decimal_separator: ',', + thousands_separator: ' ' + ), $w_weight), + border: 'B', + ln: 0, + align: 'R', + fill: $fill + ); + $this->Cell( + w: $w_status, + h: 0, + txt: $this->cut($object->getStatusText(), $w_status), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_date, + h: 0, + txt: $this->cut($object->getDateBegin(), $w_date), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_adherent, + h: 0, + txt: $this->cut($object->getMemberName(), $w_adherent), + border: 'B', + ln: 0, + align: 'L', + fill: $fill + ); + $this->Cell( + w: $w_date, + h: 0, + txt: $this->cut($object->getDateForecast(), $w_date), + border: 'B', + ln: 1, + align: 'L', + fill: $fill + ); if ($this->login->isAdmin() || $this->login->isStaff()) { $sum_price += $object->getPrice(); @@ -213,20 +425,34 @@ public function drawList(array $objects): void if (($this->login->isAdmin() || $this->login->isStaff())) { $width = $w_checkbox + $w_name + $w_description + $w_serial + $w_price; - $this->Cell($width, 0, number_format($sum_price, 2, ',', ''), '', 0, 'R'); + $this->Cell( + w: $width, + h: 0, + txt: number_format(num: $sum_price, decimals: 2, decimal_separator: ',', thousands_separator: ''), + border: '', + ln: 0, + align: 'R' + ); $this->Ln(); $this->Ln(); - $this->Cell($width, 0, _T("Total:", "objectslend") . ' ' . number_format($grant_total, 2, ',', ''), '', 0, 'R'); + $this->Cell( + w: $width, + h: 0, + txt: _T("Total:", "objectslend") . ' ' . number_format(num: $grant_total, decimals: 2, decimal_separator: ',', thousands_separator: ''), + border: '', + ln: 0, + align: 'R' + ); $this->Ln(); } $this->Ln(); - $this->Cell($w_price, 0, '', true, 0, '', true); - $this->Cell(0, 0, _T("Borrowed", "objectslend"), 0, 1); - $this->Cell($w_price, 0, '', true); - $this->Cell(0, 0, _T("Available", "objectslend"), 0, 1); + $this->Cell(w: $w_price, h: 0, txt: '', border: true, ln: 0, align: '', fill: true); + $this->Cell(w: 0, h: 0, txt: _T("Borrowed", "objectslend"), border: 0, ln: 1); + $this->Cell(w: $w_price, h: 0, txt: '', border: true); + $this->Cell(w: 0, h: 0, txt: _T("Available", "objectslend"), border: 0, ln: 1); } /** diff --git a/lib/GaletteObjectsLend/LendPreferences.php b/lib/GaletteObjectsLend/LendPreferences.php index 4347259..046ae6a 100644 --- a/lib/GaletteObjectsLend/LendPreferences.php +++ b/lib/GaletteObjectsLend/LendPreferences.php @@ -23,7 +23,7 @@ * * @author Johan Cwiklinski */ -final class LendPreferences +final readonly class LendPreferences { public const string PREFIX = 'pref_objectslend_'; @@ -67,7 +67,7 @@ final class LendPreferences * * @param Preferences $preferences Core preferences */ - public function __construct(private readonly Preferences $preferences) + public function __construct(private Preferences $preferences) { } diff --git a/lib/GaletteObjectsLend/LendService.php b/lib/GaletteObjectsLend/LendService.php index f20a3a9..41ba5a2 100644 --- a/lib/GaletteObjectsLend/LendService.php +++ b/lib/GaletteObjectsLend/LendService.php @@ -44,10 +44,10 @@ class LendService * @param LendPreferences $lendsprefs Plugin preferences */ public function __construct( - private Db $zdb, - private CorePreferences $preferences, - private Login $login, - private LendPreferences $lendsprefs + private readonly Db $zdb, + private readonly CorePreferences $preferences, + private readonly Login $login, + private readonly LendPreferences $lendsprefs ) { } @@ -58,7 +58,12 @@ public function __construct( */ public function getObject(int $id): LendObject { - return (new Objects($this->zdb, $this->preferences, $this->login, $this->lendsprefs))->getWithCurrentRent($id); + return (new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $this->lendsprefs + ))->getWithCurrentRent($id); } /** @@ -175,10 +180,21 @@ public function take( } return $this->inTransaction(function () use ($object, $status_id, $member_id, $date_forecast, $rent_price, $payment_type) { - $rent = $this->openRent($object, $status_id, $member_id, '', $date_forecast); + $rent = $this->openRent( + object: $object, + status_id: $status_id, + member_id: $member_id, + comments: '', + date_forecast: $date_forecast + ); if ($this->lendsprefs->isEnabled(LendPreferences::AUTO_GENERATE_CONTRIBUTION) && $rent_price > 0) { - return $this->storeContribution($object, $rent, $rent_price, $payment_type); + return $this->storeContribution( + object: $object, + rent: $rent, + amount: $rent_price, + payment_type: $payment_type + ); } return null; }); @@ -215,7 +231,7 @@ public function giveBack(LendObject $object, int $status_id, string $comments = } return $this->inTransaction( - fn() => $this->openRent($object, $status_id, null, $comments) + fn() => $this->openRent(object: $object, status_id: $status_id, member_id: null, comments: $comments) ); } @@ -253,7 +269,7 @@ public function changeStatus( } return $this->inTransaction( - fn() => $this->openRent($object, $status_id, $member_id, $comments) + fn() => $this->openRent(object: $object, status_id: $status_id, member_id: $member_id, comments: $comments) ); } @@ -294,10 +310,10 @@ public function giveBackMemberObjects(int $member_id): void continue; } $this->openRent( - $this->getObject($object_id), - $status_id, - null, - _T("Returned on member removal", "objectslend") + object: $this->getObject($object_id), + status_id: $status_id, + member_id: null, + comments: _T("Returned on member removal", "objectslend") ); } }); @@ -407,9 +423,24 @@ private function storeContribution( $object->getName(), $object->getDescription(), $object->getSerialNumber(), - number_format($object->getPrice(), 2, ',', ' '), - number_format($object->getRentPrice(), 2, ',', ' '), - number_format($object->getWeight(), 3, ',', ' '), + number_format( + num: $object->getPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ), + number_format( + num: $object->getRentPrice(), + decimals: 2, + decimal_separator: ',', + thousands_separator: ' ' + ), + number_format( + num: $object->getWeight(), + decimals: 3, + decimal_separator: ',', + thousands_separator: ' ' + ), $object->getDimension() ], $this->lendsprefs->getContributionText() @@ -447,10 +478,7 @@ private function storeContribution( 'Unable to store contribution for object #' . $object->getId() . ': ' . $e->getMessage(), Analog::ERROR ); - throw new LendException( - _T("An error occurred while storing the contribution.", "objectslend"), - previous: $e - ); + throw new LendException(_T("An error occurred while storing the contribution.", "objectslend"), $e->getCode(), previous: $e); } return $contrib; diff --git a/lib/GaletteObjectsLend/Repository/AbstractRepository.php b/lib/GaletteObjectsLend/Repository/AbstractRepository.php index 4b303aa..29dd518 100644 --- a/lib/GaletteObjectsLend/Repository/AbstractRepository.php +++ b/lib/GaletteObjectsLend/Repository/AbstractRepository.php @@ -56,7 +56,14 @@ public function __construct( string $entity, Pagination $filters ) { - parent::__construct($zdb, $preferences, $login, 'Entity\\' . $entity, 'GaletteObjectsLend', LEND_PREFIX); + parent::__construct( + zdb: $zdb, + preferences: $preferences, + login: $login, + entity: 'Entity\\' . $entity, + ns: 'GaletteObjectsLend', + prefix: LEND_PREFIX + ); $this->filters = $filters; } @@ -131,7 +138,7 @@ private function proceedCount(Select $select): void $counted->reset(Select::JOINS); $counted->columns(['id' => new Expression(static::ALIAS . '.' . static::PK)]); foreach ($select->joins as $join) { - $counted->join($join['name'], $join['on'], [], $join['type']); + $counted->join(name: $join['name'], on: $join['on'], columns: [], type: $join['type']); } $count_select = new Select(['counted' => $counted]); diff --git a/lib/GaletteObjectsLend/Repository/Categories.php b/lib/GaletteObjectsLend/Repository/Categories.php index 9410e5a..312aa51 100644 --- a/lib/GaletteObjectsLend/Repository/Categories.php +++ b/lib/GaletteObjectsLend/Repository/Categories.php @@ -59,7 +59,13 @@ class Categories extends AbstractRepository */ public function __construct(Db $zdb, Preferences $preferences, Login $login, ?CategoriesList $filters = null) { - parent::__construct($zdb, $preferences, $login, 'LendCategory', $filters ?? new CategoriesList()); + parent::__construct( + zdb: $zdb, + preferences: $preferences, + login: $login, + entity: 'LendCategory', + filters: $filters ?? new CategoriesList() + ); } /** @@ -85,7 +91,7 @@ public function getCategoriesList(bool $as_cat = false, bool $count = true, bool */ public function getList(bool $as_cat = false): array|ResultSet { - return $this->fetchList($as_cat, false, false); + return $this->fetchList($as_cat, count: false, limit: false); } /** @@ -101,20 +107,20 @@ protected function buildSelect(): Select ]); $select->join( - ['o' => PREFIX_DB . LEND_PREFIX . LendObject::TABLE], - 'o.' . LendCategory::PK . '=c.' . LendCategory::PK, - [], - $select::JOIN_LEFT + name: ['o' => PREFIX_DB . LEND_PREFIX . LendObject::TABLE], + on: 'o.' . LendCategory::PK . '=c.' . LendCategory::PK, + columns: [], + type: $select::JOIN_LEFT ); //categories of filtered objects only if ($this->filters->objects_filters instanceof ObjectsList) { $objects = new Objects( - $this->zdb, - $this->preferences, - $this->login, - new LendPreferences($this->preferences), - $this->filters->objects_filters + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: new LendPreferences($this->preferences), + filters: $this->filters->objects_filters ); $objects->applyFilters($select); } diff --git a/lib/GaletteObjectsLend/Repository/Objects.php b/lib/GaletteObjectsLend/Repository/Objects.php index f90f0c2..3ebad4f 100644 --- a/lib/GaletteObjectsLend/Repository/Objects.php +++ b/lib/GaletteObjectsLend/Repository/Objects.php @@ -75,10 +75,16 @@ public function __construct( Db $zdb, Preferences $preferences, Login $login, - private LendPreferences $lendsprefs, + private readonly LendPreferences $lendsprefs, ?ObjectsList $filters = null ) { - parent::__construct($zdb, $preferences, $login, 'LendObject', $filters ?? new ObjectsList()); + parent::__construct( + zdb: $zdb, + preferences: $preferences, + login: $login, + entity: 'LendObject', + filters: $filters ?? new ObjectsList() + ); } /** @@ -104,7 +110,7 @@ public function getObjectsList(bool $as_objects = false, bool $count = true, boo */ public function getList(bool $as_objects = false): array|ResultSet { - return $this->fetchList($as_objects, false, false); + return $this->fetchList($as_objects, count: false, limit: false); } /** @@ -123,7 +129,7 @@ public function removeObjects(array $ids): void //a picture file removed here comes back from the database on rollback foreach ($ids as $id) { $picture = new ObjectPicture($id); - if ($picture->hasPicture() && !$picture->delete(false)) { + if ($picture->hasPicture() && !$picture->delete(transaction: false)) { throw new \RuntimeException('Unable to remove picture for object #' . $id); } } @@ -160,31 +166,31 @@ private function buildBaseSelect(): Select $select = $this->zdb->select(LEND_PREFIX . self::TABLE, 'o'); $select->join( - ['r' => PREFIX_DB . LEND_PREFIX . LendRent::TABLE], - 'o.' . LendRent::PK . '=r.' . LendRent::PK, - ['date_begin', 'date_forecast', 'date_end', 'comments'], - $select::JOIN_LEFT + name: ['r' => PREFIX_DB . LEND_PREFIX . LendRent::TABLE], + on: 'o.' . LendRent::PK . '=r.' . LendRent::PK, + columns: ['date_begin', 'date_forecast', 'date_end', 'comments'], + type: $select::JOIN_LEFT ); $select->join( - ['s' => PREFIX_DB . LEND_PREFIX . LendStatus::TABLE], - 'r.' . LendStatus::PK . '=s.' . LendStatus::PK, - ['status_id', 'status_text', 'in_stock'], - $select::JOIN_LEFT + name: ['s' => PREFIX_DB . LEND_PREFIX . LendStatus::TABLE], + on: 'r.' . LendStatus::PK . '=s.' . LendStatus::PK, + columns: ['status_id', 'status_text', 'in_stock'], + type: $select::JOIN_LEFT ); $select->join( - ['a' => PREFIX_DB . Adherent::TABLE], - 'r.adherent_id=a.' . Adherent::PK, - [Adherent::PK, 'nom_adh', 'prenom_adh'], - $select::JOIN_LEFT + name: ['a' => PREFIX_DB . Adherent::TABLE], + on: 'r.adherent_id=a.' . Adherent::PK, + columns: [Adherent::PK, 'nom_adh', 'prenom_adh'], + type: $select::JOIN_LEFT ); $select->join( - ['c' => PREFIX_DB . LEND_PREFIX . LendCategory::TABLE], - 'o.' . LendCategory::PK . '=c.' . LendCategory::PK, - ['cat_active' => 'is_active', 'cat_name' => 'name'], - $select::JOIN_LEFT + name: ['c' => PREFIX_DB . LEND_PREFIX . LendCategory::TABLE], + on: 'o.' . LendCategory::PK . '=c.' . LendCategory::PK, + columns: ['cat_active' => 'is_active', 'cat_name' => 'name'], + type: $select::JOIN_LEFT ); return $select; diff --git a/lib/GaletteObjectsLend/Repository/Rents.php b/lib/GaletteObjectsLend/Repository/Rents.php index ca19deb..81d5b5d 100644 --- a/lib/GaletteObjectsLend/Repository/Rents.php +++ b/lib/GaletteObjectsLend/Repository/Rents.php @@ -28,7 +28,7 @@ class Rents * * @param Db $zdb Database instance */ - public function __construct(private Db $zdb) + public function __construct(private readonly Db $zdb) { } @@ -44,10 +44,10 @@ public function getForObject(int $object_id, bool $only_last = false): array { $select = $this->zdb->select(LEND_PREFIX . LendRent::TABLE, 'r') ->join( - ['a' => PREFIX_DB . Adherent::TABLE], - 'a.' . Adherent::PK . ' = r.adherent_id', - ['prenom_adh', 'nom_adh'], - Select::JOIN_LEFT + name: ['a' => PREFIX_DB . Adherent::TABLE], + on: 'a.' . Adherent::PK . ' = r.adherent_id', + columns: ['prenom_adh', 'nom_adh'], + type: Select::JOIN_LEFT ) ->join( ['s' => PREFIX_DB . LEND_PREFIX . LendStatus::TABLE], diff --git a/lib/GaletteObjectsLend/Repository/Status.php b/lib/GaletteObjectsLend/Repository/Status.php index 82843c2..7ed0d41 100644 --- a/lib/GaletteObjectsLend/Repository/Status.php +++ b/lib/GaletteObjectsLend/Repository/Status.php @@ -58,7 +58,13 @@ class Status extends AbstractRepository */ public function __construct(Db $zdb, Preferences $preferences, Login $login, ?StatusList $filters = null) { - parent::__construct($zdb, $preferences, $login, 'LendStatus', $filters ?? new StatusList()); + parent::__construct( + zdb: $zdb, + preferences: $preferences, + login: $login, + entity: 'LendStatus', + filters: $filters ?? new StatusList() + ); } /** @@ -84,7 +90,7 @@ public function getStatusList(bool $as_stt = false, bool $count = true, bool $li */ public function getList(bool $as_stt = false): array|ResultSet { - return $this->fetchList($as_stt, false, false); + return $this->fetchList($as_stt, count: false, limit: false); } /** @@ -145,7 +151,7 @@ protected function createEntity(ArrayObject $row): LendStatus */ public function getActiveTakeAwayStatuses(): array { - return $this->getActiveStatuses(false); + return $this->getActiveStatuses(in_stock: false); } /** @@ -155,7 +161,7 @@ public function getActiveTakeAwayStatuses(): array */ public function getActiveStockStatuses(): array { - return $this->getActiveStatuses(true); + return $this->getActiveStatuses(in_stock: true); } /** diff --git a/lib/GaletteObjectsLend/SampleData.php b/lib/GaletteObjectsLend/SampleData.php index 5bdda6a..c392d89 100644 --- a/lib/GaletteObjectsLend/SampleData.php +++ b/lib/GaletteObjectsLend/SampleData.php @@ -186,18 +186,18 @@ public function remove(): array } $removed['categories'] = $this->removeUnused( - LEND_PREFIX . LendCategory::TABLE, - LendCategory::PK, - 'name', - array_column($data['categories'], 'name'), - LEND_PREFIX . LendObject::TABLE + table: LEND_PREFIX . LendCategory::TABLE, + pk: LendCategory::PK, + column: 'name', + names: array_column($data['categories'], 'name'), + referencer: LEND_PREFIX . LendObject::TABLE ); $removed['statuses'] = $this->removeUnused( - LEND_PREFIX . LendStatus::TABLE, - LendStatus::PK, - 'status_text', - array_column($data['statuses'], 'text'), - LEND_PREFIX . LendRent::TABLE + table: LEND_PREFIX . LendStatus::TABLE, + pk: LendStatus::PK, + column: 'status_text', + names: array_column($data['statuses'], 'text'), + referencer: LEND_PREFIX . LendRent::TABLE ); if ($need_transaction) { @@ -258,7 +258,7 @@ private function read(): array if ($contents === false) { throw new \RuntimeException(sprintf('Unable to read sample data file %s', $this->file)); } - $data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR); + $data = json_decode($contents, associative: true, flags: JSON_THROW_ON_ERROR); if (!is_array($data) || !isset($data['categories'], $data['statuses'], $data['objects'])) { throw new \RuntimeException(sprintf('Invalid sample data file %s', $this->file)); } diff --git a/tests/GaletteObjectsLend/Controllers/tests/units/CategoriesController.php b/tests/GaletteObjectsLend/Controllers/tests/units/CategoriesController.php index d19b184..4898380 100644 --- a/tests/GaletteObjectsLend/Controllers/tests/units/CategoriesController.php +++ b/tests/GaletteObjectsLend/Controllers/tests/units/CategoriesController.php @@ -42,7 +42,7 @@ public function tearDown(): void private function addCategory(string $name): LendCategory { $category = new LendCategory($this->zdb); - $category->setName($name)->setActive(true); + $category->setName($name)->setActive(active: true); $category->store(); return $category; } @@ -69,8 +69,13 @@ public function testListAndFilter(): void $filters = $this->session->plugin_objectslend_categories_filter; $this->assertSame('', $filters->filter_str); - $categories = new Categories($this->zdb, $this->preferences, $this->login, $filters); - $this->assertCount(1, $categories->getCategoriesList(true)); + $categories = new Categories( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + $this->assertCount(1, $categories->getCategoriesList(as_cat: true)); $test_response = $this->app->handle($this->createRequest(route_name: 'objectslend_categories')); $body = (string)$test_response->getBody(); @@ -97,10 +102,12 @@ public function testAddAndEdit(): void ); $this->expectFlashData(['success_detected' => ['Category has been saved']]); - $list = (new Categories($this->zdb, $this->preferences, $this->login))->getList(true); + $list = (new Categories($this->zdb, $this->preferences, $this->login))->getList( + as_cat: true + ); $this->assertCount(1, $list); $category = $list[0]; - $this->assertSame('Tools', $category->getName(false)); + $this->assertSame('Tools', $category->getName(count: false)); $this->assertTrue($category->isActive()); $test_response = $this->app->handle( @@ -118,7 +125,7 @@ public function testAddAndEdit(): void $this->expectFlashData(['success_detected' => ['Category has been saved']]); $category = new LendCategory($this->zdb, $category->getId()); - $this->assertSame('Tools (edited)', $category->getName(false)); + $this->assertSame('Tools (edited)', $category->getName(count: false)); $this->assertFalse($category->isActive()); } diff --git a/tests/GaletteObjectsLend/Controllers/tests/units/ObjectsController.php b/tests/GaletteObjectsLend/Controllers/tests/units/ObjectsController.php index c0995e0..ab11e7a 100644 --- a/tests/GaletteObjectsLend/Controllers/tests/units/ObjectsController.php +++ b/tests/GaletteObjectsLend/Controllers/tests/units/ObjectsController.php @@ -47,15 +47,15 @@ public function setUp(): void $status = new LendStatus($this->zdb); $status->setText('In stock'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $this->instock_status = $status->getId(); $status = new LendStatus($this->zdb); $status->setText('Lent'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $this->lent_status = $status->getId(); @@ -238,7 +238,7 @@ private function returnRequest(array $data = []): \Slim\Psr7\Request */ public function testMemberCannotTakeForAnotherMember(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $member_two = $this->getMemberTwo(); @@ -260,7 +260,7 @@ public function testMemberCannotTakeForAnotherMember(): void */ public function testAdminTakeForAMember(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $member_one = $this->getMemberOne(); $this->logSuperAdmin(); @@ -280,7 +280,7 @@ public function testAdminTakeForAMember(): void */ public function testTakeLentObject(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -307,7 +307,7 @@ public function testTakeLentObject(): void */ public function testTakeWithInStockStatus(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->logSuperAdmin(); $test_response = $this->app->handle( @@ -324,7 +324,7 @@ public function testTakeWithInStockStatus(): void */ public function testAdminReturnWhenMemberRentDisabled(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -343,7 +343,7 @@ public function testAdminReturnWhenMemberRentDisabled(): void */ public function testMemberReturnObjectHeldByAnotherMember(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -362,7 +362,7 @@ public function testMemberReturnObjectHeldByAnotherMember(): void */ public function testMemberReturnOwnObject(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -379,7 +379,7 @@ public function testMemberReturnOwnObject(): void */ public function testReturnComments(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $this->logSuperAdmin(); $this->lendObject($this->getMemberOne()->id); @@ -400,7 +400,7 @@ public function testReturnComments(): void */ public function testReturnInvalid(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->logSuperAdmin(); //object is not lent @@ -491,8 +491,14 @@ public function testFilterOnField(): void $filters = $this->session->plugin_objectslend_objects_filter; $this->assertSame(\GaletteObjectsLend\Repository\Objects::FILTER_SERIAL, $filters->field_filter); - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->preferences, $this->login, new LendPreferences($this->preferences), $filters); - $list = $objects->getObjectsList(true); + $objects = new \GaletteObjectsLend\Repository\Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: new LendPreferences($this->preferences), + filters: $filters + ); + $list = $objects->getObjectsList(as_objects: true); $this->assertCount(1, $list); } @@ -590,7 +596,7 @@ public function testAddWithInvalidFirstStatus(): void */ public function testMemberCannotTakeWhenMemberRentDisabled(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $mdata = $this->dataAdherentOne(); $this->getMemberOne(); @@ -610,7 +616,7 @@ public function testMemberCannotTakeWhenMemberRentDisabled(): void */ public function testStaffTakeForAMember(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $member_two = $this->getMemberTwo(); @@ -634,7 +640,7 @@ public function testStaffTakeForAMember(): void */ public function testStaffTakeForThemselves(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $this->getStaffMember($member_one); @@ -657,9 +663,9 @@ public function testStaffTakeForThemselves(): void public function testTakeInactiveObject(): void { $object = new LendObject($this->zdb, $this->object_id); - $object->setActive(false); + $object->setActive(active: false); $object->store(); - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->logSuperAdmin(); $test_response = $this->app->handle($this->takeRequest([])); @@ -674,7 +680,7 @@ public function testTakeInactiveObject(): void */ public function testTakeClosesCurrentRent(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $rent = new LendRent($this->zdb); $rent->setObjectId($this->object_id); $rent->setStatusId($this->instock_status); @@ -709,12 +715,12 @@ public function testTakeClosesCurrentRent(): void */ public function testTakeAjax(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->logSuperAdmin(); $test_response = $this->app->handle($this->takeRequest(['mode' => 'ajax'])); $this->assertSame(200, $test_response->getStatusCode()); - $this->assertSame(['success' => 'true'], json_decode((string)$test_response->getBody(), true)); + $this->assertSame(['success' => 'true'], json_decode((string)$test_response->getBody(), associative: true)); $this->expectFlashData(['success_detected' => ['You have just borrowed Test object :)']]); $this->assertCount(1, $this->getRents()); } @@ -737,7 +743,7 @@ private function setRentPrice(float $rent_price): void */ public function testTakeGeneratesContributionWithPostedPrice(): void { - $this->setPrefs(false, true); + $this->setPrefs(member_rent: false, auto_contrib: true); $this->setRentPrice(3.5); $member_one = $this->getMemberOne(); @@ -769,7 +775,7 @@ public function testTakeGeneratesContributionWithPostedPrice(): void */ public function testMemberTakeGeneratesContribution(): void { - $this->setPrefs(true, true); + $this->setPrefs(member_rent: true, auto_contrib: true); $this->setRentPrice(3.5); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); @@ -804,7 +810,7 @@ public function testMemberTakeGeneratesContribution(): void */ public function testTakeWithInvalidContribution(): void { - $this->setPrefs(false, true); + $this->setPrefs(member_rent: false, auto_contrib: true); $this->setRentPrice(3.5); $member_one = $this->getMemberOne(); @@ -829,7 +835,7 @@ public function testTakeWithInvalidContribution(): void */ public function testTakeFreeObjectGeneratesNoContribution(): void { - $this->setPrefs(false, true); + $this->setPrefs(member_rent: false, auto_contrib: true); $this->setRentPrice(0); $member_one = $this->getMemberOne(); @@ -852,7 +858,7 @@ public function testTakeFreeObjectGeneratesNoContribution(): void */ public function testStaffReturnWhenMemberRentDisabled(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $member_two = $this->getMemberTwo(); @@ -879,7 +885,7 @@ public function testStaffReturnWhenMemberRentDisabled(): void */ public function testMemberReturnOwnObjectWhenMemberRentDisabled(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -897,14 +903,14 @@ public function testMemberReturnOwnObjectWhenMemberRentDisabled(): void */ public function testReturnAjax(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); $this->logSuperAdmin(); $test_response = $this->app->handle($this->returnRequest(['mode' => 'ajax'])); $this->assertSame(200, $test_response->getStatusCode()); - $this->assertSame(['success' => 'true'], json_decode((string)$test_response->getBody(), true)); + $this->assertSame(['success' => 'true'], json_decode((string)$test_response->getBody(), associative: true)); $this->expectFlashData(['success_detected' => ['Test object has been returned :)']]); $this->assertCount(2, $this->getRents()); } @@ -987,7 +993,7 @@ public function testStaffUpdateStatus(): void */ public function testMemberCannotUpdateStatus(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $mdata = $this->dataAdherentOne(); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); @@ -1022,7 +1028,7 @@ private function lendPageRequest(string $action): \Slim\Psr7\Request */ public function testTakePage(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->logSuperAdmin(); $test_response = $this->app->handle($this->lendPageRequest('take')); @@ -1040,7 +1046,7 @@ public function testTakePage(): void */ public function testTakePageRefusedToMember(): void { - $this->setPrefs(false); + $this->setPrefs(member_rent: false); $this->getMemberOne(); $this->logMember($this->dataAdherentOne()); @@ -1055,7 +1061,7 @@ public function testTakePageRefusedToMember(): void */ public function testReturnPage(): void { - $this->setPrefs(true); + $this->setPrefs(member_rent: true); $member_one = $this->getMemberOne(); $this->lendObject($member_one->id); diff --git a/tests/GaletteObjectsLend/Controllers/tests/units/StatusController.php b/tests/GaletteObjectsLend/Controllers/tests/units/StatusController.php index b85ef78..a99b850 100644 --- a/tests/GaletteObjectsLend/Controllers/tests/units/StatusController.php +++ b/tests/GaletteObjectsLend/Controllers/tests/units/StatusController.php @@ -56,7 +56,7 @@ public function tearDown(): void private function addStatus(string $text, bool $in_stock): LendStatus { $status = new LendStatus($this->zdb); - $status->setText($text)->setInStock($in_stock)->setActive(true); + $status->setText($text)->setInStock($in_stock)->setActive(active: true); $status->store(); return $status; } @@ -67,7 +67,7 @@ private function addStatus(string $text, bool $in_stock): LendStatus public function testList(): void { $this->logSuperAdmin(); - $this->addStatus('Shelf ', true); + $this->addStatus('Shelf ', in_stock: true); $test_response = $this->app->handle($this->createRequest(route_name: 'objectslend_statuses')); $this->assertSame(200, $test_response->getStatusCode()); @@ -100,10 +100,15 @@ public function testFilter(): void $this->assertSame(Status::IN_STOCK, $filters->stock_filter); //search string is found - $this->addStatus('Shelf & B', true); - $this->addStatus('Shelf C', true); - $statuses = new Status($this->zdb, $this->preferences, $this->login, $filters); - $this->assertCount(1, $statuses->getStatusList(true)); + $this->addStatus('Shelf & B', in_stock: true); + $this->addStatus('Shelf C', in_stock: true); + $statuses = new Status( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + $this->assertCount(1, $statuses->getStatusList(as_stt: true)); $request = $this->createRequest(route_name: 'objectslend_filter_statuses', method: 'POST') ->withParsedBody(['clear_filter' => '1']); @@ -132,7 +137,9 @@ public function testAddAndEdit(): void ); $this->expectFlashData(['success_detected' => ['Status has been saved']]); - $list = (new Status($this->zdb, $this->preferences, $this->login))->getList(true); + $list = (new Status($this->zdb, $this->preferences, $this->login))->getList( + as_stt: true + ); $this->assertCount(1, $list); $status = $list[0]; $this->assertSame('Garage', $status->getText()); @@ -179,7 +186,9 @@ public function testStoreError(): void $this->expectLogEntry(Analog::ERROR, 'Unable to store status #new'); $this->expectLogEntry(Analog::ERROR, 'Query error'); $this->assertSame($text, $this->session->objectslend_status_data['text']); - $this->assertCount(0, (new Status($this->zdb, $this->preferences, $this->login))->getList(true)); + $this->assertCount(0, (new Status($this->zdb, $this->preferences, $this->login))->getList( + as_stt: true + )); } /** @@ -188,7 +197,7 @@ public function testStoreError(): void public function testRemove(): void { $this->logSuperAdmin(); - $status = $this->addStatus('To be removed', true); + $status = $this->addStatus('To be removed', in_stock: true); $test_response = $this->app->handle( $this->createRequest(route_name: 'objectslend_remove_status', route_args: ['id' => (string)$status->getId()]) @@ -212,7 +221,7 @@ public function testRemove(): void public function testRemoveUsed(): void { $this->logSuperAdmin(); - $status = $this->addStatus('Used status', true); + $status = $this->addStatus('Used status', in_stock: true); $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('Object with history'); @@ -229,7 +238,7 @@ public function testRemoveUsed(): void method: 'POST' )->withParsedBody(['confirm' => '1', 'ajax' => 'true']); $test_response = $this->app->handle($request); - $this->assertSame(['success' => false], json_decode((string)$test_response->getBody(), true)); + $this->assertSame(['success' => false], json_decode((string)$test_response->getBody(), associative: true)); $this->expectFlashData([ 'error_detected' => ['This status is used by lends, it cannot be removed. Deactivate it instead.'] ]); diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php b/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php index ef95eec..29936d2 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php @@ -38,7 +38,7 @@ public function testEmpty(): void { $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $this->assertSame('No category (0)', $category->getName()); - $this->assertSame('No category', $category->getName(false)); + $this->assertSame('No category', $category->getName(count: false)); $this->assertInstanceOf(\GaletteObjectsLend\Entity\CategoryPicture::class, $category->getPicture()); $this->assertSame(0.0, $category->getSum()); $this->assertSame(0, $category->getObjectsNb()); @@ -47,8 +47,8 @@ public function testEmpty(): void $category = new \GaletteObjectsLend\Entity\LendCategory( $this->zdb, - null, - ['picture' => false] + args: null, + deps: ['picture' => false] ); $this->assertNull($category->getPicture()); } @@ -61,7 +61,7 @@ public function testCrud(): void $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Test category'); - $category->setActive(false); + $category->setActive(active: false); $category->store(); $cid = $category->getId(); diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php index 3606855..d9ff0d2 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php @@ -91,19 +91,19 @@ public function testEmpty(): void public function testCrud(): void { $objects = new \GaletteObjectsLend\Repository\Objects( - $this->zdb, - $this->preferences, - $this->login, - new \GaletteObjectsLend\LendPreferences($this->preferences) + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: new \GaletteObjectsLend\LendPreferences($this->preferences) ); $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('An object'); $object->setCategoryId($this->active_category_id); - $object->setActive(true); + $object->setActive(active: true); $object->setPrice(1500.00); $object->setRentPrice(10.00); - $object->setPricePerDay(true); + $object->setPricePerDay(price_per_day: true); $object->setWeight(186.00); $object->store(); @@ -164,7 +164,7 @@ public function testCrud(): void $rm_category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $rm_category->setName('Category to be removed'); - $rm_category->setActive(true); + $rm_category->setActive(active: true); $rm_category->store(); $category_id = $rm_category->getId(); @@ -197,21 +197,21 @@ private function createStatus(): void { $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active status'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $this->active_instock_status = $status->getId(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('Another active status'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One inactive status'); - $status->setInStock(true); - $status->setActive(false); + $status->setInStock(in_stock: true); + $status->setActive(active: false); $status->store(); } @@ -223,7 +223,7 @@ private function createCategories(): void $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Active test category'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $this->active_category_id = $category->getId(); @@ -232,7 +232,7 @@ private function createCategories(): void $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Inactive test category'); - $category->setActive(false); + $category->setActive(active: false); $category->store(); $this->inactive_category_id = $category->getId(); @@ -265,7 +265,7 @@ public function testLongDescription(): void $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('An object'); $object->setDescription($description); - $object->setActive(true); + $object->setActive(active: true); $object->store(); $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $object->getId()); diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php b/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php index 98d4c66..b5d83e5 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php @@ -125,7 +125,7 @@ public function testCrud(): void $this->assertCount(2, $object_rents); //only last - $object_rents = (new \GaletteObjectsLend\Repository\Rents($this->zdb))->getForObject($oid, true); + $object_rents = (new \GaletteObjectsLend\Repository\Rents($this->zdb))->getForObject($oid, only_last: true); $this->assertCount(1, $object_rents); //close all rents @@ -196,22 +196,22 @@ private function createStatus(): void { $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active status'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $this->active_instock_status = $status->getId(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('Another active status'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $this->active_notinstock_status = $status->getId(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One inactive status'); - $status->setInStock(true); - $status->setActive(false); + $status->setInStock(in_stock: true); + $status->setActive(active: false); $status->store(); } } diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendStatus.php b/tests/GaletteObjectsLend/Entity/tests/units/LendStatus.php index 6f4c978..e28dd42 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendStatus.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendStatus.php @@ -62,22 +62,22 @@ public function testCrud(): void { $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active status'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $status_one = $status->getId(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('Another active status'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $status_two = $status->getId(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One inactive status'); - $status->setInStock(true); - $status->setActive(false); + $status->setInStock(in_stock: true); + $status->setActive(active: false); $status->store(); $list = (new \GaletteObjectsLend\Repository\Status($this->zdb, $this->preferences, $this->login))->getActiveTakeAwayStatuses(); diff --git a/tests/GaletteObjectsLend/Entity/tests/units/Picture.php b/tests/GaletteObjectsLend/Entity/tests/units/Picture.php index 7f94bf3..3b41d3e 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/Picture.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/Picture.php @@ -182,7 +182,12 @@ public function testRemoveObjects(): void } $this->assertTrue(is_file($store_path . $ids[0] . '_th.jpg')); - $objects = new Objects($this->zdb, $this->preferences, $this->login, $prefs); + $objects = new Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $prefs + ); $objects->removeObjects($ids); foreach ($ids as $id) { diff --git a/tests/GaletteObjectsLend/IO/tests/units/PdfObject.php b/tests/GaletteObjectsLend/IO/tests/units/PdfObject.php index bbc8f21..a923000 100644 --- a/tests/GaletteObjectsLend/IO/tests/units/PdfObject.php +++ b/tests/GaletteObjectsLend/IO/tests/units/PdfObject.php @@ -46,7 +46,7 @@ public function testDescriptionImages(): void $object->setDescription( '

A nice object

' ); - $object->setActive(true); + $object->setActive(active: true); $object->store(); //no picture of its own: any image in the card would come from the description $this->assertFalse($object->getPicture()->hasPicture()); diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Categories.php b/tests/GaletteObjectsLend/Repository/tests/units/Categories.php index d01ead6..3dc2f37 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Categories.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Categories.php @@ -44,64 +44,69 @@ public function testGetList(): void $rs_list = $categories->getList(); $this->assertInstanceOf(\Laminas\Db\ResultSet\ResultSet::class, $rs_list); $this->assertSame(0, $rs_list->count()); - $this->assertSame([], $categories->getList(true)); + $this->assertSame([], $categories->getList(as_cat: true)); $this->assertNull($categories->getCount()); - $this->assertSame([], $categories->getCategoriesList(true)); + $this->assertSame([], $categories->getCategoriesList(as_cat: true)); $this->assertSame(0, $categories->getCount()); $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('One category'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $cat_one_id = $category->getId(); $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Another category'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $cat_two_id = $category->getId(); $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Yet another category'); - $category->setActive(false); + $category->setActive(active: false); $category->store(); $filters = new \GaletteObjectsLend\Filters\CategoriesList(); - $categories = new \GaletteObjectsLend\Repository\Categories($this->zdb, $this->preferences, $this->login, $filters); - - $this->assertCount(3, $categories->getCategoriesList(true)); + $categories = new \GaletteObjectsLend\Repository\Categories( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + + $this->assertCount(3, $categories->getCategoriesList(as_cat: true)); $this->assertSame(3, $categories->getCount()); $filters->filter_str = 'category'; - $this->assertCount(3, $categories->getCategoriesList(true)); + $this->assertCount(3, $categories->getCategoriesList(as_cat: true)); $filters->filter_str = 'Yet'; - $this->assertCount(1, $categories->getCategoriesList(true)); + $this->assertCount(1, $categories->getCategoriesList(as_cat: true)); $filters->filter_str = 'noone'; - $this->assertCount(0, $categories->getCategoriesList(true)); + $this->assertCount(0, $categories->getCategoriesList(as_cat: true)); $filters->reinit(); $filters->not_empty = true; - $this->assertCount(0, $categories->getCategoriesList(true)); + $this->assertCount(0, $categories->getCategoriesList(as_cat: true)); $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('One object'); $object->setCategoryId($cat_one_id); $object->store(); - $this->assertCount(1, $categories->getCategoriesList(true)); + $this->assertCount(1, $categories->getCategoriesList(as_cat: true)); $filters->reinit(); $filters->active_filter = \GaletteObjectsLend\Repository\Categories::ALL_CATEGORIES; - $this->assertCount(3, $categories->getCategoriesList(true)); + $this->assertCount(3, $categories->getCategoriesList(as_cat: true)); $filters->active_filter = \GaletteObjectsLend\Repository\Categories::ACTIVE_CATEGORIES; - $this->assertCount(2, $categories->getCategoriesList(true)); + $this->assertCount(2, $categories->getCategoriesList(as_cat: true)); $filters->active_filter = \GaletteObjectsLend\Repository\Categories::INACTIVE_CATEGORIES; - $this->assertCount(1, $categories->getCategoriesList(true)); + $this->assertCount(1, $categories->getCategoriesList(as_cat: true)); //categories are counted once, whatever the number of their objects $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); @@ -110,7 +115,7 @@ public function testGetList(): void $object->store(); $filters->reinit(); - $this->assertCount(3, $categories->getCategoriesList(true)); + $this->assertCount(3, $categories->getCategoriesList(as_cat: true)); $this->assertSame(3, $categories->getCount()); //count takes grouping into account @@ -120,7 +125,7 @@ public function testGetList(): void $object->store(); $filters->not_empty = true; - $this->assertCount(2, $categories->getCategoriesList(true)); + $this->assertCount(2, $categories->getCategoriesList(as_cat: true)); $this->assertSame(2, $categories->getCount()); } } diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Objects.php b/tests/GaletteObjectsLend/Repository/tests/units/Objects.php index b5fb88b..78019ea 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Objects.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Objects.php @@ -52,27 +52,32 @@ public function tearDown(): void */ public function testGetList(): void { - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->preferences, $this->login, $this->lend_prefs); + $objects = new \GaletteObjectsLend\Repository\Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $this->lend_prefs + ); $rs_list = $objects->getList(); $this->assertInstanceOf(\Laminas\Db\ResultSet\ResultSet::class, $rs_list); $this->assertSame(0, $rs_list->count()); - $this->assertSame([], $objects->getList(true)); + $this->assertSame([], $objects->getList(as_objects: true)); $this->assertNull($objects->getCount()); - $this->assertSame([], $objects->getObjectsList(true)); + $this->assertSame([], $objects->getObjectsList(as_objects: true)); $this->assertSame(0, $objects->getCount()); $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('First category'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $first_category_id = $category->getId(); $this->assertGreaterThan(0, $first_category_id); $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Second category'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $second_category_id = $category->getId(); $this->assertGreaterThan(0, $second_category_id); @@ -80,7 +85,7 @@ public function testGetList(): void $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('First object'); $object->setCategoryId($first_category_id); - $object->setActive(true); + $object->setActive(active: true); $object->store(); $first_object_id = $object->getId(); @@ -88,14 +93,14 @@ public function testGetList(): void $object->setName('Second object'); $object->setDescription('First description'); $object->setCategoryId($first_category_id); - $object->setActive(true); + $object->setActive(active: true); $object->store(); $second_object_id = $object->getId(); $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('Third object'); $object->setCategoryId($second_category_id); - $object->setActive(true); + $object->setActive(active: true); $object->store(); $third_object_id = $object->getId(); @@ -103,15 +108,21 @@ public function testGetList(): void $object->setName('Fourth object'); $object->setSerialNumber('GGABCDEXX'); $object->setDimension('210x297'); - $object->setActive(false); + $object->setActive(active: false); $object->store(); //ids are not reset between tests, a hardcoded one may exist $missing_id = $object->getId() + 1; $filters = new \GaletteObjectsLend\Filters\ObjectsList(); - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->preferences, $this->login, $this->lend_prefs, $filters); + $objects = new \GaletteObjectsLend\Repository\Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $this->lend_prefs, + filters: $filters + ); - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $this->assertSame(4, $objects->getCount()); $selected = [ @@ -119,38 +130,38 @@ public function testGetList(): void $third_object_id ]; $filters->selected = $selected; - $this->assertCount(2, $objects->getObjectsList(true)); + $this->assertCount(2, $objects->getObjectsList(as_objects: true)); $this->assertSame(2, $objects->getCount()); $filters->reinit(); $filters->active_filter = \GaletteObjectsLend\Repository\Objects::ACTIVE_OBJECTS; - $this->assertCount(3, $objects->getObjectsList(true)); + $this->assertCount(3, $objects->getObjectsList(as_objects: true)); $this->assertSame(3, $objects->getCount()); $filters->active_filter = \GaletteObjectsLend\Repository\Objects::INACTIVE_OBJECTS; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); $filters->reinit(); $filters->category_filter = -1; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); $filters->category_filter = $first_category_id; - $this->assertCount(2, $objects->getObjectsList(true)); + $this->assertCount(2, $objects->getObjectsList(as_objects: true)); $this->assertSame(2, $objects->getCount()); $filters->category_filter = $second_category_id; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); $filters->reinit(); $filters->filter_str = 'OBJECT'; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $this->assertSame(4, $objects->getCount()); $filters->filter_str = 'first'; - $this->assertCount(2, $objects->getObjectsList(true)); + $this->assertCount(2, $objects->getObjectsList(as_objects: true)); $this->assertSame(2, $objects->getCount()); //disable view description @@ -159,7 +170,7 @@ public function testGetList(): void ); //only one result (first in name only) - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); //reset prefs @@ -169,58 +180,58 @@ public function testGetList(): void $filters->field_filter = \GaletteObjectsLend\Repository\Objects::FILTER_ID; $filters->filter_str = (string)$third_object_id; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); $filters->filter_str = (string)$missing_id; - $this->assertCount(0, $objects->getObjectsList(true)); + $this->assertCount(0, $objects->getObjectsList(as_objects: true)); $this->assertSame(0, $objects->getCount()); $filters->field_filter = \GaletteObjectsLend\Repository\Objects::FILTER_SERIAL; $filters->filter_str = 'ABCDE'; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); $filters->field_filter = \GaletteObjectsLend\Repository\Objects::FILTER_DIM; $filters->filter_str = '297'; - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); $this->assertSame(1, $objects->getCount()); //quick test ordering $filters->reinit(); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_NAME; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_SERIAL; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_PRICE; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_RENTPRICE; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_WEIGHT; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_STATUS; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_BDATE; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_FDATE; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_MEMBER; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_CATEGORY; - $this->assertCount(4, $objects->getObjectsList(true)); + $this->assertCount(4, $objects->getObjectsList(as_objects: true)); $objects->removeObjects([$first_object_id, $second_object_id, $third_object_id]); - $this->assertCount(1, $objects->getObjectsList(true)); + $this->assertCount(1, $objects->getObjectsList(as_objects: true)); } /** @@ -232,7 +243,7 @@ public function testOrderByHomonymousCategories(): void foreach ([1, 2] as $i) { $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->setName('Same name'); - $category->setActive(true); + $category->setActive(active: true); $category->store(); $category_ids[] = $category->getId(); } @@ -242,14 +253,20 @@ public function testOrderByHomonymousCategories(): void $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->setName('Object ' . $i); $object->setCategoryId($category_ids[$index]); - $object->setActive(true); + $object->setActive(active: true); $object->store(); } $filters = new \GaletteObjectsLend\Filters\ObjectsList(); $filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_CATEGORY; - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->preferences, $this->login, $this->lend_prefs, $filters); - $list = $objects->getObjectsList(true, true, false); + $objects = new \GaletteObjectsLend\Repository\Objects( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: $this->lend_prefs, + filters: $filters + ); + $list = $objects->getObjectsList(as_objects: true, count: true, limit: false); $this->assertCount(6, $list); $sequence = array_map(fn($object) => $object->getCategoryId(), $list); diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Status.php b/tests/GaletteObjectsLend/Repository/tests/units/Status.php index 1204b91..9e4dda2 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Status.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Status.php @@ -53,90 +53,95 @@ public function testGetList(): void $rs_list = $status->getList(); $this->assertInstanceOf(\Laminas\Db\ResultSet\ResultSet::class, $rs_list); $this->assertSame(0, $rs_list->count()); - $this->assertSame([], $status->getList(true)); + $this->assertSame([], $status->getList(as_stt: true)); $this->assertNull($status->getCount()); - $this->assertSame([], $status->getStatusList(true)); + $this->assertSame([], $status->getStatusList(as_stt: true)); $this->assertSame(0, $status->getCount()); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active in stock status'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active in stock status'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One active not in stock status'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One inactive in stock status'); - $status->setInStock(true); - $status->setActive(false); + $status->setInStock(in_stock: true); + $status->setActive(active: false); $status->store(); $status = new \GaletteObjectsLend\Entity\LendStatus($this->zdb); $status->setText('One inactive not in stock status'); - $status->setInStock(false); - $status->setActive(false); + $status->setInStock(in_stock: false); + $status->setActive(active: false); $status->store(); $filters = new \GaletteObjectsLend\Filters\StatusList(); - $status = new \GaletteObjectsLend\Repository\Status($this->zdb, $this->preferences, $this->login, $filters); - - $this->assertCount(5, $status->getStatusList(true)); + $status = new \GaletteObjectsLend\Repository\Status( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + filters: $filters + ); + + $this->assertCount(5, $status->getStatusList(as_stt: true)); $this->assertSame(5, $status->getCount()); $filters->filter_str = 'one'; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->filter_str = 'not'; - $this->assertCount(2, $status->getStatusList(true)); + $this->assertCount(2, $status->getStatusList(as_stt: true)); $filters->filter_str = 'noone'; - $this->assertCount(0, $status->getStatusList(true)); + $this->assertCount(0, $status->getStatusList(as_stt: true)); $filters->reinit(); $filters->active_filter = \GaletteObjectsLend\Repository\Status::ACTIVE; - $this->assertCount(3, $status->getStatusList(true)); + $this->assertCount(3, $status->getStatusList(as_stt: true)); $filters->active_filter = \GaletteObjectsLend\Repository\Status::INACTIVE; - $this->assertCount(2, $status->getStatusList(true)); + $this->assertCount(2, $status->getStatusList(as_stt: true)); $filters->reinit(); $filters->stock_filter = \GaletteObjectsLend\Repository\Status::DC_STOCK; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->stock_filter = \GaletteObjectsLend\Repository\Status::IN_STOCK; - $this->assertCount(3, $status->getStatusList(true)); + $this->assertCount(3, $status->getStatusList(as_stt: true)); $filters->stock_filter = \GaletteObjectsLend\Repository\Status::OUT_STOCK; - $this->assertCount(2, $status->getStatusList(true)); + $this->assertCount(2, $status->getStatusList(as_stt: true)); //quick test ordering $filters->reinit(); $filters->orderby = \GaletteObjectsLend\Repository\Status::ORDERBY_ID; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->orderby = \GaletteObjectsLend\Repository\Status::ORDERBY_NAME; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->orderby = \GaletteObjectsLend\Repository\Status::ORDERBY_ACTIVE; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->orderby = \GaletteObjectsLend\Repository\Status::ORDERBY_STOCK; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); $filters->orderby = \GaletteObjectsLend\Repository\Status::ORDERBY_RENTDAYS; - $this->assertCount(5, $status->getStatusList(true)); + $this->assertCount(5, $status->getStatusList(as_stt: true)); } } diff --git a/tests/GaletteObjectsLend/tests/units/LendService.php b/tests/GaletteObjectsLend/tests/units/LendService.php index 3bae95c..3b24e97 100644 --- a/tests/GaletteObjectsLend/tests/units/LendService.php +++ b/tests/GaletteObjectsLend/tests/units/LendService.php @@ -60,15 +60,15 @@ public function setUp(): void $status = new LendStatus($this->zdb); $status->setText('In stock'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $this->instock_status = $status->getId(); $status = new LendStatus($this->zdb); $status->setText('Lent'); - $status->setInStock(false); - $status->setActive(true); + $status->setInStock(in_stock: false); + $status->setActive(active: true); $status->store(); $this->lent_status = $status->getId(); @@ -116,7 +116,12 @@ public function tearDown(): void */ private function getService(): \GaletteObjectsLend\LendService { - return new \GaletteObjectsLend\LendService($this->zdb, $this->preferences, $this->login, new LendPreferences($this->preferences)); + return new \GaletteObjectsLend\LendService( + zdb: $this->zdb, + preferences: $this->preferences, + login: $this->login, + lendsprefs: new LendPreferences($this->preferences) + ); } /** @@ -163,8 +168,8 @@ public function testTakeRollsBackOnContributionError(): void try { $service->take( - $service->getObject($this->object_id), - $this->lent_status, + object: $service->getObject($this->object_id), + status_id: $this->lent_status, member_id: $member->id, payment_type: 999999 ); @@ -223,8 +228,8 @@ public function testChangeStatusInvalid(): void { $status = new LendStatus($this->zdb); $status->setText('Inactive'); - $status->setInStock(true); - $status->setActive(false); + $status->setInStock(in_stock: true); + $status->setActive(active: false); $status->store(); $this->logSuperAdmin(); @@ -255,8 +260,8 @@ public function testMemberRemovalGivesBackObjects(): void //first in stock status, but not the last one the object had $status = new LendStatus($this->zdb); $status->setText('A first stock'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $repair = new LendObject($this->zdb); @@ -299,8 +304,8 @@ public function testMemberRemovalGivesBackToFirstStockStatus(): void { $status = new LendStatus($this->zdb); $status->setText('A first stock'); - $status->setInStock(true); - $status->setActive(true); + $status->setInStock(in_stock: true); + $status->setActive(active: true); $status->store(); $member = $this->getMemberOne(); diff --git a/tests/GaletteObjectsLend/tests/units/SampleData.php b/tests/GaletteObjectsLend/tests/units/SampleData.php index 531441d..138d6ae 100644 --- a/tests/GaletteObjectsLend/tests/units/SampleData.php +++ b/tests/GaletteObjectsLend/tests/units/SampleData.php @@ -73,14 +73,14 @@ public function testLoad(): void { $data = json_decode( (string)file_get_contents(\GaletteObjectsLend\SampleData::FILE), - true, + associative: true, flags: JSON_THROW_ON_ERROR ); $this->assertIsArray($data); //an existing category is reused $category = new LendCategory($this->zdb); - $category->setName($data['categories'][0]['name'])->setActive(true); + $category->setName($data['categories'][0]['name'])->setActive(active: true); $category->store(); $member = $this->getMemberOne(); @@ -129,7 +129,7 @@ public function testRemove(): void { $data = json_decode( (string)file_get_contents(\GaletteObjectsLend\SampleData::FILE), - true, + associative: true, flags: JSON_THROW_ON_ERROR ); $this->assertIsArray($data); From 2da4dfcad8790466ac6008be12c509dd360ba4fe Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 11 Nov 2026 22:53:32 +0100 Subject: [PATCH 2/2] Run rector in CI with the core configuration --- .github/workflows/ci-linux.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index c034375..85cc5e1 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -97,6 +97,17 @@ jobs: cd galette-core/galette/plugins/plugin-objectslend ../../vendor/bin/php-cs-fixer check --show-progress=dots --verbose --diff + # Core configuration, with the plugin paths given on the command line; + # run from the core root, where withPhpSets() reads the PHP version + - name: Rector + if: matrix.php-is-min + run: | + cd galette-core + galette/vendor/bin/rector process --dry-run --ansi \ + galette/plugins/plugin-objectslend/lib \ + galette/plugins/plugin-objectslend/tests \ + galette/plugins/plugin-objectslend/*.php + - name: Twig CS run: | cd galette-core/galette/plugins/plugin-objectslend