Hydrate a scan object into a ScanEntity object

@param stdClass $scan
@return ScanEntity
321458
public static function hydrate(stdClass $scan)
    {
        $hydrated = new ScanEntity();

        if (isset($scan->id)) {
            $hydrated->setId($scan->id);
        }

        if (isset($scan->version)) {
            $hydrated->setVersion($scan->version);
        }

        if (isset($scan->path)) {
            $hydrated->setPath($scan->path);
        }

        if (isset($scan->started_at)) {
            $hydrated->setStartedAt(new DateTime($scan->started_at));
        }

        if (isset($scan->finished_at)) {
            $hydrated->setFinishedAt(new DateTime($scan->finished_at));
        }

        if (isset($scan->phase)) {
            $hydrated->setPhase($scan->phase);
        }

        if (isset($scan->percent)) {
            $hydrated->setPercent($scan->percent);
        }

        if (isset($scan->loc)) {
            $hydrated->setLoc($scan->loc);
        }

        if (isset($scan->code_stored)) {
            $hydrated->setCodeStored($scan->code_stored);
        }

        if (isset($scan->upload_removed)) {
            $hydrated->setUploadRemoved($scan->upload_removed);
        }

        if (isset($scan->full_code_compared)) {
            $hydrated->setFullCodeCompared($scan->full_code_compared);
        }

        if (isset($scan->history_inherited)) {
            $hydrated->setHistoryInherited($scan->history_inherited);
        }

        if (isset($scan->source_type)) {
            $hydrated->setSourceType($scan->source_type);
        }

        if (isset($scan->php)) {
            $hydrated->setPhp(PhpHydrator::hydrate($scan->php));
        }

        if (isset($scan->java)) {
            $hydrated->setJava(JavaHydrator::hydrate($scan->java));
        }

        if (isset($scan->upload)) {
            $hydrated->setUpload(UploadHydrator::hydrate($scan->upload));
        }

        if (isset($scan->application)) {
            $hydrated->setApplication(ApplicationHydrator::hydrate($scan->application));
        }

        if (isset($scan->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($scan->created_by));
        }

        if (isset($scan->profile)) {
            $hydrated->setProfile(ProfileHydrator::hydrate($scan->profile));
        }

        if (isset($scan->issue_types) && is_array($scan->issue_types)) {
            $hydrated->setIssueTypes(IssueTypeHydrator::hydrateCollection($scan->issue_types));
        }

        if (isset($scan->parent)) {
            $hydrated->setParent(self::hydrate($scan->parent));
        }

        if (isset($scan->severity_distributions)) {
            $hydrated->setSeverityDistributions((array)$scan->severity_distributions);
        }

        if (isset($scan->analysis_depth)) {
            $hydrated->setAnalysisDepth($scan->analysis_depth);
        }

        if (isset($scan->tags)) {
            $hydrated->setTags($scan->tags);
        }

        if (isset($scan->max_issues_per_type)) {
            $hydrated->setMaxIssuesPerType($scan->max_issues_per_type);
        }

        if (isset($scan->comment)) {
            $hydrated->setComment($scan->comment);
        }

        if (isset($scan->source)) {
            $hydrated->setSource($scan->source);
        }

        if (isset($scan->libraries) && is_array($scan->libraries)) {
            $hydrated->setLibraries(LibraryHydrator::hydrateCollection($scan->libraries));
        }

        if (isset($scan->processes) && is_array($scan->processes)) {
            $hydrated->setProcesses(ProcessHydrator::hydrateCollection($scan->processes));
        }

        if (isset($scan->languages) && is_array($scan->languages)) {
            $hydrated->setLanguages(LanguageHydrator::hydrateCollection($scan->languages));
        }

        if (isset($scan->comparison)) {
            $hydrated->setComparison(ComparisonHydrator::hydrate($scan->comparison));
        }
        return $hydrated;
    }
628648
protected function hydrateEntity($result)
    {
        $client = new ClientEntity($this->getServer());
        $client->hydrate([
            'id' => $result->id,
            'name' => $result->name,
            'secret' => $result->secret,
            'redirectUri' => (isset($result->redirect_uri) ? $result->redirect_uri : null),
        ]);

        return $client;
    }
340412
public static function hydrate(stdClass $activity)
    {
        $hydrated = new ActivityEntity();

        if (isset($activity->id)) {
            $hydrated->setId($activity->id);
        }

        if (isset($activity->type)) {
            $hydrated->setType($activity->type);
        }

        if (isset($activity->context)) {
            $hydrated->setContext(json_decode(json_encode($activity->context), true));
        }

        if (isset($activity->application)) {
            $hydrated->setApplication(ApplicationHydrator::hydrate($activity->application));
        }

        if (isset($activity->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($activity->created_by));
        }

        if (isset($activity->created_at)) {
            $hydrated->setCreatedAt(new DateTime($activity->created_at));
        }

        return $hydrated;
    }
