Method extract if a variable is required
@param $doc
@return null|string
976894
public static function checkIsRequired($doc)
    {
        $required = false;
        if (false !== preg_match('/@required/', $doc, $matches)) {
            $required = (bool)count($matches);
        }
        return $required;
    }
96135
protected function extractPackageFromDocBlock($docBlock)
    {
        $packageTags = $docBlock ? $docBlock->getTagsByName('package') : null;
        if (! $packageTags) {
            return null;
        }

        /** @var DocBlock\Tag $tag */
        $tag = reset($packageTags);

        return trim($tag->getContent());
    }
1259941
function getPath(\DOMDocument $document)
    {
        $name = $document->documentElement->localName;
        if (empty($this->version)) {
            $this->loadVersion($document);
        }
        $path = $this->getFullPath($name);

        return $path;
    }
1261702
public static function extractShortText(DOMDocument $document)
    {
        $result = null;
        // try to extract first paragraph/tag
        if ($section = $document->documentElement->firstChild) {
            $textDom = $section->firstChild;

            if ($textDom && $textDom->hasChildNodes()) {
                $result = $textDom->firstChild->textContent;
            } elseif ($textDom) {
                $result = $textDom->textContent;
            }
        }

        if ($result === null) {
            $result = $document->documentElement->textContent;
        }

        // In case of newlines, extract first line. Also limit size to 255 which is maxsize on sql impl.
        $lines = preg_split('/\r\n|\n|\r/', trim($result), -1, PREG_SPLIT_NO_EMPTY);

        return empty($lines) ? '' : trim(mb_substr($lines[0], 0, 255));
    }
986621
protected function _inferFieldTypes($docs)
    {
        $fieldTypes = [];
        foreach ($docs as $doc) {
            foreach ($doc as $field => $value) {
                $fieldTypes[$field][gettype($value)] = 1;
            }
        }

        $r = [];
        foreach ($fieldTypes as $field => $types) {
            unset($types['NULL']);
            if (isset($types['object'])) {
                $r[$field] = 'objectid';
            } else {
                if (count($types) !== 1) {
                    ksort($types);
                }
                $r[$field] = implode('|', array_keys($types));
            }
        }

        return $r;
    }
1044796
public static function document($doc)
    {
        $type = 1;
        $valid = self::cpf($doc);
        if ($valid == false) {
            $type = 2;
            $valid = self::cnpj($doc);
        }
        if ($valid == false) {
            return false;
        }
        return ['type' => $type, 'valid' => $valid];
    }
800955
protected function extractContract($contact)
    {
        foreach ($contact->documents as $document) {
            if ($document->type === 'contract') {
                $document->scenario = $this->scenario;

                return $document;
            }
        }

        return null;
    }
546552
public function get($id)
    {
        $result = $this->query('+id:'.$id);

        if ($result->getNumFound() > 0) {
            $docs = $result->getDocs();

            return $docs[0];
        }

        return null;
    }
428800
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
    {
        $element = parent::getDOM($doc, $majorVersion, $minorVersion);
        foreach ($this->_entry as $entry) {
            $element->appendChild($entry->getDOM($element->ownerDocument));
        }
        return $element;
    }
83417
private function __extractDocString($DocComment, $lines = null, $parse_tags = false)
    {
        $split = preg_split("/\r\n|\n|\r/", $DocComment);

        //clean up: removes useless chars like new-lines, tabs and *
        $_tmp = array();
        $_l=1;
        foreach ($split as $id => $row) {
            $_row = trim($row, "* /\n\t\r");
            if (!empty($_row) AND $_row[0]!='@') {
                $_tmp[$_l] = $_row;
                $_l++;
            }
        }           

        if (!empty($lines)) {
            if (is_numeric($lines)) {
                if (!isset($_tmp[ $lines ])) return '';
                $_tmp = array( $_tmp[ $lines ] );
            } elseif (is_array($lines)) {
                if (!empty($lines[1]))
                    $_tmp = array_slice($_tmp, array_search( $_tmp[ $lines[0] ], $_tmp)-1, $lines[1]);
                else
                    $_tmp = array_slice($_tmp, array_search( $_tmp[ $lines[0] ], $_tmp)-1 );
            }
        }

        return trim(implode("\n",$_tmp));
    }
27202
private static function getExtractorClosure($object)
    {
        if (!isset(self::$extractorClosure)) {
            self::$extractorClosure = function($object) {
                return get_object_vars($object);
            };
        }

        $class = get_class($object);

        if (!isset(self::$extractorClosureCache[$class])) {
            self::$extractorClosureCache[$class] = \Closure::bind(self::$extractorClosure, null, $class);
        }

        return self::$extractorClosureCache[$class];
    }
131234
function extractJSONPath(doc, expr) {
  // typeof null is 'object' hence the explicit check here
  if (typeof doc !== 'object' || doc === null) {
    return '';
  }

  let results;

  try {
    results = jsonpath.query(doc, expr);
  } catch (queryErr) {
    debug(queryErr);
  }

  if (!results) {
    return '';
  }

  if (results.length > 1) {
    return results[randomInt(0, results.length - 1)];
  } else {
    return results[0];
  }
}
529638
public function getFieldValue(object $document, string $field)
    {
        if ($document instanceof GhostObjectInterface && $field !== $this->identifier && ! $document->isProxyInitialized()) {
            $document->initializeProxy();
        }

        return $this->reflFields[$field]->getValue($document);
    }
124813
public function extract($value)
    {
        if ($this->nullable && $value === null) {
            return null;
        }
        settype($value, $this->extractToType);
        return $value;
    }
257260
public function extract($rules)
    {
        /** @var \DOMElement $node */
        $node = $this->_node;

        $data = [];
        foreach ($rules as $name => $rule) {
            if ($rule[0] === '@') {
                $data[$name] = $node->getAttribute(substr($rule, 1));
            } elseif ($rule === 'text()') {
                $data[$name] = $node->textContent;
            } elseif ($rule === 'html()') {
                $data[$name] = $node->ownerDocument->saveHTML($node);
            } elseif ($rule === 'path()') {
                $data[$name] = $node->getNodePath();
            } elseif (($pos = strpos($rule, '@')) === false) {
                $nodes = $this->_document->getQuery()->css($rule, $node);
                $data[$name] = $nodes->length ? $nodes->item(0)->textContent : null;
            } else {
                $nodes = $this->_document->getQuery()->css(substr($rule, 0, $pos), $node);
                $data[$name] = $nodes->length ? $nodes->item(0)->getAttribute(substr($rule, $pos + 1)) : null;
            }
        }

        return $data;
    }
1308591
private function parseTranslationFromDocComment($docComment)
    {
        if (empty($docComment)) {
            return null;
        }

        $parts = explode("\n", $docComment);

        if (!isset($parts[1])) {
            return null;
        }

        $translation = preg_replace('/\*\s*/', '', trim($parts[1]));

        if (0 === strpos($translation, '@')) {
            return null;
        }

        return $translation;
    }
1206005
private function extract($handler)
    {
        if (is_array($handler)) {
            return $this->fromClassMethodArray($handler);
        }
        if (strpos($handler, self::CHAR_AT) !== false) {
            return $this->fromAtNotation($handler);
        }
        if (strpos($handler, self::CHAR_DOT) !== false) {
            return $this->fromDotNotation($handler);
        }
        return $this->fromClassName($handler);
    }