/**
  * @param Category $category
  */
 public function addCategory(Category $category)
 {
     if (null === $category->getCertification()) {
         $category->setCertification($this);
     }
     $this->categories->add($category);
 }
 /**
  * @param Category $category
  * @param Question $question
  * @param Answer   $answer
  *
  * @return string
  */
 public static function getHash(Category $category, Question $question, Answer $answer)
 {
     return md5($category->getName() . $question->getName() . $answer->getName());
 }
 /**
  * @param Category $category
  *
  * @return bool
  */
 public function getReportMetrics(Category $category)
 {
     if (!isset($this->reportMetrics[$category->getName()])) {
         return false;
     }
     return $this->reportMetrics[$category->getName()];
 }
 /**
  * @param CertificationContextInterface $context
  *
  * @return Certification
  */
 protected function normalize(CertificationContextInterface $context)
 {
     $certification = static::createCertification();
     $certification->setContext($context);
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('Normalize %s', $context->getName()));
     }
     $flattenResources = $this->collector->getFlattenResources($context->getName());
     //Should I throw Exception like NoResourcesCollectedException ?
     if (empty($flattenResources)) {
         return $certification;
     }
     $metrics = $certification->getMetrics();
     foreach ($this->collector->getFlattenResources($context->getName()) as $resource) {
         if ($resource->getCertificationName() !== $context->getName()) {
             continue;
         }
         $resourceContent = $resource->getContent();
         if (empty($resourceContent)) {
             continue;
         }
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Adding resource %s on certification %s', $resource->getResourceName(), $resource->getCertificationName()), $resource->getContent());
         }
         $category = new Category();
         $category->setLabel($resourceContent['category']);
         $category->setName($resource->getResourceName());
         $metrics->increment(Metrics::CATEGORY);
         if (empty($resourceContent['questions'])) {
             $resourceContent['questions'] = [];
         }
         foreach ($resourceContent['questions'] as $questionContent) {
             $question = new Question();
             $question->setLabel($questionContent['question']);
             $metrics->increment(Metrics::QUESTION);
             foreach ($questionContent['answers'] as $answerContent) {
                 $answer = new Answer();
                 $answer->setLabel($answerContent['value']);
                 $answer->setExpected($answerContent['correct']);
                 $metrics->increment(Metrics::ANSWER);
                 $question->addAnswer($answer);
             }
             $category->addQuestion($question);
         }
         $certification->addCategory($category);
     }
     return $certification;
 }
 /**
  * @param array $data
  *
  * @return Category
  */
 public static function __set_state(array $data)
 {
     $category = new Category();
     $category->setLabel($data['label']);
     $category->setName($data['name']);
     $category->setQuestions($data['questions']);
     return $category;
 }