150384
public static function hydrate(stdClass $log)
    {
        $hydrated = new LogEntity();

        if (isset($log->id)) {
            $hydrated->setId($log->id);
        }

        if (isset($log->text)) {
            $hydrated->setText($log->text);
        }

        if (isset($log->level)) {
            $hydrated->setLevel($log->level);
        }

        if (isset($log->channel)) {
            $hydrated->setChannel($log->channel);
        }

        if (isset($log->request_uri)) {
            $hydrated->setRequestUri($log->request_uri);
        }

        if (isset($log->request_method)) {
            $hydrated->setRequestMethod($log->request_method);
        }

        if (isset($log->ip)) {
            $hydrated->setIp($log->ip);
        }

        if (isset($log->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($log->created_by));
        }

        if (isset($log->email)) {
            $hydrated->setEmail($log->email);
        }

        if (isset($log->organization)) {
            $hydrated->setOrganization(OrgHydrator::hydrate($log->organization));
        }

        if (isset($log->organization_name)) {
            $hydrated->setOrganizationName($log->organization_name);
        }

        if (isset($log->context)) {
            $hydrated->setContext($log->context);
        }

        if (isset($log->created_at)) {
            $hydrated->setCreatedAt(new DateTime($log->created_at));
        }

        if (isset($log->user_agent)) {
            $hydrated->setUserAgent($log->user_agent);
        }

        return $hydrated;
    }
1276028
public static function hydrate(stdClass $quota)
    {
        $hydrated = new QuotaEntity();

        if (isset($quota->id)) {
            $hydrated->setId($quota->id);
        }

        if (isset($quota->current_application)) {
            $hydrated->setCurrentApplication($quota->current_application);
        }

        if (isset($quota->current_scan)) {
            $hydrated->setCurrentScan($quota->current_scan);
        }

        if (isset($quota->current_user)) {
            $hydrated->setCurrentUser($quota->current_user);
        }

        if (isset($quota->max_applications)) {
            $hydrated->setMaxApplications($quota->max_applications);
        }

        if (isset($quota->max_scans)) {
            $hydrated->setMaxScans($quota->max_scans);
        }

        if (isset($quota->max_users)) {
            $hydrated->setMaxUsers($quota->max_users);
        }

        if (isset($quota->max_loc)) {
            $hydrated->setMaxLoc($quota->max_loc);
        }

        if (isset($quota->valid_from)) {
            $hydrated->setValidFrom(new DateTime($quota->valid_from));
        }

        if (isset($quota->valid_until)) {
            $hydrated->setValidUntil(new DateTime($quota->valid_until));
        }

        if (isset($quota->allowed_misses)) {
            $hydrated->setAllowedMisses($quota->allowed_misses);
        }

        if (isset($quota->public)) {
            $hydrated->setPublic($quota->public);
        }

        if (isset($quota->organization)) {
            $hydrated->setOrganization(OrgHydrator::hydrate($quota->organization));
        }

        if (isset($quota->created_at)) {
            $hydrated->setCreatedAt(new DateTime($quota->created_at));
        }

        if (isset($quota->languages) && is_array($quota->languages)) {
            $hydrated->setLanguages(LanguageHydrator::hydrateCollection($quota->languages));
        }

        if (isset($quota->notify)) {
            $hydrated->setNotify($quota->notify);
        }

        if (isset($quota->trial_issue_types) && is_array($quota->trial_issue_types)) {
            $hydrated->setTrialIssueTypes(TypeHydrator::hydrateCollection($quota->trial_issue_types));
        }

        if (isset($quota->issue_type_limit)) {
            $hydrated->setIssueTypeLimit($quota->issue_type_limit);
        }

        if (isset($quota->update_only)) {
            $hydrated->setUpdateOnly($quota->update_only);
        }

        if (isset($quota->flexible_applications)) {
            $hydrated->setFlexibleApplications($quota->flexible_applications);
        }

        return $hydrated;
    }
1145383
private function hydrateEntity($document)
    {
        $class = $this->entityClass;
        $reflectionClass = new \ReflectionClass(AbstractDocument::class);
        $entity = new $class();

        if (!($entity instanceof AbstractDocument)) {
            throw new \Exception(sprintf('"%s" is not a subclass of "%s"', $this->entityClass, AbstractDocument::class));
        }

        $documentProperty = $reflectionClass->getProperty('document');
        $documentProperty->setAccessible(true);
        $documentProperty->setValue($entity, $document);

        return $entity;
    }
