/**
  * If type is callable object or in namespace then can render type hinting in setter
  * @todo refactor
  *
  * @return boolean
  */
 public function canAddTypeHinting()
 {
     if (class_exists($this->getProperty()->getTypeName())) {
         return true;
     }
     return Tools::isNamespaceValid($this->getProperty()->getType(), false);
 }
 /**
  * @param \HelloWordPl\SimpleEntityGeneratorBundle\Lib\MultilineCommentableInterface $element
  * @return string
  */
 protected function prepareMultilineCommentForElement(MultilineCommentableInterface $element)
 {
     if ($element->getMultilineComment()->isEmpty()) {
         return "";
     }
     $multilineCommentPrepared = [];
     $multilineCommentPrepared[] = "\n *";
     foreach ($element->getMultilineComment() as $row) {
         $multilineCommentPrepared[] = sprintf(" * %s", $row);
     }
     return Tools::implodeArrayToTemplate($multilineCommentPrepared);
 }
 /**
  * Return namespace without name - for rendering namespace in class
  *
  * @return string
  * @throws Exception
  */
 public function getNamespaceWithoutNameAndBackslashPrefix()
 {
     return Tools::removeBackslashPrefixFromNamespace(Tools::getNamespaceWithoutName($this->getNamespace()));
 }
 /**
  * @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;
 }
 /**
  * Append \Test\ part to namespace
  *
  * @param string $namespace
  * @return string
  * @throws Exception
  */
 protected function appendTestDirectory($namespace)
 {
     if (false == Tools::isNamespaceValid($namespace)) {
         throw new Exception(sprintf("Invalid namespace: %s", $namespace));
     }
     $namespace = Tools::removeBackslashPrefixFromNamespace($namespace);
     $namespaceParts = explode("\\", $namespace);
     $firstParts = array_slice($namespaceParts, 0, 1);
     $secondParts = array_slice($namespaceParts, 1, count($namespaceParts) - 1);
     $newNamespaceParts = [];
     $newNamespaceParts = array_merge($newNamespaceParts, $firstParts);
     $newNamespaceParts[] = "Tests";
     $newNamespaceParts = array_merge($newNamespaceParts, $secondParts);
     return "\\" . implode("\\", $newNamespaceParts);
 }
 public function testGetUpdatedItemSourceContentForTestClassManager()
 {
     $classManager = $this->preapareClassManager();
     $testClassManager = $classManager->getTestClass();
     $testClassNamespace = "\\Tests\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Dummies\\UserTestDummy";
     $existingFileContent = $this->getContentFile($this->getKernel()->getRootDir() . "/../src" . Tools::getDirectoryFromNamespace($testClassNamespace) . "/" . Tools::getNameFromNamespace($testClassNamespace) . ".php");
     $existingClassReflection = $this->getReflectionClass($testClassNamespace);
     $this->assertEquals($this->testClassContentBeforeUpdate, $existingFileContent);
     $updatedContent = $this->getStructureResolver()->getUpdatedItemSourceContent($existingFileContent, $testClassManager, $existingClassReflection);
     $this->assertEquals($this->testClassContentAfterUpdate, $updatedContent);
 }
 /**
  * @dataProvider dataForTestIsFirstCharBackslashWhenInvalidString
  * @expectedException \Exception
  */
 public function testIsFirstCharBackslashWhenInvalidString($value)
 {
     Tools::isFirstCharBackslash($value);
 }
 /**
  * @Assert\IsTrue(message = "Property has invalid validation constraint! Insert only constraint class with parameters eg. NotBlank() or Email(message = 'Invalid email')")
  */
 public function hasAllCallableConstraintIfHasAny()
 {
     if (false == $this->hasConstraints()) {
         return true;
     }
     foreach ($this->getConstraintAnnotationCollection() as $constraintAnnotation) {
         if (false == Tools::isCallableConstraintAnnotation($constraintAnnotation)) {
             return false;
         }
     }
     return true;
 }