/**
  * Will create a file with the altered class definition as it's content
  *
  * @param string                                                 $targetFileName      The intended name of the
  *                                                                                    new file
  * @param \TechDivision\PBC\Entities\Definitions\ClassDefinition $structureDefinition The definition of the
  *                                                                                    structure we will alter
  *
  * @return bool
  */
 private function createFileFromClassDefinition($targetFileName, ClassDefinition $structureDefinition)
 {
     $res = fopen($this->createFilePath($structureDefinition->getQualifiedName()), 'w+');
     // Append all configured filters
     $this->appendFilter($res, $structureDefinition);
     $tmp = fwrite($res, file_get_contents($structureDefinition->getPath(), time()));
     // Did we write something?
     if ($tmp > 0) {
         fclose($res);
         return true;
     } else {
         // Delete the empty file stub we made
         unlink($this->createFilePath($structureDefinition->getQualifiedName()), $res);
         fclose($res);
         return false;
     }
 }
 /**
  * This method will add all assertions any ancestral structures (parent classes, implemented interfaces) might have
  * to the passed class definition.
  *
  * @param \TechDivision\PBC\Entities\Definitions\ClassDefinition $classDefinition The class definition we have to
  *                                                                                add the assertions to
  *
  * @return null
  */
 protected function addAncestralAssertions(ClassDefinition $classDefinition)
 {
     $dependencies = $classDefinition->getDependencies();
     foreach ($dependencies as $dependency) {
         // freshly set the dependency definition to avoid side effects
         $dependencyDefinition = null;
         $fileEntry = $this->structureMap->getEntry($dependency);
         if (!$fileEntry instanceof Structure) {
             // Continue, don't fail as we might have dependencies which are not under PBC surveillance
             continue;
         }
         // Get the needed parser
         $structureParserFactory = new StructureParserFactory();
         $parser = $structureParserFactory->getInstance($fileEntry->getType(), $fileEntry->getPath(), $this->config, $this->structureMap, $this->structureDefinitionHierarchy);
         // Get the definition
         $dependencyDefinition = $parser->getDefinition($dependency, true);
         // Only classes and traits have invariants
         if ($fileEntry->getType() === 'class') {
             $classDefinition->ancestralInvariants = $dependencyDefinition->getInvariants(true);
         }
         // Finally add the dependency definition to our structure definition hierarchy to avoid
         // redundant parsing
         $this->structureDefinitionHierarchy->insert($dependencyDefinition);
     }
 }