Example #1
0
 /**
  * @return ActionPreview
  */
 public static function create()
 {
     $retval = new self();
     if (\Phpcf\Helper::isAtty()) {
         // @todo eliminate OS-specific
         $cdiff = '/usr/bin/cdiff';
         if (is_executable($cdiff)) {
             $retval->setCdiffCmd($cdiff);
         }
     }
     return $retval;
 }
Example #2
0
 /**
  * @param array $ctx_rules
  * @param array $formatting_rules
  * @param \Phpcf\ExecStat $Stat
  */
 public final function __construct(array $ctx_rules, array $formatting_rules, \Phpcf\ExecStat $Stat)
 {
     \Phpcf\Helper::loadExtension('tokenizer');
     $this->initControls($formatting_rules);
     $this->FSM = new Fsm($ctx_rules);
     $this->FSM->setExecStat($Stat);
     $this->Stat = $Stat;
     $this->Stat->setCallback([$this, 'printAllContextMessages']);
     $this->init();
 }
Example #3
0
 /**
  * @param array $argv
  * @return \Phpcf\Options
  */
 private function parseParams(array &$argv)
 {
     $options = [];
     foreach ($argv as $k => $v) {
         \Phpcf\Helper::parseArg('debug', 'd', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('quiet', 'q', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('emacs', 'e', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('summary', 's', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('no-messages', 'n', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('pure-php', 'p', 1, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('lines', 0, 0, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('log', 0, 0, $options, $argv, $k, $v);
         \Phpcf\Helper::parseArg('style', 0, 0, $options, $argv, $k, $v);
     }
     $Retval = new \Phpcf\Options();
     if (!empty($options['quiet'])) {
         $Retval->setQuiet(true);
     }
     if (!empty($options['pure-php'])) {
         $Retval->usePure(true);
     }
     if (!empty($options['debug'])) {
         $Retval->setDebug(true);
     }
     if (!empty($options['emacs'])) {
         $Retval->setEmacsStyle(true);
     }
     if (!empty($options['summary'])) {
         $Retval->setSummary(true);
     }
     if (!empty($options['style'])) {
         $Retval->setCustomStyle($options['style']);
     }
     $argv = array_values($argv);
     return $Retval;
 }
Example #4
0
 private function initImplementation()
 {
     \Phpcf\Helper::loadExtension('tokenizer');
     $fsm_context_rules = (require __DIR__ . "/../styles/default/context-rules.php");
     $controls = (require __DIR__ . "/../styles/default/formatting-rules.php");
     $custom_style_dir = $this->Options->getCustomStyle();
     $custom_formatter_class = null;
     $use_pure = false;
     if (!empty($custom_style_dir)) {
         // check, which dir is given - relative, or absolute
         if (strpos($custom_style_dir, DIRECTORY_SEPARATOR) === false) {
             $custom_style_dir = __DIR__ . '/../styles/' . $custom_style_dir . '/';
         }
         if (!is_dir($custom_style_dir)) {
             throw new \RuntimeException("Given custom style dir '{$custom_style_dir}' is not a dir");
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "context-rules.php")) {
             require $file;
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "formatting-rules.php")) {
             require $file;
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "phpcf-class.php")) {
             require_once $file;
             $class_name = ucfirst(pathinfo($custom_style_dir, PATHINFO_FILENAME));
             $custom_formatter_class = "\\Phpcf\\Impl\\PHPCF_{$class_name}";
             if (!class_exists($custom_formatter_class, false)) {
                 throw new \InvalidArgumentException("Custom formatter class '{$custom_formatter_class}' not found in '{$file}'");
             } else {
                 if (!in_array(ltrim(self::IMPL_CLASS, '\\'), class_parents($custom_formatter_class, true))) {
                     throw new \InvalidArgumentException("Class '{$custom_formatter_class}' must be instanceof '" . self::IMPL_CLASS . "'");
                 }
             }
             $use_pure = true;
         }
     }
     $use_pure = $this->Options->getPureBehaviour() || $use_pure;
     if (!$use_pure) {
         try {
             \Phpcf\Helper::loadExtension('phpcf');
             if (function_exists('phpcf_get_version')) {
                 $version = phpcf_get_version();
                 if ($version !== PHPCF_VERSION && !$this->Options->isQuiet()) {
                     $error_string = "Extension use disabled, version mismatch: '" . PHPCF_VERSION . "' != '{$version}'";
                     trigger_error($error_string, E_USER_NOTICE);
                     $use_pure = true;
                 }
             } else {
                 // old version
                 $use_pure = true;
             }
         } catch (\Exception $Error) {
             $use_pure = true;
         }
     }
     if ($use_pure) {
         $formatter_class = $custom_formatter_class ? $custom_formatter_class : self::IMPL_CLASS;
         $this->Implementation = new $formatter_class($fsm_context_rules, $controls, new ExecStat());
     } else {
         $this->Implementation = new \Phpcf\Impl\Extension($fsm_context_rules, $controls);
     }
     if ($this->Options->isCyrillicFilterEnabled()) {
         $this->Implementation->setStringFilter(new \Phpcf\Filter\StringAscii(new \Phpcf\Filter\StringAsciiMapCyr()));
     }
 }