public function __construct(Clazz $class, Method $method, $declaringClass = null) { $this->class = $class; $this->method = $method; $this->name = strtolower($method->getName()); if ($class->getName() === $declaringClass) { $declaringClass = null; } $this->declaringClass = $declaringClass; }
public function __construct(InterfaceC $interface, Method $method, $declaringInterface = null) { $this->interface = $interface; $this->method = $method; $this->name = strtolower($method->getName()); if ($interface->getName() === $declaringInterface) { $declaringInterface = null; } $this->declaringInterface = $declaringInterface; }
public function testDocTypesOfMethods() { $this->packageVersion->addContainer($foo = new Clazz('Foo')); $foo->addMethod($method = new Method('foo')); $method->setReturnDocType('self'); $method->setParamDocType(0, 'string'); $this->persister->persist($this->packageVersion); $reloadedFoo = $this->em->createQuery('SELECT c FROM Scrutinizer\\PhpAnalyzer\\Model\\Clazz c WHERE c.name = :name')->setParameter('name', 'Foo')->getSingleResult(); $reloadedMethod = $reloadedFoo->getMethod('foo'); $this->assertEquals(array('param_0' => 'string', 'return' => 'self'), $reloadedMethod->getDocTypes()); }
public function addMethod(Method $method, $declaringInterface = null) { $interfaceMethod = new InterfaceMethod($this, $method, $declaringInterface); $this->methods->set(strtolower($method->getName()), $interfaceMethod); }
public function addMethod(Method $method, $declaringClass = null) { $classMethod = new ClassMethod($this, $method, $declaringClass); $this->methods->set(strtolower($method->getName()), $classMethod); }
private function scanMethod(\PHPParser_Node_Stmt_ClassMethod $stmt, MethodContainer $class) { $method = new Method($stmt->name); $method->setAstNode($stmt); $method->setReturnByRef($stmt->byRef); // convert PHPParser modifier to our modifier $modifier = 0; if (\PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT === ($stmt->type & \PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT)) { $modifier |= Method::MODIFIER_ABSTRACT; } if (\PHPParser_Node_Stmt_Class::MODIFIER_FINAL === ($stmt->type & \PHPParser_Node_Stmt_Class::MODIFIER_FINAL)) { $modifier |= Method::MODIFIER_FINAL; } if (\PHPParser_Node_Stmt_Class::MODIFIER_STATIC === ($stmt->type & \PHPParser_Node_Stmt_Class::MODIFIER_STATIC)) { $modifier |= Method::MODIFIER_STATIC; } // All interface methods are automatically abstract without being declared as such. if ($class instanceof InterfaceC) { $modifier |= Method::MODIFIER_ABSTRACT; } $method->setModifier($modifier); $method->setVisibility(\PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE === ($stmt->type & \PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE) ? Method::VISIBILITY_PRIVATE : (\PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED === ($stmt->type & \PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED) ? Method::VISIBILITY_PROTECTED : Method::VISIBILITY_PUBLIC)); foreach ($this->paramParser->parse($stmt->params, 'Scrutinizer\\PhpAnalyzer\\Model\\MethodParameter') as $param) { $method->addParameter($param); } foreach ($stmt->params as $i => $param) { if (null !== ($docType = $this->commentParser->getTypeFromParamAnnotation($param, $param->name, true))) { $method->setParamDocType($i, $docType); } } if (null !== ($returnDocType = $this->commentParser->getTypeFromReturnAnnotation($stmt, true))) { $method->setReturnDocType($returnDocType); } $class->addMethod($method); }
/** * @group foreach */ public function testForeach3() { $this->registry->registerClass($foo = new Clazz('Foo')); $foo->setTypeRegistry($this->registry); $foo->addImplementedInterface('Iterator'); $foo->addMethod($current = new Method('current')); $current->setReturnType($this->registry->getClassOrCreate('Bar')); $this->assuming('y', 'object<Foo>'); $this->inMethod('$x = $i = null; foreach ($y as $i => $x);'); $this->verify('x', $this->createNullableType('object<Bar>')); $this->verify('i', $this->createNullableType('integer|string')); }
private function insertMethod(Method $method, $packageVersionId) { $this->methodStmt->bindValue(1, $this->phpType->convertToDatabaseValue($method->getReturnType(), $this->platform)); $this->methodStmt->bindValue(2, $method->getName()); $this->methodStmt->bindValue(3, $method->isReturnByRef() ? 1 : 0, \PDO::PARAM_INT); $this->methodStmt->bindValue(4, $method->getModifier(), \PDO::PARAM_INT); $this->methodStmt->bindValue(5, $method->getVisibility(), \PDO::PARAM_INT); $this->methodStmt->bindValue(6, $packageVersionId, \PDO::PARAM_INT); $this->methodStmt->bindValue(7, $method->hasVariableParameters() ? 1 : 0, \PDO::PARAM_INT); $this->methodStmt->bindValue(8, json_encode($method->getDocTypes()), \PDO::PARAM_STR); $this->methodStmt->execute(); $this->methodIdRef->setValue($method, $methodId = $this->con->lastInsertId()); foreach ($method->getParameters() as $param) { $this->paramPersister->persist($param, $method); } foreach ($method->getInCallSites() as $callSite) { $this->callSitePersister->persist($callSite); } foreach ($method->getOutCallSites() as $callSite) { $this->callSitePersister->persist($callSite); } return $methodId; }