Esempio n. 1
0
 /**
  * Get the mapped issues for a Node.
  *
  * @param \Drupal\Core\Entity\EntityInterface
  *
  *
  * @return array
  *   An array containing all the entites of the mapped issues.
  */
 public function getIssuesByEntity(EntityInterface $entity)
 {
     $inids = array();
     foreach ($this->getIssuesByNid($entity) as $inid) {
         $inids[] = CheckstyleIssue::load($inid);
     }
     return $inids;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function file(SplFileInfo $file)
 {
     $issues = array();
     if ($this->shouldProcess($file)) {
         $fileReport = $this->analyzer->reporting->prepareFileReport($this->analyzer->processFile($file->getRealPath()));
         /** @var SplFileInfo $file */
         $this->codeparser->setFile($file);
         foreach ($fileReport['messages'] as $line => $lineErrors) {
             foreach ($lineErrors as $column => $colErrors) {
                 foreach ($colErrors as $error) {
                     $code = $this->renderSourceCode($this->codeparser->getAffectedCode($line), $line, $file->getRelativePathname(), $error['message']);
                     $data = ["line" => $line, "code" => $code, "message" => $error['message'], "relative_path" => $file->getRelativePathname(), "display_lines" => \Drupal::config('checkstyle.settings')->get('display_lines'), "issue_type" => $error['source']];
                     $issue = array_merge($data, $error);
                     $entity = CheckstyleIssue::create($issue);
                     $entity->save();
                     $issues[] = $entity;
                 }
             }
         }
         return $issues;
     }
 }
 /**
  * Displays add content links for available content types.
  *
  * Redirects to node/add/[type] if only one content type is available.
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *   A render array for a list of the node types that can be added; however,
  *   if there is only one node type defined for the site, the function
  *   will return a RedirectResponse to the node add page for that one node
  *   type.
  */
 public function result()
 {
     /*$build = array();
         $high = 3;
         $med = 5;
         $low = 123;
         $total = $high + $med + $low;
         $rows = array();
         $header = array(
           $this->t('Total'),
           $this->t('High Priority'),
           $this->t('Medium Priority'),
           $this->t('Low Priority')
         );
         $row = [
           ['data' => ['#markup' => $total]],
           ['data' => ['#markup' => $high]],
           ['data' => ['#markup' => $med]],
           ['data' => ['#markup' => $low]],
         ];
         $rows[] = $row;
         $build['summary'] = [
           '#theme' => 'table',
           '#rows' => $rows,
           '#header' => $header,
           '#caption' => $this->t('Summary')
         ];
     
     
         /** RESULTS */
     /*$results = $this->loadAnalysis("/Users/legovaer/Dropbox/Work/GitHub/drupal-code-grader/src/checkstyle-warnings.xml");
         foreach ($results as $category => $types) {
           foreach ($types as $typeName => $type) {
             //var_dump($issue);
             $data = [
               [
                 '#type' => 'details',
                 '#title' => $type['message'] . " (" . count($type["issues"]) . ")",
                 '#theme_wrappers' => array('details'),
               ],
     /*            "data" => [
                   '#type' => 'markup',
                   '#prefix' => '<em>',
                   '#suffix' => '</em>',
                   '#markup' => $this->t("This file ends with no newline character. It won't render properly on a terminal, and it's considered a bad practice. Add a simple line feed as the last character to fix it.")
               ]*/
     /*
             ];
             $build[strtolower($category)] = $data;
           }
         }
     /*    $build['resilts'] = array(
           '#type' => 'details',
           '#title' => $this->t('Text files should end with a newline character'),
           '#theme_wrappers' => array('details'),
         );
         $build['resilts']['edata'] = [
           '#type' => 'markup',
           '#prefix' => '<em>',
           '#suffix' => '</em>',
           '#markup' => $this->t("This file ends with no newline character. It won't render properly on a terminal, and it's considered a bad practice. Add a simple line feed as the last character to fix it.")
         ];*/
     //echo var_dump($this->loadAnalysis("/Users/legovaer/Dropbox/Work/GitHub/drupal-code-grader/src/checkstyle-warnings.xml"));
     /**
      * Display results
      */
     //* $results = $this->analyzeProject("scheduler");
     /*$results = $this->sortResultsByType($results);
         krumo($results);
     
         $data = array(
           '#type' => 'markup',
           '#markup' => 'Hello!',
         );*/
     /**
      * Add a CheckstyleIssue
      */
     $edit = array('severity' => "1", 'code' => '<html></html>', 'fixable' => TRUE, 'priority' => "WARNING", 'source' => 'Drupal.blabla', 'relative_path' => 'src/Entity/Form/CheckStyleIssueForm.php', 'line' => 13, 'issue_type' => 'Drupal.blabla.ietmas', 'field_source' => "test", 'field_message' => "test2", 'entity_type' => 'checkstyle_issue');
     $entity = CheckstyleIssue::create($edit);
     $entity->save();
     //krumo($entity);*/
     /**
      * Get entity_id by title
      */
     /*$result = db_select('node_revision__issue_type', 'it')
           ->fields('it', array('entity_id'))
           ->condition('it.issue_type_value', 'Drupal.blabla.ietms')
           ->orderBy('it.revision_id', 'DESC')
           ->range(0, 1)
           ->execute();
     
         krumo($result->fetchField());*/
     $data = array('#type' => 'markup', '#markup' => 'test');
     return $data;
 }