/**
  * Gives all the entities to be required in the compound interface
  * Also generates a unique alias for them
  *
  * @param EntityPackage $entity_package
  * @param PackageClass $package_class
  * @param array $checked list of checked packages to prevent recursion errors
  * @return UseStatement[]
  */
 private function recursivelyFindUseStatementsFor(EntityPackage $entity_package, PackageClass $package_class, array &$checked = [])
 {
     $result = [];
     $entity_package_name = $entity_package->getPackage()->getName();
     if (isset($checked[$entity_package_name])) {
         return $result;
     } else {
         $checked[$entity_package_name] = true;
     }
     foreach ($entity_package->getDependentPackages() as $name => $dependent_package) {
         /* @var $dependent_package EntityPackage */
         $use_statements = $this->recursivelyFindUseStatementsFor($dependent_package, $package_class, $checked);
         $result = array_merge($result, $use_statements);
     }
     $this->writeIfDebug('          - Scanning for traits in <info>' . $entity_package->getPackage()->getName() . '</info>.');
     $contents = $this->content_provider->getPackageContent($entity_package);
     $traits = $contents->getOptionalTraits($package_class->getShortName());
     foreach ($traits as $trait) {
         /* @var $trait \Hostnet\Component\EntityPlugin\OptionalPackageTrait */
         $requirement = $trait->getRequirement();
         if ($this->doesEntityExistInTree($entity_package, $requirement)) {
             $result[] = $trait;
             $this->writeIfDebug('            Injected <info>' . $trait->getName() . '</info> from <info>' . $entity_package->getPackage()->getName() . '</info>.');
         } else {
             $this->writeIfDebug('            Not injected <warn>' . $trait->getName() . '</warn> from <info>' . $entity_package->getPackage()->getName() . ' because ' . $requirement . ' is not found</info>.');
         }
     }
     $package_class = $contents->getClassOrTrait($package_class->getShortName());
     if ($package_class) {
         $result[] = $package_class;
         $this->writeIfDebug('            Found <info>' . $package_class->getName() . '</info> in <info>' . $entity_package->getPackage()->getName() . '</info>.');
     }
     return $result;
 }
 /**
  * @param EntityPackage $entity_package
  * @return PackageContent
  */
 public function getPackageContent(EntityPackage $entity_package)
 {
     if ($this->type == PackageContent::ENTITY) {
         return $entity_package->getEntityContent();
     } else {
         return $entity_package->getRepositoryContent();
     }
 }
 public function testGetRequires()
 {
     $package = new Package('hostnet/foo', 1.0, 1.0);
     $content = self::createMock('Hostnet\\Component\\EntityPlugin\\PackageContentInterface');
     $entity_package = new EntityPackage($package, $content, $content);
     $this->assertEquals([], $entity_package->getRequires());
     $link = new Link('hostnet/a', 'hostnet/foo');
     $package->setRequires([$link]);
     $this->assertSame([$link], $entity_package->getRequires());
 }