lundi 28 novembre 2016

3 Methods in a repository or merge into 1 method?

I have created a TokenRepository class with 3 methods.

Those methods create an entry to same a table but each method have different fields. Is this good pattern or should I use an interface and 3 implementations or merge 3 methods into 1 method?

For example:

class TokenRepository
{

  public function createTokenDigitalOcean(User $user, $name, $accessToken, $refreshToken = null)
    {
        return $user->tokens()->create([
            'name'          => $name,
            'provider'      => 'digital_ocean',
            'access_token'  => $accessToken,
            'refresh_token' => $refreshToken,
        ]);
    }

    public function createTokenLinode(User $user, $name, $key)
    {
        return $user->tokens()->create([
            'name'       => $name,
            'provider'   => 'linode',
            'linode_key' => $key,
        ]);
    }

    public function createTokenAws(User $user, $name, $key, $secret)
    {
        return $user->tokens()->create([
            'name'       => $name,
            'provider'   => 'aws',
            'aws_key'    => $key,
            'aws_secret' => $secret,
        ]);
    }
}

Aucun commentaire:

Enregistrer un commentaire