Skip to content

Instantly share code, notes, and snippets.

@midorikocak
Created January 27, 2020 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midorikocak/b3c220e79655e072dcf4b69d59eeecbc to your computer and use it in GitHub Desktop.
Save midorikocak/b3c220e79655e072dcf4b69d59eeecbc to your computer and use it in GitHub Desktop.
Interface for a CRUD app.
<?php
declare(strict_types=1);
namespace midorikocak\nano;
use Exception;
interface CrudInterface
{
/**
* @param array $data Array data of an Item.
* @return array Array data of an Item with id.
* @throws Exception if the data does not pass validate
*/
public function create(array $data): array;
/**
* @param string $id
* @return array Returns the array of New Item.
* @throws Exception if something bad happens
*/
public function read($id): array;
/**
* @param string $id Can be an integer or a string
* @param array $data Accepts Array data of an Item with or without id.
* @return array Returns the array of Updated Item.
* @throws Exception if something bad happens
* @todo Is it ok to have id in array data?
*/
public function update(string $id, array $data): array;
/**
* @param string $id Can be an integer or a string
* @return void Returns nothing. Simple Command Query separation.
* @throws Exception if id not found or something bad happens
* @todo Should create different exceptions for negative outcomes
*/
public function delete(string $id): void;
/**
* @return array[] Should return an array of arrays that contain Item Data.
*/
public function list(): array;
/**
* We have to validate data in every operation that receives item array.
* @param array $data Accepts Array data of an Item with or without id.
* @todo How we can be sure that this runs in every method that acceps item data?
* @todo Maybe an abstract class?
*
* @return bool
*/
public function validateData(array $data): bool;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment