private function fixLine(Line $line) { $content = $line->getContent(); preg_match_all('/ \\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $content, $matches); if (isset($matches[0][0])) { $line->setContent(str_replace($matches[0][0], '', $content)); } }
/** * Fix scalar types. * * We must be super careful not to modify parts of words. * * @param Line $line * @param string $tag */ private function fixScalars(Line $line, $tag) { $content = $line->getContent(); $tagSplit = preg_split('/\\s*\\@' . $tag . '\\s*/', $content); $spaceSplit = preg_split('/\\s/', $tagSplit[1]); $usefulContent = $spaceSplit[0]; if (strpos($usefulContent, '|') !== false) { $newContent = implode('|', self::normalizeTypes(explode('|', $usefulContent))); } else { $newContent = self::normalizeType($usefulContent); } if ($newContent !== $usefulContent) { // limiting to 1 replacement to prevent errors like // "integer $integer" being converted to "int $int" // when they should be converted to "int $integer" $line->setContent(preg_replace('/' . preg_quote($usefulContent) . '/', $newContent, $content, 1)); } }
public function testSetContent() { $line = new Line(" * @param \$foo Hi!\n"); $this->assertSame(" * @param \$foo Hi!\n", $line->getContent()); $line->addBlank(); $this->assertSame(" * @param \$foo Hi!\n *\n", $line->getContent()); $line->setContent(" * test\n"); $this->assertSame(" * test\n", $line->getContent()); $line->remove(); $this->assertSame('', $line->getContent()); }
/** * @dataProvider provideTypesCases */ public function testTypes($expected, $new, $input, $output) { $line = new Line($input); $tag = new Annotation(array($line)); $this->assertSame($expected, $tag->getTypes()); $tag->setTypes($new); $this->assertSame($new, $tag->getTypes()); $this->assertSame($output, $line->getContent()); }