<?php declare(strict_types=1); class Game { public function __construct( public readonly string $name ) {} } class GameCollection { private array $games = []; public function add(Game $game): void { $this->games[$game->name] = $game; } public function remove(Game $game): void { unset($this->games[$game->name]); } public function getAll(): array { return $this->games; } } class GameStore { public function __construct( private GameCollection $games, private GameCollection $loans ) {} public function addGame(Game $game): void { $this->games->add($game); } public function getAllGames(): array { return $this->games->getAll(); } public function checkOut(Game $game): void { $this->loans->add($game); $this->games->remove($game); } public function checkIn(Game $game): void { $this->loans->remove($game); $this->games->add($game); } public function getAllOnLoan(): array { return $this->loans->getAll(); } } $csgo = new Game('CS:GO'); $exp33 = new Game('Expedition 33'); $marioBros = new Game('Super Mario Bros'); $collection = new GameCollection(); $collection->add($csgo); $collection->add($exp33); $collection->add($marioBros); var_dump( 'Current collection:', $collection->getAll() ); $collection->remove($exp33); var_dump( 'Collection without Expedition 33:', $collection->getAll() ); $store = new GameStore( games: new GameCollection(), loans: new GameCollection() ); $store->addGame($csgo); $store->addGame($exp33); var_dump( 'GameStore', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() ); $store->checkOut($csgo); var_dump( 'GameStore - checkOut', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() ); $store->checkOut($exp33); $store->checkIn($csgo); var_dump( 'GameStore - checkIn & checkOut', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() );
You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).