Today when I was refactoring my PHP Pinterest Bot, I’ve noticed that it has a logout method with a boolean param. So when you want to logout, you use something like this:
But you can also type this:
And I actually didn’t remember what means this true. Looking through the code, I’ve remembered that is a flag to clear cookies:
And here comes the question. Should I leave it as it is or should I refactor it somehow. Because again in six months I should look through the code or the documentation to find out, what does true means in
$bot->auth->logout(true). The boolean passed as a flag to the method always mean, that this method does too much. It has several tasks, each is performed according to the passed flag.
So, of cource we can pass this parameter explicitly:
And now we can read the code, and understand the purpose of the param. But the core problem still exists. The method does too much. I think that it is better to create a separate method to handle cookies. Something like this:
Now I have two clear methods, and in six months from now, there will be no questions about their meanings and purpose.