Skip to content

Commit 962d6e7

Browse files
author
dereuromark
committed
Move parsing to factory method.
1 parent 4c8ee0b commit 962d6e7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Annotation/AnnotationFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@ public static function create($tag, $type, $content, $index = null) {
2727
return null;
2828
}
2929

30+
/**
31+
* @param string $annotation (e.g. `@method \Foo\Bar myMethod($x)`)
32+
*
33+
* @return \IdeHelper\Annotation\AbstractAnnotation|null
34+
*/
35+
public static function createFromString($annotation) {
36+
preg_match('/(.+?) (.+?) (.+)/', $annotation, $matches);
37+
if (!$matches) {
38+
return null;
39+
}
40+
return static::create($matches[1], $matches[2], $matches[3]);
41+
}
42+
3043
}

src/Annotator/ModelAnnotator.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ protected function _table($path, $entityName, array $associations) {
8484
}
8585
// Make replacable via array structure
8686
foreach ($annotations as $key => $annotation) {
87-
preg_match('/(.+?) (.+?) (.+)/', $annotation, $matches);
88-
if (!$matches) {
89-
continue;
90-
}
91-
$annotation = AnnotationFactory::create($matches[1], $matches[2], $matches[3]);
87+
$annotation = AnnotationFactory::createFromString($annotation);
9288
if (!$annotation) {
9389
continue;
9490
}

0 commit comments

Comments
 (0)