343102
public function populate($entityName)
    {
        if (!class_exists($entityName)) {
            throw new \RuntimeException(sprintf('Entity %s does not exists.', $entityName));
        }

        $feed = $this->get();

        return $this->hydrator->hydrate($feed, $entityName);
    }
911232
public function scan($table, Context\Scan $context = null)
    {
        if (null !== $this->logger) {
            $this->log('Scan on table '.$table);
        }

        $parameters = array(
            'TableName' => $table
        );

        if (null !== $context) {
            $parameters += $context->getForDynamoDB();
        }

        if (null !== $this->logger) {
            $this->log('Scan request paramaters : '.print_r($parameters, true), Logger::DEBUG);
        }

        $response = $this->connector->scan($parameters);

        if (null !== $this->logger) {
            $this->log('Scan request response : '.print_r($response, true), Logger::DEBUG);
            $this->log($response['ScannedCount'].' scanned items');
        }

        $this->addConsumedReadUnits($table, floatval($response['ConsumedCapacityUnits']));

        if (isset($response['LastEvaluatedKey'])) {
            if (null === $context) {
                $nextContext = new Context\Scan();
            } else {
                $nextContext = clone $context;
            }
            $nextContext->setExclusiveStartKey($response['LastEvaluatedKey']);

            if (null !== $this->logger) {
                $this->log('More Items to retrieve');
            }
        } else {
            $nextContext = null;
        }

        $items = new Collection(
            $nextContext,
            $response['Count']
        );
        if (!empty($response['Items'])) {
            foreach ($response['Items'] as $responseItem) {
                $item = new Item($table);
                $item->populateFromDynamoDB($responseItem);
                $items->add($item);
            }
        }

        if (null !== $this->logger) {
            $this->log('Find '.count($items).' Items');
        }

        return $items;
    }
1115686
public static function hydrate(stdClass $organization)
    {
        $hydrated = new OrgEntity();

        if (isset($organization->id)) {
            $hydrated->setId($organization->id);
        }

        if (isset($organization->name)) {
            $hydrated->setName($organization->name);
        }

        if (isset($organization->valid_until)) {
            $hydrated->setValidUntil(new DateTime($organization->valid_until));
        }

        if (isset($organization->quotas) && is_array($organization->quotas)) {
            $hydrated->setQuotas(QuotaHydrator::hydrateCollection($organization->quotas));
        }

        if (isset($organization->trial_issue_types) && is_array($organization->trial_issue_types)) {
            $hydrated->setTrialIssueTypes(TypeHydrator::hydrateCollection($organization->trial_issue_types));
        }

        if (isset($organization->disabled)) {
            $hydrated->setDisabled($organization->disabled);
        }

        return $hydrated;
    }
92684
private function scan(RecordSchema $context, array $columns, array $relations)
    {
        $flatColumns = $this->processColumns($columns);

        $fields = $this->processFields($context->getFields(), $columns);
        $relations = $this->findRelations($context->getClass(), $relations);
        $properties = array_merge($flatColumns, $fields, $relations);

        $docs = [];
        foreach ($properties as $name => $type) {
            $docs[] = new ClassProperty($name, $type);
        }

        return $docs;
    }
1276423
public static function hydrate(stdClass $comparison)
    {
        $hydrated = new ComparisonEntity();

        if (isset($comparison->id)) {
            $hydrated->setId($comparison->id);
        }

        if (isset($comparison->allowedMisses)) {
            $hydrated->setAllowedMisses($comparison->allowedMisses);
        }

        if (isset($comparison->filesThreshold)) {
            $hydrated->setFilesThreshold($comparison->filesThreshold);
        }

        if (isset($comparison->scannedOldFiles)) {
            $hydrated->setScannedOldFiles($comparison->scannedOldFiles);
        }

        if (isset($comparison->scannedNewFiles)) {
            $hydrated->setScannedNewFiles($comparison->scannedNewFiles);
        }

        if (isset($comparison->skippedOldFiles)) {
            $hydrated->setSkippedOldFiles($comparison->skippedOldFiles);
        }

        if (isset($comparison->skippedNewFiles)) {
            $hydrated->setSkippedNewFiles($comparison->skippedNewFiles);
        }

        if (isset($comparison->misses)) {
            $hydrated->setMisses($comparison->misses);
        }

        return $hydrated;
    }
