Hydrate a file object into a FileEntity object

@param stdClass $file
@return FileEntity
512735
public static function hydrate(stdClass $file)
    {
        $hydrated = new FileEntity();

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

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

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

        if (isset($file->scanned)) {
            $hydrated->setScanned($file->scanned);
        }

        if (isset($file->code)) {
            $hydrated->setCode($file->code);
        }

        return $hydrated;
    }
616226
public static function hydrate(stdClass $context)
    {
        $hydrated = new ContextEntity();

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

        if (isset($context->parts)) {
            $hydrated->setParts(PartHydrator::hydrateCollection($context->parts));
        }

        return $hydrated;
    }
276777
public function setFile(File $file)
    {
        $this->file = $file;

        if ($this->file) {
            $this->updatedAt = new \DateTime('now');
        }

        return $this;
    }
818854
public function make($file)
    {
        if ($file instanceof SymfonyUploadedFile) {
            return $this->createFromObject($file);
        }

        if (is_array($file)) {
            if (isset($file['base64']) && isset($file['name'])) {
                return $this->createFromBase64($file['name'], $file['base64']);
            }
            else {
                return $this->createFromArray($file);
            }
        }

        if (array_key_exists('scheme', parse_url($file))) {
            return $this->createFromUrl($file);
        }

        return $this->createFromString($file);
    }
706730
public function addFile(File $file): self
    {
        $directory = $this->getPath();
        $file->moveToDirectory($directory);

        return $this;
    }
821031
public function fileDownload($file)
    {
        $response = new SymfonyResponse();

        $response->headers->set('Content-Disposition', 
            $response->headers->makeDisposition(
                ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                $file
            )
        );

        return $response;
    }
112513
public static function hydrate(stdClass $source)
    {
        $hydrated = new SourceEntity();

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

        if (isset($source->line)) {
            $hydrated->setLine($source->line);
        }

        if (isset($source->start_line)) {
            $hydrated->setStartLine($source->start_line);
        }

        if (isset($source->end_line)) {
            $hydrated->setEndLine($source->end_line);
        }

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

        if (isset($source->parameter)) {
            $hydrated->setParameter($source->parameter);
        }

        if (isset($source->file)) {
            $hydrated->setFile(FileHydrator::hydrate($source->file));
        }

        if (isset($source->function)) {
            $hydrated->setFunction(CustomFunctionHydrator::hydrate($source->function));
        }

        if (isset($source->class)) {
            $hydrated->setClass(CustomClassHydrator::hydrate($source->class));
        }

        if (isset($source->start_column)) {
            $hydrated->setStartColumn($source->start_column);
        }

        if (isset($source->end_column)) {
            $hydrated->setEndColumn($source->end_column);
        }

        if (isset($source->type)) {
            $hydrated->setType(TypeHydrator::hydrate($source->type));
        }

        if (isset($source->taint)) {
            $hydrated->setTaint(TaintHydrator::hydrate($source->taint));
        }

        return $hydrated;
    }
990208
private function createDocument($file)
    {
        $d = new Document();
        $d->uniqueName = $this->getUniqueName();
        $d->originalName = $file->getClientOriginalName();
        $d->extension = strtolower($file->getClientOriginalExtension());
        $d->mimeType = $file->getClientMimeType();
        $d->filePath = sprintf('%s/%s.%s', $this->subfolder, $d->uniqueName, $d->extension);
        $d->storage_disk = Config::get('filesystems.default');
        $d->hash = md5_file($file->getRealPath());
        $d->realPath = $file->getRealPath();

        return $d;
    }
