if(isset($_POST['adate']) && isset($_POST['atime']) && isset($_POST['discno']) && isset($_POST['babybht']) && isset($_POST['motherbht']) && isset($_POST['ward']) && isset($_POST['namebo']) && isset($_POST['address1']) && isset($_POST['address2']) && isset($_POST['telephone']) && isset($_POST['ageonadmission']) && isset($_POST['admissionweight']) && isset($_POST['bdate']) && isset($_POST['btime']) && isset($_POST['poaw']) && isset($_POST['poad']) && isset($_POST['bweight']) && isset($_POST['placeofdelivery']) && isset($_POST['admittedfrom']){}

If I use so many boolean operators in a 'if condition' like above code fragment, will it affect to the reliability of the application. I've heard if the software complexity is more than 10 then that is not a reliable software.

Sorry for the broken English.

Recommended Answers

All 3 Replies

If you want to learn more about this google for cyclomatic complexity. See this article on Wikipedia.

Member Avatar

BTW - do you really mean isset or check that they're non-empty?

Text fields are always set even if they're empty after form submission.

You could to an array_map trim on $_POST - if these are the only post fields (and they're all text) and then do a count on all non-empty ones. If they're equal to the number that you're checking + 1 (+ 1 due to submit button maybe), then you don't need to check each. I haven't really thought that through, but I think it'd work.

Variations on a theme include using a count after an array_filter() to pull out blank fields. In addition, you could use a foreach à la JorgeM.

Also you could check with in_array()

There seem to be many, many ways to do this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.