From 57f61183083cfe1ca06b50e8cd6c1f2149e243d4 Mon Sep 17 00:00:00 2001 From: Patrick Louys Date: Tue, 1 Nov 2016 17:17:52 +0100 Subject: [PATCH] Update 10-dynamic-pages.md --- 10-dynamic-pages.md | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/10-dynamic-pages.md b/10-dynamic-pages.md index ca41bb5..eea4ac7 100644 --- a/10-dynamic-pages.md +++ b/10-dynamic-pages.md @@ -48,7 +48,7 @@ namespace Example\Page; interface PageReader { - public function readBySlug($slug) : string; + public function readBySlug(string $slug) : string; } ``` @@ -70,7 +70,7 @@ class FilePageReader implements PageReader $this->pageFolder = $pageFolder; } - public function readBySlug($slug) : string + public function readBySlug(string $slug) : string { return 'I am a placeholder'; } @@ -142,18 +142,7 @@ class Page So far so good, now let's make our `FilePageReader` actually do some work. -Again, let's check first that the proper type was passed into the method: - -```php -public function readBySlug($slug) -{ - if (!is_string($slug)) { - throw new InvalidArgumentException('slug must be a string'); - } -} -``` - -We also need to be able to communicate that a page was not found. For this we can create a custom exception that we can catch later. In your `src/Page` folder, create a `InvalidPageException.php` file with this content: +We need to be able to communicate that a page was not found. For this we can create a custom exception that we can catch later. In your `src/Page` folder, create a `InvalidPageException.php` file with this content: ```php