/** * @param Stmt $classStmt * @param $namespace * @param $source * @return Element\ClassModel */ public function parse(Stmt $classStmt, $namespace, $source) { $attrs = $classStmt->getAttributes(); $class = $this->classFactory->create($classStmt->name); $class->setNamespace($namespace); $class->setSource($source, $attrs['startLine'], 0); // annotation $this->commentsParser->parse($attrs, $class); // property $properties = array_filter($classStmt->stmts, function ($stmt) { return $this->propertyParser->match($stmt); }); array_map(function (Stmt $propertiesStmt) use($class) { $prop = $this->propertyParser->parse($propertiesStmt, $class); $this->propertyAnnotationParser->parse($propertiesStmt, $prop, $class); $varAnnotations = $prop->annotations->withName('var'); if (!$varAnnotations->isEmpty()) { /** @var Element\Annotation $var */ $var = $varAnnotations->first(); $prop->setAccessModifier($var->parameters); } }, $properties); // method $methods = array_filter($classStmt->stmts, function ($stmt) { return $this->methodParser->match($stmt); }); array_map(function ($methodStmt) use($class) { $this->methodParser->parse($methodStmt, $class); }, $methods); return $class; }
/** * @test */ public function parseNormal() { $stmts = (include __DIR__ . '/../fixtures/1/Model/Product.php.property_base.cache'); $property = $this->parser->parse($stmts, $this->class); $this->assertThat($property, $this->isInstanceOf(Property::class)); $this->assertThat($property->name, $this->equalTo('updatedAt')); $this->assertThat($property->getAccessModifier(), $this->equalTo('public')); }