/**
  * @param ReflectionClass $reflectionClass
  * @return type
  */
 protected function getNewPropertyPosition(ReflectionClass $reflectionClass)
 {
     $constructor = $reflectionClass->getConstructor();
     if ($constructor instanceof ReflectionMethod) {
         $commentParts = Tools::explodeTemplateStringToArray($constructor->getDocComment());
         return $constructor->getStartLine() - count($commentParts) - 1;
     }
     $methods = $reflectionClass->getMethods();
     if (count($methods) > 0) {
         $firstMethod = reset($methods);
         if ($firstMethod instanceof ReflectionMethod) {
             return $firstMethod->getStartLine() - 1;
         }
     }
     return $reflectionClass->getEndLine() - 1;
 }
 /**
  * Update source file with rendered elements
  *
  * @param string $content
  * @param integer $startPosition
  * @param array $renderedElements
  * @return string
  */
 protected function updateSourceWithElements($content, $startPosition = 0, array $renderedElements = [])
 {
     $source = Tools::explodeTemplateStringToArray($content);
     foreach ($renderedElements as $renderedElement) {
         $this->putElementIntoSource($source, $startPosition, $renderedElement);
     }
     return Tools::implodeArrayToTemplate($source);
 }
 public function testExplodeTemplateStringToArray()
 {
     $this->assertEquals(3, count(Tools::explodeTemplateStringToArray("foo\nbar\n")));
     $this->assertEquals(2, count(Tools::explodeTemplateStringToArray("foo\n")));
     $this->assertEquals(1, count(Tools::explodeTemplateStringToArray("foo")));
 }