384205
public static function hydrate(stdClass $java)
    {
        $hydrated = new JavaEntity();

        if (isset($java->id)) {
            $hydrated->setId($java->id);
        }

        if (isset($java->major_version)) {
            $hydrated->setMajorVersion($java->major_version);
        }

        if (isset($java->minor_version)) {
            $hydrated->setMinorVersion($java->minor_version);
        }

        if (isset($java->release_version)) {
            $hydrated->setReleaseVersion($java->release_version);
        }

        if (isset($java->implementation)) {
            $hydrated->setImplementation($java->implementation);
        }

        if (isset($java->setting)) {
            $hydrated->setSetting(SettingHydrator::hydrate($java->setting));
        }

        return $hydrated;
    }
1310456
public static function hydrate(stdClass $review)
    {
        $hydrated = new ReviewEntity();

        if (isset($review->id)) {
            $hydrated->setId($review->id);
        }

        if (isset($review->created_at)) {
            $hydrated->setCreatedAt(new DateTime($review->created_at));
        }

        if (isset($review->type)) {
            $hydrated->setType(ReviewTypeHydrator::hydrate($review->type));
        }

        if (isset($review->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($review->created_by));
        }

        if (isset($review->source)) {
            $hydrated->setSource($review->source);
        }

        if (isset($review->issue)) {
            $hydrated->setIssue(IssueHydrator::hydrate($review->issue));
        }

        return $hydrated;
    }
1032583
public static function hydrate(stdClass $type)
    {
        $hydrated = new TypeEntity();

        if (isset($type->id)) {
            $hydrated->setId($type->id);
        }

        if (isset($type->tag)) {
            $hydrated->setTag($type->tag);
        }

        if (isset($type->description)) {
            $hydrated->setDescription($type->description);
        }

        if (isset($type->name)) {
            $hydrated->setName($type->name);
        }

        if (isset($type->markup)) {
            $hydrated->setMarkup($type->markup);
        }

        if (isset($type->severity)) {
            $hydrated->setSeverity($type->severity);
        }

        if (isset($type->effort)) {
            $hydrated->setEffort($type->effort);
        }

        if (isset($type->second_order)) {
            $hydrated->setSecondOrder($type->second_order);
        }

        if (isset($type->cwe)) {
            $hydrated->setCwe($type->cwe);
        }

        if (isset($type->owasp2010)) {
            $hydrated->setOwasp2010($type->owasp2010);
        }

        if (isset($type->owasp2013)) {
            $hydrated->setOwasp2013($type->owasp2013);
        }

        if (isset($type->owasp2017)) {
            $hydrated->setOwasp2017($type->owasp2017);
        }

        if (isset($type->sans)) {
            $hydrated->setSans($type->sans);
        }

        if (isset($type->pcidss)) {
            $hydrated->setPcidss($type->pcidss);
        }

        if (isset($type->asvs301)) {
            $hydrated->setAsvs301($type->asvs301);
        }

        if (isset($type->asvs401)) {
            $hydrated->setAsvs401($type->asvs401);
        }

        if (isset($type->enabled)) {
            $hydrated->setEnabled($type->enabled);
        }

        if (isset($type->category)) {
            $hydrated->setCategory($type->category);
        }

        if (isset($type->parent)) {
            $hydrated->setParent(self::hydrate($type->parent));
        }

        if (isset($type->resources)) {
            $hydrated->setResources(ResourceHydrator::hydrateCollection($type->resources));
        }

        if (isset($type->inactive)) {
            $hydrated->setInactive($type->inactive);
        }

        if (isset($type->languages) && is_array($type->languages)) {
            $hydrated->setLanguages(LanguageHydrator::hydrateCollection($type->languages));
        }

        return $hydrated;
    }
1322887
public function hydrateCollection(array $collection)
    {
        $records = array();

        foreach ($collection as $key => $record) {
            if ($record instanceof \stdClass) {
                $records[$key] = $this->hydrate($record);
            } else {
                $records[$key] = $this->hydrateRid(new Rid($record));
            }
        }

        return new ArrayCollection($records);
    }
79336
public static function update($entity)
    {
        $entityManager = self::getEntityManager();
        $entity = $entityManager->merge($entity);
        $entityManager->flush(); // transact

        return $entity;
    }
642290
public static function hydrate(stdClass $extension)
    {
        $hydrated = new ExtensionEntity();

        if (isset($extension->id)) {
            $hydrated->setId($extension->id);
        }

        if (isset($extension->extension)) {
            $hydrated->setExtension($extension->extension);
        }

        return $hydrated;
    }