i have a php object i called $product, it has several string properties. Now i want to check the values of its fields to see if they are empty, but i am having to do this with many if statements like below, is there any smarter way?, i don't mind using a library
private function validate(Product $product)
{
if (isEmpty($product->country)) {
throw New \Exception("country is empty");
} elseif (isEmpty($product->getCategory())) {
throw New \Exception("category is empty");
} elseif (isEmpty($product->getSubCategory())) {
throw New \Exception("subcategory is empty");
} elseif (isEmpty($product->getCoolingType())) {
throw New \Exception("category is empty");
} elseif (isEmpty($product->getPackagingType())) {
throw New \Exception("category is empty");
}
}
btw i am using symfony framwork 3.0 if that helps all the fields i am trying to validate are strings