/** * $this->invalidArgument(1, $param1, 'PositiveInteger', __FUNCTION__); * @param string|Type $expected der Type oder ein String der den Typ beschreibt * @cc-ignore */ protected function invalidArgument($num, $actual, $expected, $function) { $class = Code::getClass($this); $namespace = Code::getNamespace($class); $context = $class . '::' . $function . '()'; $expandType = function ($type) use($class, $namespace) { if (is_string($type)) { $type = Type::create($type); if ($type instanceof ObjectType) { $type->expandNamespace($namespace); } } return $type; }; if (is_array($expected)) { $composite = Type::create('Composite'); foreach ($expected as $type) { $composite->addComponent($expandType($type)); } $expected = $composite; } else { $expected = $expandType($expected); } return Exception::invalidArgument($num, $context, $actual, $expected); }
/** * @param string $name FQN Name der Function/Methode * @param GParameter[] $parameters * @param string|array $body ist body ein array wird jeder Eintrag als string und als Zeile des Bodys ausgewertet */ public function __construct($name = NULL, array $parameters = array(), $body = NULL) { parent::__construct(); if ($name != NULL) { $this->namespace = Code::getNamespace($name); $this->name = Code::getClassName($name); } foreach ($parameters as $parameter) { $this->addParameter($parameter); } if (is_array($body)) { $this->setBodyCode($body); } elseif ($body != NULL) { $this->setBody($body); } }
/** * Setzt den Namen der Klasse * * Namespace wird immer mitgesetzt! D. h. übergibt man hier nur den ShortName wird der Namespace auf NULL gesetzt * Wenn man nur den Namen der Klasse und nicht den Namespace wechseln will, muss man setClassName() nehmen * @param string FQN; */ public function setName($name) { if (mb_strpos($name, '\\') !== FALSE) { $this->setNamespace(Code::getNamespace($name)); $this->name = Code::getClassName($name); } else { $this->name = $name; $this->namespace = NULL; } return $this; }
public function testGetNamespace_root() { $this->assertEquals(NULL, Code::getNamespace('\\stdClass')); $this->assertEquals(NULL, Code::getNamespace('stdClass')); }