/**
  * @param array        $parameters
  * @param Lead         $lead
  * @param CompanyModel $companyModel
  *
  * @return array
  */
 public static function identifyLeadsCompany($parameters, Lead $lead, CompanyModel $companyModel)
 {
     $companyName = $companyDomain = null;
     $leadAdded = false;
     if (isset($parameters['company'])) {
         $companyName = filter_var($parameters['company'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     } elseif (isset($parameters['email'])) {
         $companyName = $companyDomain = self::domainExists($parameters['email']);
     }
     if ($companyName) {
         $companyRepo = $companyModel->getRepository();
         $city = isset($parameters['city']) ? $parameters['city'] : null;
         $country = isset($parameters['country']) ? $parameters['country'] : null;
         $state = isset($parameters['state']) ? $parameters['state'] : null;
         $company = $companyRepo->identifyCompany($companyName, $city, $country, $state);
         if (!empty($company)) {
             //check if lead is already assigned to company
             $companyLeadRepo = $companyModel->getCompanyLeadRepository();
             if (empty($companyLeadRepo->getCompaniesByLeadId($lead->getId(), $company['id']))) {
                 $leadAdded = true;
             }
         } else {
             //create new company
             $company = ['companyname' => $companyName, 'companywebsite' => $companyDomain, 'companycity' => $city, 'companystate' => $state, 'companycountry' => $country];
             $companyEntity = $companyModel->getEntity();
             $companyModel->setFieldValues($companyEntity, $company, true);
             $companyModel->saveEntity($companyEntity);
             $company['id'] = $companyEntity->getId();
             $leadAdded = true;
         }
         return [$company, $leadAdded];
     }
     return [null, false];
 }