Exakat\Data\Composer::getComposerTraits PHP Method

getComposerTraits() public method

public getComposerTraits ( $vendor = null )
    public function getComposerTraits($vendor = null)
    {
        // global namespace is stored with 'global' keyword, so we remove it.
        $query = "SELECT CASE namespace WHEN 'global' THEN traitname ELSE namespace || '\\' || traitname END AS traitname FROM namespaces \nJOIN traits ON traits.namespace_id = namespaces.id";
        if ($vendor !== null) {
            list($vendor, $component) = explode('/', $vendor);
            $query .= " WHERE vendor = '{$vendor}' and component = '{$component}'";
        }
        $res = $this->sqlite->query($query);
        $return = array();
        while ($row = $res->fetchArray(\SQLITE3_ASSOC)) {
            $return[] = strtolower($row['traitname']);
        }
        return $return;
    }

Usage Example

Example #1
0
 public function analyze()
 {
     $data = new Composer();
     $packagistNamespaces = $data->getComposerNamespaces();
     $packagistNamespacesFullNS = $this->makeFullNSPath($packagistNamespaces);
     $packagistClasses = $data->getComposerClasses();
     $packagistClassesFullNS = $this->makeFullNSPath($packagistClasses);
     // Chunks is made to shorten the queries
     $packagistClassesFullNSChunks = array_chunk($packagistClassesFullNS, 5000);
     $packagistInterfaces = $data->getComposerInterfaces();
     $packagistInterfacesFullNs = $this->makeFullNSPath($packagistInterfaces);
     ////////////////////////////////////////////////
     // Use
     // namespaces in Composer
     $this->atomIs('Use')->outIs('USE')->is('originpath', $packagistNamespacesFullNS);
     $this->prepareQuery();
     // classes in Composer
     foreach ($packagistClassesFullNSChunks as $id => $p) {
         $this->atomIs('Use')->outIs('USE')->is('originpath', $p);
         $this->prepareQuery();
     }
     // interfaces in Composer
     $this->atomIs('Use')->outIs('USE')->is('originpath', $packagistInterfaces);
     $this->prepareQuery();
     // traits in Composer
     $packagistTraits = $data->getComposerTraits();
     $this->atomIs('Use')->outIs('USE')->is('originpath', $packagistTraits);
     $this->prepareQuery();
     ////////////////////////////////////////////////
     // Classes extends or implements
     // Classes in Composer
     foreach ($packagistClassesFullNSChunks as $id => $p) {
         $this->atomIs('Class')->outIs(array('IMPLEMENTS', 'EXTENDS'))->fullnspathIs($p);
         $this->prepareQuery();
     }
     $this->atomIs('Class')->outIs(array('IMPLEMENTS', 'EXTENDS'))->fullnspathIs($packagistInterfacesFullNs);
     $this->prepareQuery();
     ////////////////////////////////////////////////
     // Instanceof
     // Classes or interfaces in Composer
     foreach ($packagistClassesFullNSChunks as $id => $p) {
         $this->atomIs('Instanceof')->outIs('CLASS')->atomIs(array('Nsname', 'Identifier'))->fullnspathIs($p);
         $this->prepareQuery();
     }
     $this->atomIs('Instanceof')->outIs('CLASS')->atomIs(array('Nsname', 'Identifier'))->fullnspathIs($packagistInterfacesFullNs);
     $this->prepareQuery();
 }