-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat code in accordance with PSR-12 and add necessary comments.
Issue MIDU-177
- Loading branch information
1 parent
b88c849
commit 008ab0a
Showing
23 changed files
with
390 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
//require 'src/bootstrap.php'; | ||
|
||
use Logeecom\Bookstore\presentation\routers\BaseRouter; | ||
|
||
// TODO comments; | ||
// TODO refactor links to assets | ||
// TODO refactor validation code - like SinglePageAuthorController | ||
|
||
$request_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | ||
(new BaseRouter())->route($request_path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ | |
|
||
class AuthorLogic | ||
{ | ||
|
||
/** | ||
* @var AuthorRepositoryInterface - Repository of author data. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private AuthorRepositoryInterface $authorRepository; | ||
|
||
public function __construct(AuthorRepositoryInterface $authorRepository) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ | |
|
||
class BookLogic | ||
{ | ||
|
||
/** | ||
* @var BookRepositoryInterface - Repository of book data. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private BookRepositoryInterface $bookRepository; | ||
|
||
public function __construct( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,23 @@ | |
|
||
class Author implements \JsonSerializable | ||
{ | ||
|
||
/** | ||
* @var int|null - Id of the author. Null while object not persisted. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private ?int $id; | ||
/** | ||
* @var string - First name of the author. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private string $firstname; | ||
/** | ||
* @var string - Last name of the author. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private string $lastname; | ||
|
||
/** | ||
|
@@ -101,6 +115,10 @@ public function setLastname(string $lastname): void | |
$this->lastname = $lastname; | ||
} | ||
|
||
/** | ||
* Serializes Author object as JSON. | ||
* @return array | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,29 @@ | |
|
||
class Book implements \JsonSerializable | ||
{ | ||
|
||
/** | ||
* @var int|null - Id of the book. Null while object not persisted. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private ?int $id; | ||
/** | ||
* @var string - Title of the book. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private string $title; | ||
/** | ||
* @var int - Year of publishing of the book. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private int $year; | ||
/** | ||
* @var int - Id of author of the book. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private int $author_id; | ||
|
||
/** | ||
|
@@ -128,6 +147,10 @@ public function setAuthorId(?int $author_id): void | |
$this->author_id = $author_id; | ||
} | ||
|
||
/** | ||
* Serializes Book object as JSON. | ||
* @return array | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,18 @@ | |
|
||
class AuthorRepositoryDatabase implements AuthorRepositoryInterface | ||
{ | ||
|
||
/** | ||
* Name of table in DB. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private const TABLE_NAME = "authors"; | ||
|
||
/** | ||
* @var PDO - Connection to DB. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private PDO $PDO; | ||
|
||
public function __construct(PDO $PDO) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,8 @@ public function fetch(int $id): ?Author; | |
* Add an author. | ||
* | ||
* @param Author $author Author to be added. | ||
* @return bool True if adding successful. Otherwise, false. | ||
* @return Author|null Author object if adding successful. Otherwise, null. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function add(Author $author): ?Author; | ||
|
||
|
@@ -41,17 +40,16 @@ public function add(Author $author): ?Author; | |
* @param int $id Id of author to be edited. | ||
* @param string $firstname New firstname value. | ||
* @param string $lastname New lastname value. | ||
* @return bool True if editing successful. Otherwise, false. | ||
* @return Author|null Author object if editing successful. Otherwise, null. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function edit(int $id, string $firstname, string $lastname): ?Author; | ||
|
||
/** | ||
* Delete an author. | ||
* | ||
* @param int $id Id of author to be deleted. | ||
* @return bool True if deletion successful. Otherwise, not. | ||
* @return bool True if deletion successful. Otherwise, false. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,14 @@ class AuthorRepositorySession implements AuthorRepositoryInterface | |
{ | ||
/** | ||
* Session key for list of authors. | ||
* | ||
* @author Sava Gavric <[email protected]> | ||
*/ | ||
private const SESSION_TAG = "authors"; | ||
/** | ||
* Session key for auto-generated author key. | ||
* | ||
* @author Sava Gavric <[email protected]> | ||
*/ | ||
private const ID_TAG = "author_id"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,18 @@ | |
|
||
class BookRepositoryDatabase implements BookRepositoryInterface | ||
{ | ||
|
||
/** | ||
* Name of table in DB. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private const TABLE_NAME = "books"; | ||
|
||
/** | ||
* @var PDO - Connection to DB. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private PDO $PDO; | ||
|
||
public function __construct(PDO $PDO) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,14 @@ interface BookRepositoryInterface | |
*/ | ||
public function fetchAll(): array; | ||
|
||
/** | ||
* Fetch all books from the given author. | ||
* | ||
* @param int $author_id - Id of the author. | ||
* @return array Array of books. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function fetchAllFromAuthor(int $author_id): array; | ||
|
||
/** | ||
|
@@ -30,9 +38,9 @@ public function fetch(int $id): ?Book; | |
/** | ||
* Add a book. | ||
* | ||
* @return bool True if adding successful. Otherwise, false. | ||
* @param Book $book | ||
* @return Book|null Book object if adding successful. Otherwise, null. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function add(Book $book): ?Book; | ||
|
||
|
@@ -43,7 +51,7 @@ public function add(Book $book): ?Book; | |
* @param string $title New title value. | ||
* @param int $year New year value. | ||
* @param ?int $author_id New author Id value. | ||
* @return bool True if editing successful. Otherwise, false. | ||
* @return Book|null Book object if editing successful. Otherwise, null. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
|
@@ -53,7 +61,7 @@ public function edit(int $id, string $title, int $year, ?int $author_id): ?Book; | |
* Delete a book. | ||
* | ||
* @param int $id Id of book to be deleted. | ||
* @return bool True if deletion successful. Otherwise, not. | ||
* @return bool True if deletion successful. Otherwise, false. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,14 @@ class BookRepositorySession implements BookRepositoryInterface | |
{ | ||
/** | ||
* Session key for list of books. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private const SESSION_TAG = "books"; | ||
/** | ||
* Session key for auto-generated book key. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
private const ID_TAG = "book_id"; | ||
|
||
|
@@ -116,8 +120,11 @@ public function delete(int $id): bool | |
|
||
/** | ||
* Deletes all books from given author. | ||
* | ||
* @param int $author_id Id of author. | ||
* @return bool Returns true if all books successfully deleted. Otherwise, returns false. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function deleteAllFromAuthor(int $author_id): bool | ||
{ | ||
|
@@ -132,8 +139,11 @@ public function deleteAllFromAuthor(int $author_id): bool | |
|
||
/** | ||
* Returns number of books written by the author. | ||
* | ||
* @param int $id Id of the author. | ||
* @return int Number of books. | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function countFromAuthor(int $id): int | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,13 @@ | |
|
||
interface ControllerInterface | ||
{ | ||
/** | ||
* Parses path and processes the request. | ||
* | ||
* @param string $path Path of the request. | ||
* @return void | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function process(string $path): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,13 @@ | |
|
||
interface RouterInterface | ||
{ | ||
/** | ||
* Route execution to appropriate controller | ||
* | ||
* @param string $request_path - Path of the request. | ||
* @return void | ||
* @author Sava Gavric <[email protected]> | ||
* | ||
*/ | ||
public function route(string $request_path): void; | ||
} |
Oops, something went wrong.