Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the Repository interface.
PHP
<?php
interface [1] {
public function findAll();
}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated names like Service or Controller for the interface.
✗ Incorrect
The interface is named Repository to define the contract for data access.
2fill in blank
mediumComplete the method signature to find an item by its ID.
PHP
<?php
interface Repository {
public function findById([1] $id);
}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect types like bool or array for the ID parameter.
✗ Incorrect
The findById method usually takes an int as the ID parameter.
3fill in blank
hardFix the error in the repository implementation class declaration.
PHP
<?php class UserRepository [1] Repository { public function findAll() { // code to get all users } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'extends' keyword for interfaces causes errors.
✗ Incorrect
In PHP, classes implement interfaces using the implements keyword.
4fill in blank
hardFill both blanks to complete the method that saves a user entity.
PHP
<?php class UserRepository implements Repository { public function save([1] $user) : [2] { // code to save user } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter types or return types like void or array.
✗ Incorrect
The save method takes a User object and returns a bool indicating success.
5fill in blank
hardFill all three blanks to complete the repository method that deletes a user by ID.
PHP
<?php class UserRepository implements Repository { public function delete([1] $id) : [2] { // code to delete user return [3]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types or returning false by default.
✗ Incorrect
The delete method takes an int ID, returns a bool, and returns true on success.