Last active
May 23, 2018 04:35
-
-
Save nahidulhasan/3e08895ea708e1990e9f3d7f7c4a66dc to your computer and use it in GitHub Desktop.
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
<?php | |
interface LessonRepositoryInterface | |
{ | |
/** | |
* Fetch all records. | |
* | |
* @return array | |
*/ | |
public function getAll(); | |
} | |
class FileLessonRepository implements LessonRepositoryInterface | |
{ | |
public function getAll() | |
{ | |
// return through file system | |
return []; | |
} | |
} | |
class DbLessonRepository implements LessonRepositoryInterface | |
{ | |
public function getAll() | |
{ | |
/* | |
Violates LSP because: | |
- the return type is different | |
- the consumer of this subclass and FileLessonRepository won't work identically | |
*/ | |
// return Lesson::all(); | |
// to fix this | |
return Lesson::all()->toArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment