Esempio n. 1
0
<?php

defined('_JEXEC') || die('=;)');
/**
 * @package    EasyCreator
 * @subpackage Views
 * @author     Nikolai Plath
 * @author     Created on 09-Sep-2009
 * @license    GNU/GPL, see JROOT/LICENSE.php
 */
$sniffer = new EcrPearHelperCodesniffer();
if (false == $sniffer->checkEnv()) {
    echo 'Env check failed.. cannot continue :(';
    return;
}
$standard = JFactory::getApplication()->input->get('sniff_standard');
$standards = $sniffer->getStandards();
//-- @todo provide own standards ¿ JFolder::folders(JPATH_COMPONENT.DS.'helpers'.DS.'CodeSniffer');
$easyStandards = array();
$formats = array('full', 'xml', 'checkstyle', 'csv', 'emacs', 'source', 'summary');
ecrLoadMedia('php_file_tree');
$fileTree = drawFileTree($this->project);
?>

<div class="ecr_floatbox">
    <?php 
echo $fileTree;
?>
    <div onclick="sniffFolder();" class="btn block left">
        <i class="img32 icon32-nose"></i>
        <?php 
Esempio n. 2
0
 /**
  * Executes a 'sniff'.
  *
  * @return void
  */
 public function phpcs()
 {
     $input = JFactory::getApplication()->input;
     $path = $input->getPath('path');
     $file = $input->getPath('file');
     if ('' == $file) {
         if (false == JFolder::exists(JPATH_ROOT . DS . $path)) {
             $this->response->message = '<b style="color: red">' . jgettext('Folder not found') . '</b>';
             echo json_encode($this->response);
             return;
         }
         $fullPath = JPATH_ROOT . DS . $path;
     } else {
         $ext = JFile::getExt($file);
         $sniffExtensions = array('php', 'js');
         if (false == in_array($ext, $sniffExtensions)) {
             $this->response->message = '<b style="color: red">Sniffeable extensions:<br />' . implode(',', $sniffExtensions) . '</b>';
             echo json_encode($this->response);
             return;
         }
         $fullPath = JPATH_ROOT . DS . $path . DS . $file;
         if (false == JFile::exists($fullPath)) {
             $this->response->message = '<b style="color: red">' . jgettext('File not found') . '</b>';
             echo json_encode($this->response);
             return;
         }
     }
     $fullPath = str_replace('/', DS, $fullPath);
     ob_start();
     $sniffer = new EcrPearHelperCodesniffer();
     $standard = $input->get('sniff_standard');
     if ($standard) {
         $sniffer->setStandard($standard);
     }
     $format = $input->get('sniff_format');
     if ($format) {
         $sniffer->setFormat($format);
     }
     $verbose = $input->get('sniff_verbose');
     $sniffer->verboseLevel = $verbose == 'true' ? '-v' : '';
     $sniffs = $input->get('sniff_sniffs');
     if ($sniffs) {
         if (substr($sniffs, strlen($sniffs) - 1) == ',') {
             $sniffs = substr($sniffs, 0, strlen($sniffs) - 1);
         }
         $sniffer->sniffs = explode(',', $sniffs);
     }
     $results = $sniffer->sniffFile($fullPath);
     $this->response->message = ob_get_contents();
     ob_end_clean();
     $this->response->debug = htmlentities($results);
     $this->response->status = 1;
     if ($file && 'xml' == $format) {
         $xml = simplexml_load_string($results);
         $warnings = array();
         $errors = array();
         if ($xml) {
             if (isset($xml->file->error)) {
                 /* @var $error SimpleXMLElement */
                 foreach ($xml->file->error as $error) {
                     $line = (int) $error->attributes()->line;
                     if (false == isset($errors[$line])) {
                         $errors[$line] = array();
                     }
                     $errors[$line][] = htmlentities((string) $error . ' (' . (string) $error->attributes()->source . ')');
                 }
             }
             if (isset($xml->file->warnings)) {
                 foreach ($xml->file->warning as $error) {
                     $line = (int) $error->attributes()->line;
                     if (!isset($warnings[$line])) {
                         $warnings[$line] = array();
                     }
                     $warnings[$line][] = htmlentities((string) $error . ' (' . (string) $error->attributes()->source . ')');
                 }
             }
         }
         $highlight = '';
         $highlight .= '<pre>';
         $contents = file($fullPath);
         foreach ($contents as $i => $line) {
             $lNo = $i + 1;
             $msg = '';
             $class = '';
             if (isset($warnings[$lNo])) {
                 $class = 'warning';
                 $msg .= implode("\n", $warnings[$lNo]);
             }
             if (isset($errors[$lNo])) {
                 $class = 'error';
                 $msg .= implode("\n", $errors[$lNo]);
             }
             $highlight .= '<div class="' . $class . '">';
             $highlight .= str_pad($lNo, 4, ' ', STR_PAD_LEFT) . ' ' . htmlentities($line);
             if ($msg) {
                 $highlight .= '     <small>' . $msg . '</small>';
             }
             $highlight .= '</div>';
         }
         $highlight .= '</pre>';
         $this->response->message = $highlight . $this->response->message;
     }
     echo json_encode($this->response);
     jexit();
 }