/** * Computes the data used to render the history chart. * * @param ProjectEntity $project * * @return array */ private function computeHistoryChartDatasets(ProjectEntity $project) { $data = array(); foreach ($project->getAnalyses() as $analysis) { // We include in the chart just the analyses with valid results. if (!parent::isResultEmpty($analysis)) { $data[] = $analysis->getDependencyResults()->getScore(); } } $dataset = array('label' => 'Error number', 'fillColor' => $this->helper->generateColorForCss(self::$historyChartColor, Settings::CHART_FILL_OPACITY), 'strokeColor' => $this->helper->generateColorForCss(self::$historyChartColor, Settings::CHART_STROKE_OPACITY), 'highlightFill' => $this->helper->generateColorForCss(self::$historyChartColor, Settings::CHART_HIGHLIGHT_FILL_OPACITY), 'highlightStroke' => $this->helper->generateColorForCss(self::$historyChartColor, Settings::CHART_HIGHLIGHT_STROKE_OPACITY), 'data' => $data); return array($dataset); }
/** * Handles project creation action. * * @param Request $request * * @return Response */ public function addAction(Request $request) { $project = new Project(); $project->setUser($this->getUser()); // Create the form which manages the project creation. $form = $this->createForm(new ProjectType(), $project); // Handle user submitted data. $form->handleRequest($request); // Validate the form. if ($form->isValid()) { // If the data is valid, save the newly created project. $data = $form->getData(); // Set created and updated flags. $data->setCreated()->setUpdated(); $doctrine = $this->getDoctrine()->getManager(); $doctrine->persist($data); $doctrine->flush(); return $this->redirectToRoute('php_sanitizer_project_index'); } // Render the form. return $this->render('project/add.html.twig', array('form' => $form->createView())); }
/** * Removes a project's source code from the server. * * @param Project $project */ protected function removeProjectData(Project $project) { $this->fileSystem->remove($project->getFilepath()); }
/** * Computes the current status of the project. * * @param ProjectEntity $project * * @return boolean */ private function computeIsAnalyzed(ProjectEntity $project) { return $project->getAnalyzing(); }
/** * Ends the analysis process. * * @param Project $project */ protected function endAnalysis(Project $project) { // Remove the flag from the project. $project->setAnalyzing(false); $this->doctrine->getManager()->flush(); }
/** * Makes the preparations for the analysis process: unzips the source code of the project * into a temporary directory and returns its path. * * @param Project $project * * @return string * * @throws FileNotFoundException */ protected function prepare(Project $project) { $sourceFile = $project->getFilepath(); if (!is_file($sourceFile)) { throw new FileNotFoundException('The project source code was expected to still exist!'); } $projectDir = $this->createTempDirectory(); $this->unzip($sourceFile, $projectDir); return $projectDir; }
/** * Project setter. * * @param Project $project * * @return Analysis */ public function setProject(Project $project) { $project->addAnalysis($this); $this->project = $project; return $this; }