예제 #1
0
 /**
  * Prints all properties
  */
 public static function print_all()
 {
     echo '<pre>' . FWS_Printer::to_string(self::$accessor->get_all()) . '</pre>';
 }
예제 #2
0
 /**
  * Prints the given value and various other information
  * 
  * @param mixed $val the value to print
  */
 protected function debug($val)
 {
     $token = token_name($this->tokens[$this->pos][0]);
     if ($token == 'UNKNOWN') {
         $token = $this->tokens[$this->pos][1];
     }
     echo FWS_Printer::to_string(array('file' => $this->file, 'line' => $this->line, 'token' => $token, 'value' => $this->tokens[$this->pos][1], 'debugval' => $val));
 }
예제 #3
0
 /**
  * The string-representation of the type
  *
  * @return string the string
  */
 public function __toString()
 {
     if ($this->_type == self::OBJECT && $this->_class) {
         return (string) $this->_class;
     }
     if ($this->_type == self::TARRAY) {
         $str = 'array';
         if ($this->_value !== null) {
             $str .= '=' . FWS_Printer::to_string($this->_value, PHP_SAPI != 'cli', false);
         }
         return $str;
     }
     $str = $this->get_type_name($this->_type);
     if ($this->_value !== null) {
         $str .= '=' . FWS_Printer::to_string($this->_value, PHP_SAPI != 'cli', false);
     }
     return $str;
 }
예제 #4
0
 /**
  * Checks whether $arg is ok for $param, assumes that $param is a callable and $arg is known.
  *
  * @param PC_Obj_Location $loc the location
  * @param PC_Obj_MultiType $arg the argument
  */
 private function check_callable($loc, $arg)
 {
     $first = $arg->get_first();
     if ($first->get_type() == PC_Obj_Type::STRING) {
         if ($first->is_val_unknown()) {
             return;
         }
         $func = $this->env->get_types()->get_function($first->get_value());
         if ($func === null) {
             $this->report($loc, 'The function "' . $first->get_value() . '" does not exist!', PC_Obj_Error::E_S_FUNCTION_MISSING);
         }
     } else {
         if ($first->get_type() == PC_Obj_Type::TARRAY) {
             if ($first->is_val_unknown()) {
                 return;
             }
             $callable = $first->get_value();
             if (count($callable) != 2 || !$callable[0]->is_unknown() && $callable[0]->get_first()->get_type() != PC_Obj_Type::OBJECT || !$callable[1]->is_unknown() && $callable[1]->get_first()->get_type() != PC_Obj_Type::STRING) {
                 $this->report($loc, 'Invalid callable: ' . FWS_Printer::to_string($first) . '!', PC_Obj_Error::E_S_CALLABLE_INVALID);
             } else {
                 if ($callable[0]->is_unknown() || $callable[1]->is_unknown()) {
                     return;
                 }
                 $obj = $callable[0]->get_first();
                 $name = $callable[1]->get_first();
                 $classname = $obj->get_class();
                 $class = $this->env->get_types()->get_class($classname);
                 if (!$class) {
                     $this->report($loc, 'The class "#' . $classname . '#" does not exist!', PC_Obj_Error::E_S_CLASS_MISSING);
                 } else {
                     if (!$class->contains_method($name->get_value())) {
                         $this->report($loc, 'The method "' . $name->get_value() . '" does not exist in the class "#' . $classname . '#"!', PC_Obj_Error::E_S_METHOD_MISSING);
                     }
                 }
             }
         } else {
             if ($first->get_type() != PC_Obj_Type::TCALLABLE) {
                 $this->report($loc, 'Invalid callable: ' . FWS_Printer::to_string($first) . '!', PC_Obj_Error::E_S_CALLABLE_INVALID);
             }
         }
     }
 }
예제 #5
0
    public function test_throws()
    {
        $code = '<?php
class Exception {}

abstract class A {
	/**
	 * @throws Exception
	 */
	public abstract function foo();
}

class B extends A {
	public function foo() {
		throw new Exception();
	}
}

/**
 * @throws Exception always
 */
function a() {
}

/**
 * @throws A
 * @throws B
 */
function b() {
	throw new B();
	throw new Exception();
	throw 1;
}
?>';
        list($functions, $classes, , , $errors) = $this->analyze($code);
        $func = $functions['a'];
        self::assert_equals('a', $func->get_name());
        self::assert_equals(FWS_Printer::to_string(array('Exception' => 'self')), FWS_Printer::to_string($func->get_throws()));
        $func = $functions['b'];
        self::assert_equals('b', $func->get_name());
        self::assert_equals(FWS_Printer::to_string(array('A' => 'self', 'B' => 'self')), FWS_Printer::to_string($func->get_throws()));
        self::assert_equals(4, count($errors));
        $error = $errors[0];
        self::assert_equals(PC_Obj_Error::E_S_DOC_WITHOUT_THROW, $error->get_type());
        self::assert_regex('/The function\\/method "a" throws "Exception" according to PHPDoc, but does not throw it/', $error->get_msg());
        $error = $errors[1];
        self::assert_equals(PC_Obj_Error::E_S_DOC_WITHOUT_THROW, $error->get_type());
        self::assert_regex('/The function\\/method "b" throws "A" according to PHPDoc, but does not throw it/', $error->get_msg());
        $error = $errors[2];
        self::assert_equals(PC_Obj_Error::E_S_THROW_NOT_IN_DOC, $error->get_type());
        self::assert_regex('/The function\\/method "b" does not throw "Exception" according to PHPDoc, but throws it/', $error->get_msg());
        $error = $errors[3];
        self::assert_equals(PC_Obj_Error::E_S_THROW_INVALID, $error->get_type());
        self::assert_regex('/The function\\/method "b" throws a non-object \\(integer=1\\)/', $error->get_msg());
    }