protected function addElementsOfTypeToPackage(ProjectDescriptor $project, array $elements, $type)
    {
        /** @var DescriptorAbstract $element */
        foreach ($elements as $element) {
            $packageName = '';
            $packageTags = $element->getTags()->get('package');
            if ($packageTags instanceof Collection) {
                $packageTag = $packageTags->getIterator()->current();
                if ($packageTag instanceof TagDescriptor) {
                    $packageName = $packageTag->getDescription();
                }
            }

            $subpackageCollection = $element->getTags()->get('subpackage');
            if ($subpackageCollection instanceof Collection && $subpackageCollection->count() > 0) {
                $subpackageTag = $subpackageCollection->getIterator()->current();
                if ($subpackageTag instanceof TagDescriptor) {
                    $packageName .= '\\' . $subpackageTag->getDescription();
                }
            }

            // ensure consistency by trimming the slash prefix and then re-appending it.
            $packageIndexName = '\\' . ltrim($packageName, '\\');
            if (!isset($project->getIndexes()->packages[$packageIndexName])) {
                $this->createPackageDescriptorTree($project, $packageName);
            }

            /** @var PackageDescriptor $package */
            $package = $project->getIndexes()->packages[$packageIndexName];

            // replace textual representation with an object representation
            $element->setPackage($package);

            // add element to package
            $getter = 'get'.ucfirst($type);

            /** @var Collection $collection  */
            $collection = $package->$getter();
            $collection->add($element);
        }
    }
protected function addElementsOfTypeToPackage(ProjectDescriptor $project, array $elements, $type)
    {
        /** @var DescriptorAbstract $element */
        foreach ($elements as $element) {
            $packageName = '';
            $packageTags = $element->getTags()->get('package');
            if ($packageTags instanceof Collection) {
                $packageTag = $packageTags->getIterator()->current();
                if ($packageTag instanceof TagDescriptor) {
                    $packageName = $packageTag->getDescription();
                }
            }

            $subpackageCollection = $element->getTags()->get('subpackage');
            if ($subpackageCollection instanceof Collection && $subpackageCollection->count() > 0) {
                $subpackageTag = $subpackageCollection->getIterator()->current();
                if ($subpackageTag instanceof TagDescriptor) {
                    $packageName .= '\\' . $subpackageTag->getDescription();
                }
            }

            // ensure consistency by trimming the slash prefix and then re-appending it.
            $packageIndexName = '\\' . ltrim($packageName, '\\');
            if (!isset($project->getIndexes()->packages[$packageIndexName])) {
                $this->createPackageDescriptorTree($project, $packageName);
            }

            /** @var PackageDescriptor $package */
            $package = $project->getIndexes()->packages[$packageIndexName];

            // replace textual representation with an object representation
            $element->setPackage($package);

            // add element to package
            $getter = 'get'.ucfirst($type);

            /** @var Collection $collection  */
            $collection = $package->$getter();
            $collection->add($element);
        }
    }
protected function addElementsOfTypeToPackage ( ProjectDescriptor $ project , array $ elements , $ type ) { /** @var DescriptorAbstract $element */ foreach ( $ elements as $ element ) { $ packageName = '' ; $ packageTags = $ element -> getTags ( ) -> get ( 'package' ) ; if ( $ packageTags instanceof Collection ) { $ packageTag = $ packageTags -> getIterator ( ) -> current ( ) ; if ( $ packageTag instanceof TagDescriptor ) { $ packageName = $ packageTag -> getDescription ( ) ; } } $ subpackageCollection = $ element -> getTags ( ) -> get ( 'subpackage' ) ; if ( $ subpackageCollection instanceof Collection && $ subpackageCollection -> count ( ) > 0 ) { $ subpackageTag = $ subpackageCollection -> getIterator ( ) -> current ( ) ; if ( $ subpackageTag instanceof TagDescriptor ) { $ packageName .= '\\' . $ subpackageTag -> getDescription ( ) ; } } // ensure consistency by trimming the slash prefix and then re-appending it. $ packageIndexName = '\\' . ltrim ( $ packageName , '\\' ) ; if ( ! isset ( $ project -> getIndexes ( ) -> packages [ $ packageIndexName ] ) ) { $ this -> createPackageDescriptorTree ( $ project , $ packageName ) ; } /** @var PackageDescriptor $package */ $ package = $ project -> getIndexes ( ) -> packages [ $ packageIndexName ] ; // replace textual representation with an object representation $ element -> setPackage ( $ package ) ; // add element to package $ getter = 'get' . ucfirst ( $ type ) ; /** @var Collection $collection  */ $ collection = $ package -> $ getter ( ) ; $ collection -> add ( $ element ) ; } }
Adds the given elements of a specific type to their respective Package Descriptors.

This method will assign the given elements to the package as registered in the package field of that
element. If a package does not exist yet it will automatically be created.

@param ProjectDescriptor    $project
@param DescriptorAbstract[] $elements Series of elements to add to their respective package.
@param string               $type     Declares which field of the package will be populated with the given
series of elements. This name will be transformed to a getter which must exist. Out of performance
considerations will no effort be done to verify whether the provided type is valid.

@return void
Adds the given elements of a specific type to their respective Package Descriptors .