Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope of variables #2

Closed
harikt opened this issue Jul 9, 2011 · 1 comment
Closed

Scope of variables #2

harikt opened this issue Jul 9, 2011 · 1 comment
Assignees

Comments

@harikt
Copy link
Member

harikt commented Jul 9, 2011

Hi Paul ,
As you have already mentioned in irc , this is just an initial commit , you can ignore if I am also wrong :-) .

Currently in many places , some variables are never assigned . For eg: currently for getRead() , see $slaves . In constructor we are accepting and setting $slaves , $masters array.

// pick a random slave, or a random master if no slaves, or default if no masters
public function getRead()
{
    if ($slaves) {
        return $this->getRandomSlave();
    } elseif ($masters) {
        return $this->getRandomMaster();
    } else {
        return $this->getDefault();
    }
}

So I guess the below implementation will be the correct way .

// pick a random slave, or a random master if no slaves, or default if no masters
public function getRead()
{
    if (!empty($this->slaves)) {
        return $this->getRandomSlave();
    } elseif (!empty($this->masters)) {
        return $this->getRandomMaster();
    } else {
        return $this->getDefault();
    }
}

getRandomSlave() and getRandomSlave() are having $key which is not assigned . See below.

// converts a random $this->masters entry to a Connection object
public function getRandomSlave()
{
    if (! $key) {
        $key = array_rand($this->slaves);
    } elseif (! isset($this->slaves[$key])) {
        throw new Exception\NoSuchConnection;
    }

    if (! $this->conn['slaves'][$key] instanceof Connection) {
        list($adapter, $params) = $this->merge($this->slaves[$key]);
        $this->conn['slaves'][$key] = $this->factory->newInstance($adapter, $params);
    }
    return $this->conn['slaves'][$key];
}

My commit is over

harikt@794181f

As told for the getRandomSlave() and getRandomSlave() , I have not made any changes . Please have a look .

Thanks

@ghost ghost assigned pmjones Jul 9, 2011
@harikt
Copy link
Member Author

harikt commented Jul 11, 2011

Merged in 08af037 .
This resolves the current issue .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants