Skip to content

Instantly share code, notes, and snippets.

@irfan
Created January 2, 2016 00:02
Show Gist options
  • Save irfan/d59af29477244078ccbc to your computer and use it in GitHub Desktop.
Save irfan/d59af29477244078ccbc to your computer and use it in GitHub Desktop.
<?php
/**
* user nick update
*/
namespace \User\Credential;
class User extends BaseUser
{
/**
* @User's current nick name
* @type String
*/
private $currentUsername;
/**
* @type String
*/
private $newUsername;
/**
* @param $username String
*/
public function setCurrentUsername($username)
{
$this->currentUsername = $username;
}
/**
* @param $username String
*/
public function setNewUsername($username)
{
$this->newUsername = $username;
}
/**
* TODO: We need implementation of the function
*/
public function isUsernameExists()
{
return false;
}
/**
* Checks the username whether valid
*/
public function isValid()
{
if (!$this->isUsernameExists()) {
preg_match("^[a-z0-9_-]{3,15}$", $this->newUsername, $matches);
return $matches;
}
}
/**
* Set new username
*/
public function saveUsername($users)
{
foreach ($users as $id => $user) {
if ($user['nickname'] == $this->currentUsername) {
$users[$id]['nickname'] = $this->newUsername;
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment