Skip to content

Instantly share code, notes, and snippets.

@nahidulhasan
Last active May 23, 2018 04:35
Show Gist options
  • Save nahidulhasan/3e08895ea708e1990e9f3d7f7c4a66dc to your computer and use it in GitHub Desktop.
Save nahidulhasan/3e08895ea708e1990e9f3d7f7c4a66dc to your computer and use it in GitHub Desktop.
<?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