/** * Checks the evaluations of the current article * @param BlogComment $blogComments * @param $average * @param array $comments * @throws \Exception */ public function checkComments(BlogComment $blogComments, $average, array $comments) { $this->checkRating($blogComments, $average); $comments = Helper::floatArray($comments, ['stars']); $result = Helper::assertElements($comments, $blogComments); if ($result === true) { return; } $messages = array('The following comments are wrong:'); foreach ($result as $evaluation) { $messages[] = sprintf('%s - Bewertung: %s (%s is "%s", should be "%s")', $evaluation['properties']['author'], $evaluation['properties']['stars'], $evaluation['result']['key'], $evaluation['result']['value'], $evaluation['result']['value2']); } Helper::throwException($messages); }
/** * Checks the cart positions * Available properties are: number (required), name (required), quantity, itemPrice, sum * @param CartPosition $cartPositions * @param array $items */ public function checkCartProducts(CartPosition $cartPositions, array $items) { Helper::assertElementCount($cartPositions, count($items)); $items = Helper::floatArray($items, ['quantity', 'itemPrice', 'sum']); $result = Helper::assertElements($items, $cartPositions); if ($result !== true) { $messages = ['The following articles are wrong:']; foreach ($result as $product) { $messages[] = sprintf('%s - %s (%s is "%s", should be "%s")', $product['properties']['number'], $product['properties']['name'], $product['result']['key'], $product['result']['value'], $product['result']['value2']); } Helper::throwException($messages); } }