1

Sorry, noob question. What's the best way to refactor this?

if (is_dir('temp'))
{
  ===== do action A =====
}
else
{
  mkdir("/path/to/my/dir", 0755);
  ===== do action A =====
}

Thanks.

2
  • 2
    Is there a need to refactor this? I don't really see it. Commented Aug 9, 2011 at 7:18
  • Not sure you would need to... Commented Aug 9, 2011 at 7:21

4 Answers 4

8
if (!is_dir('temp'))
{
   mkdir("/path/to/my/dir", 0755);
}
===== do action A =====
Sign up to request clarification or add additional context in comments.

Comments

3

What about:

if (!is_dir('temp'))
{
    mkdir("/path/to/my/dir", 0755);
}
===== do action A =====

Comments

1

Personally, I use this 'shorthand' for if blocks that only contain one line of code.

if(!is_dir('temp'))
    mkdir("/path/to/my/dir", 0755);

Comments

0
if(!is_dir('temp')){ mkdir("/path/to/my/dir", 0755); }

===== do action A =====

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.