diff --git a/src/Catalogue/Book.php b/src/Catalogue/Book.php index 3785242..f2ddd7e 100644 --- a/src/Catalogue/Book.php +++ b/src/Catalogue/Book.php @@ -4,38 +4,14 @@ namespace Akondas\Library\Catalogue; -class Book +final readonly class Book { - private ISBN $isbn; - - private Title $title; - - private Author $author; - - private function __construct(ISBN $isbn, Title $title, Author $author) + private function __construct(public ISBN $isbn, public Title $title, public Author $author) { - $this->isbn = $isbn; - $this->title = $title; - $this->author = $author; } public static function of(string $isbn, string $title, string $author): self { return new self(new ISBN($isbn), new Title($title), new Author($author)); } - - public function bookIsbn(): ISBN - { - return $this->isbn; - } - - public function title(): Title - { - return $this->title; - } - - public function author(): Author - { - return $this->author; - } } diff --git a/src/Catalogue/BookId.php b/src/Catalogue/BookId.php index a46ffd8..6bfe05f 100644 --- a/src/Catalogue/BookId.php +++ b/src/Catalogue/BookId.php @@ -6,17 +6,14 @@ use Akondas\Library\Common\UUID; -final class BookId +final readonly class BookId { - private UUID $bookId; - - public function __construct(UUID $bookId) + public function __construct(public UUID $bookId) { - $this->bookId = $bookId; } - public function bookId(): UUID + public static function random(): self { - return $this->bookId; + return new self(UUID::random()); } } diff --git a/src/Catalogue/BookInstance.php b/src/Catalogue/BookInstance.php index 4ee073a..39907a4 100644 --- a/src/Catalogue/BookInstance.php +++ b/src/Catalogue/BookInstance.php @@ -4,40 +4,14 @@ namespace Akondas\Library\Catalogue; -use Akondas\Library\Common\UUID; - -class BookInstance +final readonly class BookInstance { - private ISBN $isbn; - - private BookId $bookId; - - private BookType $bookType; - - private function __construct(ISBN $isbn, BookId $bookId, BookType $bookType) + private function __construct(public ISBN $isbn, public BookId $bookId, public BookType $bookType) { - $this->isbn = $isbn; - $this->bookId = $bookId; - $this->bookType = $bookType; } public static function of(Book $book, BookType $bookType): self { - return new self($book->bookIsbn(), new BookId(UUID::random()), $bookType); - } - - public function bookIsbn(): ISBN - { - return $this->isbn; - } - - public function bookId(): BookId - { - return $this->bookId; - } - - public function bookType(): BookType - { - return $this->bookType; + return new self($book->isbn, BookId::random(), $bookType); } } diff --git a/src/Catalogue/BookInstanceAddedToCatalogue.php b/src/Catalogue/BookInstanceAddedToCatalogue.php index 818e84d..887bba2 100644 --- a/src/Catalogue/BookInstanceAddedToCatalogue.php +++ b/src/Catalogue/BookInstanceAddedToCatalogue.php @@ -7,34 +7,24 @@ use Akondas\Library\Common\Event\DomainEvent; use Akondas\Library\Common\UUID; -class BookInstanceAddedToCatalogue implements DomainEvent +final readonly class BookInstanceAddedToCatalogue implements DomainEvent { - private UUID $eventId; - - private string $isbn; - - private BookType $bookType; - - private UUID $bookId; - - private \DateTimeImmutable $when; - - private function __construct(UUID $eventId, string $isbn, BookType $bookType, UUID $bookId, \DateTimeImmutable $when) - { - $this->eventId = $eventId; - $this->isbn = $isbn; - $this->bookType = $bookType; - $this->bookId = $bookId; - $this->when = $when; + private function __construct( + public UUID $eventId, + public string $isbn, + public BookType $bookType, + public UUID $bookId, + public \DateTimeImmutable $when + ) { } public static function now(BookInstance $bookInstance): self { return new self( UUID::random(), - $bookInstance->bookIsbn()->isbn(), - $bookInstance->bookType(), - $bookInstance->bookId()->bookId(), + $bookInstance->isbn->isbn, + $bookInstance->bookType, + $bookInstance->bookId->bookId, new \DateTimeImmutable() ); } @@ -49,21 +39,6 @@ public function aggregateId(): UUID return $this->bookId; } - public function isbn(): string - { - return $this->isbn; - } - - public function bookType(): BookType - { - return $this->bookType; - } - - public function bookId(): UUID - { - return $this->bookId; - } - public function when(): \DateTimeImmutable { return $this->when; diff --git a/src/Catalogue/Catalogue.php b/src/Catalogue/Catalogue.php index 6788455..d500c2d 100644 --- a/src/Catalogue/Catalogue.php +++ b/src/Catalogue/Catalogue.php @@ -9,15 +9,10 @@ use Munus\Control\Option; use Munus\Control\TryTo; -class Catalogue +final readonly class Catalogue { - private CatalogueDatabase $database; - private DomainEventPublisher $eventPublisher; - - public function __construct(CatalogueDatabase $database, DomainEventPublisher $eventPublisher) + public function __construct(private CatalogueDatabase $database, private DomainEventPublisher $eventPublisher) { - $this->database = $database; - $this->eventPublisher = $eventPublisher; } /** diff --git a/src/Catalogue/ISBN.php b/src/Catalogue/ISBN.php index 0313152..3ff9174 100644 --- a/src/Catalogue/ISBN.php +++ b/src/Catalogue/ISBN.php @@ -6,21 +6,12 @@ use Isbn\Isbn as IsbnCode; -class ISBN +final readonly class ISBN { - private string $isbn; - - public function __construct(string $isbn) + public function __construct(public string $isbn) { if (!(new IsbnCode())->validation->isbn($isbn)) { throw new \InvalidArgumentException('Invalid ISBN'); } - - $this->isbn = $isbn; - } - - public function isbn(): string - { - return $this->isbn; } } diff --git a/src/Catalogue/Title.php b/src/Catalogue/Title.php index ea05ff7..da29adc 100644 --- a/src/Catalogue/Title.php +++ b/src/Catalogue/Title.php @@ -4,21 +4,12 @@ namespace Akondas\Library\Catalogue; -class Title +final readonly class Title { - private string $title; - - public function __construct(string $title) + public function __construct(public string $title) { if ($title === '') { throw new \InvalidArgumentException('Title cannot be empty'); } - - $this->title = $title; - } - - public function title(): string - { - return $this->title; } } diff --git a/src/Lending/Book/Domain/AvailableBook.php b/src/Lending/Book/Domain/AvailableBook.php index 378af68..613db92 100644 --- a/src/Lending/Book/Domain/AvailableBook.php +++ b/src/Lending/Book/Domain/AvailableBook.php @@ -9,19 +9,14 @@ use Akondas\Library\Common\Aggregate\Version; use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; -final class AvailableBook implements Book +final readonly class AvailableBook implements Book { - private BookId $bookId; - private BookType $bookType; - private LibraryBranchId $libraryBranch; - private Version $version; - - public function __construct(BookId $bookId, BookType $bookType, LibraryBranchId $libraryBranch, Version $version) + public function __construct( + public BookId $bookId, + public BookType $bookType, + public LibraryBranchId $libraryBranch, + public Version $version) { - $this->bookId = $bookId; - $this->bookType = $bookType; - $this->libraryBranch = $libraryBranch; - $this->version = $version; } public function bookId(): BookId @@ -39,11 +34,6 @@ public function version(): Version return $this->version; } - public function libraryBranch(): LibraryBranchId - { - return $this->libraryBranch; - } - public function isRestricted(): bool { return $this->bookType === BookType::RESTRICTED; diff --git a/src/Lending/Book/Domain/BookOnHold.php b/src/Lending/Book/Domain/BookOnHold.php index 429dbef..09e8905 100644 --- a/src/Lending/Book/Domain/BookOnHold.php +++ b/src/Lending/Book/Domain/BookOnHold.php @@ -10,41 +10,21 @@ use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; use Akondas\Library\Lending\Patron\Domain\PatronId; -final class BookOnHold implements Book +final readonly class BookOnHold implements Book { - private BookId $bookId; - - private BookType $bookType; - - private LibraryBranchId $libraryBranch; - - private PatronId $byPatron; - - private \DateTimeImmutable $holdTill; - - private Version $version; - - /** - * BookOnHold constructor. - */ - public function __construct(BookId $bookId, BookType $bookType, LibraryBranchId $libraryBranch, PatronId $byPatron, \DateTimeImmutable $holdTill, Version $version) + public function __construct( + public BookId $bookId, + public BookType $bookType, + public LibraryBranchId $libraryBranch, + public PatronId $byPatron, + public \DateTimeImmutable $holdTill, + public Version $version) { - $this->bookId = $bookId; - $this->bookType = $bookType; - $this->libraryBranch = $libraryBranch; - $this->byPatron = $byPatron; - $this->holdTill = $holdTill; - $this->version = $version; } public function by(PatronId $patronId): bool { - return $this->byPatron->patronId()->isEqual($patronId->patronId()); - } - - public function libraryBranch(): LibraryBranchId - { - return $this->libraryBranch; + return $this->byPatron->patronId->isEqual($patronId->patronId); } public function bookId(): BookId @@ -61,14 +41,4 @@ public function version(): Version { return $this->version; } - - public function byPatron(): PatronId - { - return $this->byPatron; - } - - public function holdTill(): \DateTimeImmutable - { - return $this->holdTill; - } } diff --git a/src/Lending/LibraryBranch/Domain/LibraryBranchId.php b/src/Lending/LibraryBranch/Domain/LibraryBranchId.php index 6304ebd..b450281 100644 --- a/src/Lending/LibraryBranch/Domain/LibraryBranchId.php +++ b/src/Lending/LibraryBranch/Domain/LibraryBranchId.php @@ -6,17 +6,9 @@ use Akondas\Library\Common\UUID; -final class LibraryBranchId +final readonly class LibraryBranchId { - private UUID $libraryBranchId; - - public function __construct(UUID $libraryBranchId) - { - $this->libraryBranchId = $libraryBranchId; - } - - public function libraryBranchId(): UUID + public function __construct(public UUID $libraryBranchId) { - return $this->libraryBranchId; } } diff --git a/src/Lending/Patron/Domain/Hold.php b/src/Lending/Patron/Domain/Hold.php index 16fac14..615271c 100644 --- a/src/Lending/Patron/Domain/Hold.php +++ b/src/Lending/Patron/Domain/Hold.php @@ -7,24 +7,9 @@ use Akondas\Library\Catalogue\BookId; use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; -class Hold +final readonly class Hold { - private BookId $bookId; - private LibraryBranchId $libraryBranchId; - - public function __construct(BookId $bookId, LibraryBranchId $libraryBranchId) - { - $this->bookId = $bookId; - $this->libraryBranchId = $libraryBranchId; - } - - public function bookId(): BookId - { - return $this->bookId; - } - - public function libraryBranchId(): LibraryBranchId + public function __construct(public BookId $bookId, public LibraryBranchId $libraryBranchId) { - return $this->libraryBranchId; } } diff --git a/src/Lending/Patron/Domain/HoldDuration.php b/src/Lending/Patron/Domain/HoldDuration.php index 6126a5d..681dcb6 100644 --- a/src/Lending/Patron/Domain/HoldDuration.php +++ b/src/Lending/Patron/Domain/HoldDuration.php @@ -4,20 +4,13 @@ namespace Akondas\Library\Lending\Patron\Domain; -use Munus\Control\Option; - -final class HoldDuration +final readonly class HoldDuration { - private \DateTimeImmutable $from; - private ?\DateTimeImmutable $to; - - private function __construct(\DateTimeImmutable $from, ?\DateTimeImmutable $to) + private function __construct(public \DateTimeImmutable $from, public ?\DateTimeImmutable $to) { if ($to !== null && $to < $from) { throw new \InvalidArgumentException('Close-ended duration must be valid'); } - $this->from = $from; - $this->to = $to; } public static function openEnded(): self @@ -29,20 +22,7 @@ public static function closeEnded(NumberOfDays $days): self { $now = new \DateTimeImmutable(); - return new self($now, $now->modify(sprintf('+%s days', $days->days()))); - } - - public function from(): \DateTimeImmutable - { - return $this->from; - } - - /** - * @return Option<\DateTimeImmutable> - */ - public function to(): Option - { - return Option::of($this->to); + return new self($now, $now->modify(sprintf('+%s days', $days->days))); } public function isOpenEnded(): bool diff --git a/src/Lending/Patron/Domain/NumberOfDays.php b/src/Lending/Patron/Domain/NumberOfDays.php index fa7a195..c296691 100644 --- a/src/Lending/Patron/Domain/NumberOfDays.php +++ b/src/Lending/Patron/Domain/NumberOfDays.php @@ -4,16 +4,13 @@ namespace Akondas\Library\Lending\Patron\Domain; -final class NumberOfDays +final readonly class NumberOfDays { - private int $days; - - private function __construct(int $days) + private function __construct(public int $days) { if ($days <= 0) { throw new \InvalidArgumentException('Cannot use negative integer or zero as number of days'); } - $this->days = $days; } public static function of(int $days): self @@ -21,11 +18,6 @@ public static function of(int $days): self return new self($days); } - public function days(): int - { - return $this->days; - } - public function isGreaterThan(int $days): bool { return $this->days > $days; diff --git a/src/Lending/Patron/Domain/Patron.php b/src/Lending/Patron/Domain/Patron.php index 067f4d7..d203a01 100644 --- a/src/Lending/Patron/Domain/Patron.php +++ b/src/Lending/Patron/Domain/Patron.php @@ -12,25 +12,13 @@ use Munus\Control\Either; use Munus\Control\Option; -final class Patron +final readonly class Patron { - private PatronInformation $patron; - - /** - * @var GenericList - */ - private GenericList $placingOnHoldPolicies; - - private PatronHolds $patronHolds; - /** * @param GenericList $placingOnHoldPolicies */ - public function __construct(PatronInformation $patron, GenericList $placingOnHoldPolicies, PatronHolds $patronHolds) + public function __construct(public PatronInformation $patron, public GenericList $placingOnHoldPolicies, public PatronHolds $patronHolds) { - $this->patron = $patron; - $this->placingOnHoldPolicies = $placingOnHoldPolicies; - $this->patronHolds = $patronHolds; } public function isRegular(): bool @@ -45,10 +33,10 @@ public function placeOnHold(AvailableBook $aBook, HoldDuration $holdDuration): E { $rejection = $this->patronCanHold($aBook, $holdDuration); if ($rejection->isEmpty()) { - return Either::right(BookPlacedOnHold::now($this->patron->patronId(), $aBook->bookId(), $aBook->bookType(), $aBook->libraryBranch(), $holdDuration)); + return Either::right(BookPlacedOnHold::now($this->patron->patronId, $aBook->bookId(), $aBook->bookType(), $aBook->libraryBranch, $holdDuration)); } - return Either::left(BookHoldFailed::now($this->patron->patronId(), $rejection->get()->reason(), $aBook->bookId(), $aBook->libraryBranch(), $holdDuration)); + return Either::left(BookHoldFailed::now($this->patron->patronId, $rejection->get()->reason, $aBook->bookId(), $aBook->libraryBranch, $holdDuration)); } public function numberOfHolds(): int diff --git a/src/Lending/Patron/Domain/PatronEvent/BookHoldFailed.php b/src/Lending/Patron/Domain/PatronEvent/BookHoldFailed.php index 88ae954..0c90158 100644 --- a/src/Lending/Patron/Domain/PatronEvent/BookHoldFailed.php +++ b/src/Lending/Patron/Domain/PatronEvent/BookHoldFailed.php @@ -11,27 +11,18 @@ use Akondas\Library\Lending\Patron\Domain\PatronEvent; use Akondas\Library\Lending\Patron\Domain\PatronId; -final class BookHoldFailed implements PatronEvent +final readonly class BookHoldFailed implements PatronEvent { - private UUID $eventId; - private PatronId $patronId; - private string $reason; - private BookId $bookId; - private LibraryBranchId $libraryBranchId; - private \DateTimeImmutable $when; - private \DateTimeImmutable $holdFrom; - private ?\DateTimeImmutable $holdTill; - - public function __construct(UUID $eventId, PatronId $patronId, string $reason, BookId $bookId, LibraryBranchId $libraryBranchId, \DateTimeImmutable $when, \DateTimeImmutable $holdFrom, ?\DateTimeImmutable $holdTill) + public function __construct( + public UUID $eventId, + public PatronId $patronId, + public string $reason, + public BookId $bookId, + public LibraryBranchId $libraryBranchId, + public \DateTimeImmutable $when, + public \DateTimeImmutable $holdFrom, + public ?\DateTimeImmutable $holdTill) { - $this->eventId = $eventId; - $this->patronId = $patronId; - $this->reason = $reason; - $this->bookId = $bookId; - $this->libraryBranchId = $libraryBranchId; - $this->when = $when; - $this->holdFrom = $holdFrom; - $this->holdTill = $holdTill; } public static function now(PatronId $patronId, string $reason, BookId $bookId, LibraryBranchId $libraryBranchId, HoldDuration $holdDuration): self @@ -43,8 +34,8 @@ public static function now(PatronId $patronId, string $reason, BookId $bookId, L $bookId, $libraryBranchId, new \DateTimeImmutable(), - $holdDuration->from(), - $holdDuration->to()->getOrNull() + $holdDuration->from, + $holdDuration->to ); } @@ -55,7 +46,7 @@ public function patronId(): PatronId public function aggregateId(): UUID { - return $this->patronId->patronId(); + return $this->patronId->patronId; } public function eventId(): UUID @@ -67,29 +58,4 @@ public function when(): \DateTimeImmutable { return $this->when; } - - public function reason(): string - { - return $this->reason; - } - - public function bookId(): BookId - { - return $this->bookId; - } - - public function libraryBranchId(): LibraryBranchId - { - return $this->libraryBranchId; - } - - public function holdFrom(): \DateTimeImmutable - { - return $this->holdFrom; - } - - public function holdTill(): ?\DateTimeImmutable - { - return $this->holdTill; - } } diff --git a/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php b/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php index a57f64f..10500df 100644 --- a/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php +++ b/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php @@ -14,25 +14,16 @@ final class BookPlacedOnHold implements PatronEvent { - private UUID $eventId; - private PatronId $patronId; - private BookId $bookId; - private BookType $bookType; - private LibraryBranchId $libraryBranchId; - private \DateTimeImmutable $holdFrom; - private ?\DateTimeImmutable $holdTill; - private \DateTimeImmutable $when; - - private function __construct(UUID $eventId, PatronId $patronId, BookId $bookId, BookType $bookType, LibraryBranchId $libraryBranchId, \DateTimeImmutable $when, \DateTimeImmutable $holdFrom, ?\DateTimeImmutable $holdTill) + private function __construct( + public UUID $eventId, + public PatronId $patronId, + public BookId $bookId, + public BookType $bookType, + public LibraryBranchId $libraryBranchId, + public \DateTimeImmutable $when, + public \DateTimeImmutable $holdFrom, + public ?\DateTimeImmutable $holdTill) { - $this->eventId = $eventId; - $this->patronId = $patronId; - $this->bookId = $bookId; - $this->bookType = $bookType; - $this->libraryBranchId = $libraryBranchId; - $this->when = $when; - $this->holdFrom = $holdFrom; - $this->holdTill = $holdTill; } public static function now(PatronId $patronId, BookId $bookId, BookType $bookType, LibraryBranchId $libraryBranchId, HoldDuration $holdDuration): self @@ -44,26 +35,11 @@ public static function now(PatronId $patronId, BookId $bookId, BookType $bookTyp $bookType, $libraryBranchId, new \DateTimeImmutable(), - $holdDuration->from(), - $holdDuration->to()->getOrNull() + $holdDuration->from, + $holdDuration->to ); } - public function bookId(): BookId - { - return $this->bookId; - } - - public function holdFrom(): \DateTimeImmutable - { - return $this->holdFrom; - } - - public function holdTill(): ?\DateTimeImmutable - { - return $this->holdTill; - } - public function patronId(): PatronId { return $this->patronId; @@ -76,21 +52,11 @@ public function eventId(): UUID public function aggregateId(): UUID { - return $this->patronId->patronId(); + return $this->patronId->patronId; } public function when(): \DateTimeImmutable { return $this->when; } - - public function bookType(): BookType - { - return $this->bookType; - } - - public function libraryBranchId(): LibraryBranchId - { - return $this->libraryBranchId; - } } diff --git a/src/Lending/Patron/Domain/PatronHolds.php b/src/Lending/Patron/Domain/PatronHolds.php index 148234c..1db1e87 100644 --- a/src/Lending/Patron/Domain/PatronHolds.php +++ b/src/Lending/Patron/Domain/PatronHolds.php @@ -8,26 +8,20 @@ use Akondas\Library\Lending\Book\Domain\BookOnHold; use Munus\Collection\Set; -class PatronHolds +final readonly class PatronHolds { - public const MAX_NUMBER_OF_HOLDS = 5; - - /** - * @var Set - */ - private Set $resourcesOnHold; + public const int MAX_NUMBER_OF_HOLDS = 5; /** * @param Set $resourcesOnHold */ - public function __construct(Set $resourcesOnHold) + public function __construct(public Set $resourcesOnHold) { - $this->resourcesOnHold = $resourcesOnHold; } public function a(BookOnHold $bookOnHold): bool { - return $this->resourcesOnHold->contains(new Hold($bookOnHold->bookId(), $bookOnHold->libraryBranch())); + return $this->resourcesOnHold->contains(new Hold($bookOnHold->bookId(), $bookOnHold->libraryBranch)); } public function count(): int diff --git a/src/Lending/Patron/Domain/PatronId.php b/src/Lending/Patron/Domain/PatronId.php index f32c954..ea7be6f 100644 --- a/src/Lending/Patron/Domain/PatronId.php +++ b/src/Lending/Patron/Domain/PatronId.php @@ -6,17 +6,9 @@ use Akondas\Library\Common\UUID; -final class PatronId +final readonly class PatronId { - private UUID $patronId; - - public function __construct(UUID $patronId) - { - $this->patronId = $patronId; - } - - public function patronId(): UUID + public function __construct(public UUID $patronId) { - return $this->patronId; } } diff --git a/src/Lending/Patron/Domain/PatronInformation.php b/src/Lending/Patron/Domain/PatronInformation.php index d7e70e7..8dcf14a 100644 --- a/src/Lending/Patron/Domain/PatronInformation.php +++ b/src/Lending/Patron/Domain/PatronInformation.php @@ -4,25 +4,10 @@ namespace Akondas\Library\Lending\Patron\Domain; -final class PatronInformation +final readonly class PatronInformation { - private PatronId $patronId; - private PatronType $patronType; - - public function __construct(PatronId $patronId, PatronType $patronType) - { - $this->patronId = $patronId; - $this->patronType = $patronType; - } - - public function patronId(): PatronId - { - return $this->patronId; - } - - public function patronType(): PatronType + public function __construct(public PatronId $patronId, public PatronType $patronType) { - return $this->patronType; } public function isRegular(): bool diff --git a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanHoldRestrictedBooks.php b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanHoldRestrictedBooks.php index cd5c7ba..a480108 100644 --- a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanHoldRestrictedBooks.php +++ b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanHoldRestrictedBooks.php @@ -10,7 +10,7 @@ use Akondas\Library\Lending\Patron\Domain\PlacingOnHoldPolicy; use Munus\Control\Either; -final class OnlyResearcherPatronsCanHoldRestrictedBooks implements PlacingOnHoldPolicy +final readonly class OnlyResearcherPatronsCanHoldRestrictedBooks implements PlacingOnHoldPolicy { /** * @return Either diff --git a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanPlaceOpenEndedHolds.php b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanPlaceOpenEndedHolds.php index 2d39ba7..41ef89a 100644 --- a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanPlaceOpenEndedHolds.php +++ b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/OnlyResearcherPatronsCanPlaceOpenEndedHolds.php @@ -12,7 +12,7 @@ use Munus\Control\Either\Left; use Munus\Control\Either\Right; -final class OnlyResearcherPatronsCanPlaceOpenEndedHolds implements PlacingOnHoldPolicy +final readonly class OnlyResearcherPatronsCanPlaceOpenEndedHolds implements PlacingOnHoldPolicy { /** * @return Either diff --git a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/RegularPatronMaximumNumberOfHoldsPolicy.php b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/RegularPatronMaximumNumberOfHoldsPolicy.php index f8cab1d..b54513f 100644 --- a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/RegularPatronMaximumNumberOfHoldsPolicy.php +++ b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/RegularPatronMaximumNumberOfHoldsPolicy.php @@ -13,7 +13,7 @@ use Munus\Control\Either\Left; use Munus\Control\Either\Right; -class RegularPatronMaximumNumberOfHoldsPolicy implements PlacingOnHoldPolicy +final readonly class RegularPatronMaximumNumberOfHoldsPolicy implements PlacingOnHoldPolicy { public function __invoke(AvailableBook $toHold, Patron $patron, HoldDuration $holdDuration): Either { diff --git a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/Rejection.php b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/Rejection.php index 10fe925..f63b0aa 100644 --- a/src/Lending/Patron/Domain/PlacingOnHoldPolicy/Rejection.php +++ b/src/Lending/Patron/Domain/PlacingOnHoldPolicy/Rejection.php @@ -4,17 +4,9 @@ namespace Akondas\Library\Lending\Patron\Domain\PlacingOnHoldPolicy; -final class Rejection +final readonly class Rejection { - private string $reason; - - public function __construct(string $reason) - { - $this->reason = $reason; - } - - public function reason(): string + public function __construct(public string $reason) { - return $this->reason; } } diff --git a/tests/Context/DomainContext.php b/tests/Context/DomainContext.php index 1daf5f8..4ef3ea2 100644 --- a/tests/Context/DomainContext.php +++ b/tests/Context/DomainContext.php @@ -41,7 +41,7 @@ public function aRegularPatronWithHoldsPlaceOnHold(int $holds, int $days): void */ public function placeOnHoldShouldFailWithReason(string $reason): void { - assertTrue($this->hold && $this->hold->getLeft()->reason() === $reason); + assertTrue($this->hold && $this->hold->getLeft()->reason === $reason); } /** diff --git a/tests/Fixture/BookFixture.php b/tests/Fixture/BookFixture.php index 9a2a5ba..2b13b0a 100644 --- a/tests/Fixture/BookFixture.php +++ b/tests/Fixture/BookFixture.php @@ -30,7 +30,7 @@ function anyBranch(): LibraryBranchId return new LibraryBranchId(UUID::random()); } -define('DDD_ISBN_STR', (string) 9780321125217); +const DDD_ISBN_STR = '9780321125217'; function dddBook(): Book { diff --git a/tests/Unit/Catalogue/CatalogueTest.php b/tests/Unit/Catalogue/CatalogueTest.php index 5b39f57..5d903c9 100644 --- a/tests/Unit/Catalogue/CatalogueTest.php +++ b/tests/Unit/Catalogue/CatalogueTest.php @@ -4,6 +4,7 @@ namespace Akondas\Library\Tests\Unit\Catalogue; +use Akondas\Library\Catalogue\BookInstance; use Akondas\Library\Catalogue\BookInstanceAddedToCatalogue; use Akondas\Library\Catalogue\BookType; use Akondas\Library\Catalogue\Catalogue; @@ -43,6 +44,8 @@ public function testGetBookFromCatalogue(): void public function testPutBookToCatalogue(): void { + // given + $this->database->method('saveBook')->willReturn(dddBook()); // when $result = $this->catalogue->addBook(DDD_ISBN_STR, 'Domain Driven Design', 'Eric Evans'); // then @@ -59,6 +62,7 @@ public function testPutNewBookInstanceToCatalogue(): void ->expects(self::once()) ->method('publish') ->with(self::isInstanceOf(BookInstanceAddedToCatalogue::class)); + $this->database->method('saveBookInstance')->willReturn(BookInstance::of(dddBook(), BookType::RESTRICTED)); // when $result = $this->catalogue->addBookInstance(DDD_ISBN_STR, BookType::RESTRICTED); // then diff --git a/tests/Unit/Common/UUIDTest.php b/tests/Unit/Common/UUIDTest.php index ea4746b..85a0ff1 100644 --- a/tests/Unit/Common/UUIDTest.php +++ b/tests/Unit/Common/UUIDTest.php @@ -5,9 +5,11 @@ namespace Akondas\Library\Tests\Unit\Common; use Akondas\Library\Common\UUID; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +#[CoversClass(UUID::class)] final class UUIDTest extends TestCase { #[Test] diff --git a/tests/Unit/Lending/Patron/Domain/PatronRequestingOpenEndedHoldTest.php b/tests/Unit/Lending/Patron/Domain/PatronRequestingOpenEndedHoldTest.php index 20a7a97..a265dc5 100644 --- a/tests/Unit/Lending/Patron/Domain/PatronRequestingOpenEndedHoldTest.php +++ b/tests/Unit/Lending/Patron/Domain/PatronRequestingOpenEndedHoldTest.php @@ -24,8 +24,8 @@ public function testResearcherPatronCanRequestCloseEndedHold(): void $event = $hold->get(); self::assertInstanceOf(BookPlacedOnHold::class, $event); self::assertEquals($patronId, $event->patronId()); - self::assertEquals($aBook->bookId(), $event->bookId()); - self::assertNull($event->holdTill()); + self::assertEquals($aBook->bookId(), $event->bookId); + self::assertNull($event->holdTill); } public function testRegularPatronCannotRequestOpenEndedHold(): void @@ -36,7 +36,7 @@ public function testRegularPatronCannotRequestOpenEndedHold(): void self::assertTrue($hold->isLeft()); self::assertStringContainsString( 'Regular patron cannot place open ended holds', - $hold->getLeft()->reason() + $hold->getLeft()->reason ); } } diff --git a/tests/Unit/Lending/Patron/Domain/RegularPatronRequestingRestrictedBooksTest.php b/tests/Unit/Lending/Patron/Domain/RegularPatronRequestingRestrictedBooksTest.php index fac5c78..2459fec 100644 --- a/tests/Unit/Lending/Patron/Domain/RegularPatronRequestingRestrictedBooksTest.php +++ b/tests/Unit/Lending/Patron/Domain/RegularPatronRequestingRestrictedBooksTest.php @@ -18,7 +18,7 @@ public function testARegularPatronCannotPlaceOnHoldRestrictedBook(): void self::assertTrue($hold->isLeft()); self::assertStringContainsString( 'Regular patrons cannot hold restricted books', - $hold->getLeft()->reason() + $hold->getLeft()->reason ); } }