1216649
public static function hydrate(stdClass $concat)
    {
        $hydrated = new ConcatEntity();

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

        if (isset($concat->line)) {
            $hydrated->setLine($concat->line);
        }

        if (isset($concat->start_line)) {
            $hydrated->setStartLine($concat->start_line);
        }

        if (isset($concat->end_line)) {
            $hydrated->setEndLine($concat->end_line);
        }

        if (isset($concat->file)) {
            $hydrated->setFile(FileHydrator::hydrate($concat->file));
        }

        if (isset($concat->function)) {
            $hydrated->setFunction(CustomFunctionHydrator::hydrate($concat->function));
        }

        if (isset($concat->class)) {
            $hydrated->setClass(CustomClassHydrator::hydrate($concat->class));
        }

        if (isset($concat->start_column)) {
            $hydrated->setStartColumn($concat->start_column);
        }

        if (isset($concat->end_column)) {
            $hydrated->setEndColumn($concat->end_column);
        }

        if (isset($concat->taint)) {
            $hydrated->setTaint(TaintHydrator::hydrate($concat->taint));
        }

        return $hydrated;
    }
854226
public static function hydrate(stdClass $taint)
    {
        $hydrated = new TaintEntity();

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

        if (isset($taint->start_line)) {
            $hydrated->setStartLine($taint->start_line);
        }

        if (isset($taint->end_line)) {
            $hydrated->setEndLine($taint->end_line);
        }

        if (isset($taint->start_column)) {
            $hydrated->setStartColumn($taint->start_column);
        }

        if (isset($taint->end_column)) {
            $hydrated->setEndColumn($taint->end_column);
        }

        return $hydrated;
    }
882701
public static function hydrate(stdClass $summary)
    {
        $hydrated = new SummaryEntity();

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

        if (isset($summary->line)) {
            $hydrated->setLine($summary->line);
        }

        if (isset($summary->content)) {
            $hydrated->setContent($summary->content);
        }

        if (isset($summary->highlighted_content)) {
            $hydrated->setHighlightedContent($summary->highlighted_content);
        }

        if (isset($summary->file)) {
            $hydrated->setFile(FileHydrator::hydrate($summary->file));
        }

        if (isset($summary->function)) {
            $hydrated->setFunction(CustomFunctionHydrator::hydrate($summary->function));
        }

        if (isset($summary->class)) {
            $hydrated->setClass(CustomClassHydrator::hydrate($summary->class));
        }

        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;
    }
606829
public function setFile($file): self
    {
        $this->file = $file;

        if (is_string($file)) {
            $this->pathToFile = $file;
            $this->setFileName(pathinfo($file, PATHINFO_BASENAME));
            $this->mediaName = pathinfo($file, PATHINFO_FILENAME);

            return $this;
        }

        if ($file instanceof UploadedFile) {
            $this->pathToFile = $file->getPath().'/'.$file->getFilename();
            $this->setFileName($file->getClientOriginalName());
            $this->mediaName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);

            return $this;
        }

        if ($file instanceof SymfonyFile) {
            $this->pathToFile = $file->getPath().'/'.$file->getFilename();
            $this->setFileName(pathinfo($file->getFilename(), PATHINFO_BASENAME));
            $this->mediaName = pathinfo($file->getFilename(), PATHINFO_FILENAME);

            return $this;
        }

        throw UnknownType::create();
    }
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;
    }
1157222
public function setFile($file)
    {

        //Return false if file does not exists;
        if (!$this->isFile($file)) {
            return false;
        }
        //Get the file info
        $this->file = $file;
        $this->pathinfo[$file] = pathinfo($file);

        //Return an instance of the file object;
        return $this;
    }
1339597
public static function hydrate(stdClass $resource)
    {
        $hydrated = new ResourceEntity();

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

        if (isset($resource->title)) {
            $hydrated->setTitle($resource->title);
        }

        if (isset($resource->author)) {
            $hydrated->setAuthor($resource->author);
        }

        if (isset($resource->url)) {
            $hydrated->setUrl($resource->url);
        }

        if (isset($resource->published_at)) {
            $hydrated->setPublishedAt(new DateTime($resource->published_at));
        }

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

        return $hydrated;
    }
1268495
public static function createFromFile($file)
    {
        // If the file is not readable
        if (!is_readable($file)) {
            throw new InvalidArgumentException(
                sprintf(InvalidArgumentException::INVALID_FILE_STR, $file),
                InvalidArgumentException::INVALID_FILE
            );
        }

        return self::createFromString(file_get_contents($file));
    }