@param string $phpDoc
@param string $class
@param string $name

@throws \Exception
@throws \InvalidArgumentException
164825
private function parsePhpDoc(string $phpDoc, string $class, string $name = null)
    {
        $phpDoc = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $phpDoc);
        $phpDoc = ltrim($phpDoc, "\r\n");

        $split = preg_split("/(\n@)/isU", $phpDoc, -1, PREG_SPLIT_DELIM_CAPTURE);

        if (!isset($split[0][0])) {
            throw new \Exception(sprintf("Empty PhpDoc for '%s::%s'", $class, $name));
        }

        if ($split[0][0] != '@') {
            $comments = explode("\n", array_shift($split));

            $this->add(new Comment(isset($comments[0]) ? array_shift($comments) : null), Definition::COMMENT);

            $commentLong = isset($comments[0]) ? trim(implode($comments, "\n"), "\n") : null;
            if ($commentLong) {
                $this->add(new CommentLong($commentLong), Definition::COMMENT_LONG);
            }
        } else {
            $split[0] = substr($split[0], 1);
        }

        foreach ($split as $content) {
            if ($content == '@') {
                continue;
            }

            // clean up variables
            $tempString = str_replace('  ', '-', $content);
            while ($content != $tempString) {
                $tempString = $content;
                $content = str_replace('  ', ' ', $content);
            }

            $explode = explode(' ', trim(str_replace("\t", '  ', $content)));

            $paramType = array_shift($explode);
            if ($paramType == '@') {
                continue;
            }

            switch ($paramType) {
                case Definition::PARAM:
                    $this->add(new Param($explode), $paramType, true);
                    break;

                case Definition::RETURNS:
                    $this->add(new ReturnType($explode), $paramType);
                    break;

                case Definition::THROWS:
                    $this->add(new Throws($explode), $paramType, true);
                    break;

                case Definition::RESPONSE:
                    $this->add(new Response($explode), $paramType, true);
                    break;

                case Definition::EXAMPLE:
                    $this->add(new Example($explode), $paramType, true);
                    break;

                case Definition::HEADER:
                    $this->add(new Header($explode), $paramType, true);
                    break;

                case Definition::AUTH:
                    $this->add(new Auth(implode(' ', $explode)), $paramType);
                    break;

                case Definition::HTTP_METHOD:
                    $this->add(new HttpMethod(implode(' ', $explode)), $paramType);
                    break;

                default:
                    throw new \InvalidArgumentException(
                        sprintf("Invalid param type '%s' on '%s::%s'", $paramType, $class, $name)
                    );
            }
        }

        if (is_null($this->getDefinition(Definition::RESPONSE)) &&
            !is_null($this->getDefinition(Definition::RETURNS))
        ) {
            $response = new Response();
            /* @noinspection PhpParamsInspection */
            $response->fromReturn($this->getDefinition(Definition::RETURNS));

            $this->add($response, Definition::RESPONSE, true);
        }
    }
929367
public function inlineAttachment($name, $content)
    {
        if (!is_string($content) && (!is_resource($content) || get_resource_type($content) != 'stream')) {
            throw new Exception\InvalidArgumentException(
                sprintf("Attachment content must be either string or stream, %s passed")
            );
        }
        
        $this->attachments[$name] = [
            'content' => $content,
            'inline'  => true
        ];
    }
232318
protected function assertCorrectDocBlockParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void
    {
        $result = [];
        foreach ($parts as $key => $part) {
            if ($part !== 'self') {
                continue;
            }

            $parts[$key] = '$this';
            $result[$part] = '$this';
        }

        if (!$result) {
            return;
        }

        $message = [];
        foreach ($result as $part => $useStatement) {
            $message[] = $part . ' => ' . $useStatement;
        }

        $fix = $phpCsFile->addFixableError(implode(', ', $message), $classNameIndex, 'SelfVsThis');
        if ($fix) {
            $newContent = implode('|', $parts);
            $phpCsFile->fixer->replaceToken($classNameIndex, $newContent . $appendix);
        }
    }
438320
public function register($name, $class, $requirement = '', $priority = false)
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('%s is not a valid class name.', $class));
        }

        $definition = [
            'class'       => $class,
            'requirement' => $requirement
        ];

        if ($priority) {
            $this->classes = array_merge_recursive([$name => $definition], $this->classes);
        } else {
            $this->classes[$name] = $definition;
        }
    }
143578
protected function addInterface(string $name, string $class)
    {
        if (!$this->hasInterface($name)) {
            $this->interfaces[$name] = $class;
            return;
        }
        $interfaces = $this->getInterface($name);

        if (!is_array($interfaces)) {
            $interfaces = [$interfaces];
        }

        if (!in_array($class, $interfaces)) {
            $interfaces[] = $class;
            $this->interfaces[$name] = $interfaces;
        }
    }
1170207
public static function registerLookup($class, $name = null)
    {
        /* @var $class BaseLookup */
        if (is_null($name)) {
            $name = strtolower($class::$lookupName);
        }
        self::$lookups[$name] = $class;
    }
1073320
public function actionIndex($name)
    {
        // First we will check to see if the class already exists. If it does, we don't want
        // to create the class and overwrite the user's code. So, we will bail out so the
        // code is untouched. Otherwise, we will continue generating this class' files.
        if ($this->alreadyExists($name)) {
            $this->stderr("Notification {$name} already exists!");
            return false;
        }

        // Make sure the directory exists
        $dir = CRAFT_BASE_PATH . '/notifications';
        if (! is_dir($dir)) {
            FileHelper::createDirectory($dir);
        }

        FileHelper::writeToFile($dir . "/{$name}.php", $this->buildClass($name));

        $this->stdout("Notification created successfully.");
    }
58402
static function hasAnnotation($name, $class, $method = NULL)
	{
		return NULL !== self::getAnnotation($name, $class, $method, TRUE);
	}
652509
public function createExtendedCollection($name, MkCol $mkCol)
    {
        if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) {
            throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection');
        }
        $properties = $mkCol->getRemainingValues();
        $mkCol->setRemainingResultCode(201);
        $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties);
    }
263923
public static function registerAdminClass(string $name, string $class): bool
    {
        if (class_exists($class) === false) {
            return false;
        }
        if (self::$admin_classes === null) {
            self::$admin_classes = [];
        }
        $check = new ReflectionClass($class);
        if ($check->implementsInterface("TheCMSThread\\Classes\\Admin") === true) {
            self::$admin_classes[$name] = $class;
            return true;
        } else {
            return false;
        }
    }
491546
protected function assertValidDocBlock(File $phpCsFile, int $methodIndex): void
    {
        $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $methodIndex);
        if (!$docBlockEndIndex) {
            // Let another sniff take care of this
            return;
        }

        $tokens = $phpCsFile->getTokens();

        $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener'];

        for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) {
            if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') {
                continue;
            }
            if (!in_array($tokens[$i]['content'], ['@param', '@return'], true)) {
                continue;
            }

            $classNameIndex = $i + 2;

            if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') {
                continue;
            }

            $content = $tokens[$classNameIndex]['content'];

            $spacePos = strpos($content, ' ');
            if ($spacePos) {
                $content = substr($content, 0, $spacePos);
            }
            if (substr($content, 0, 8) !== '\Spryker') {
                continue;
            }
            if (substr($content, -9) === 'Interface') {
                continue;
            }
            $pieces = explode('\\', $content);
            $lastPiece = array_pop($pieces);

            if (!$this->isRelevant($lastPiece)) {
                continue;
            }

            $error = 'Bridges should be annotated with interfaces only.';
            $phpCsFile->addError($error, $classNameIndex, 'WrongAnnotation');
        }
    }
47981
protected function getEntity($class, $name)
    {
        if (isset($this->entities[$class][$name])) {
            return $this->entities[$class][$name];
        } elseif ($this->hasReferencer() && $this->getReferencer()->hasReference($name)) {
            return $this->getManager()->merge($this->getReferencer()->getReference($name));
        }
        throw new \Exception(sprintf("No entity found for name '%s'.", $name));
    }
1161502
protected function loadProcessor($class, $name)
    {
        if (!class_exists($class) && !function_exists($class)) {
            try {
                $this->getCore()->getLoader()->loadPlugin($name);
            }
            catch (Exception $e) {
                throw new Exception('Processor ' . $name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $name . '.php in the plugin directory');
            }
        }

        if (class_exists($class)) {
            return array(new $class($this), 'process');
        }

        if (function_exists($class)) {
            return $class;
        }

        throw new Exception('Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"');
    }
412776
public function checkFieldName($name, $className)
    {
        if (!$name || trim($name) == '') {
            throw new \InvalidArgumentException(
                "Please provide valid field name for class [{$className}]"
            );
        }

        if (in_array($name, static::$reservedFieldNames)) {
            throw new \InvalidArgumentException(
                "Field name [{$name}] in form [{$className}] is a reserved word. Please use a different field name." .
                "\nList of all reserved words: " . join(', ', static::$reservedFieldNames)
            );
        }

        return true;
    }
354739
public static function trigger(
        $class,
        string $name,
        self $event = null
    ): void {
        $wildcardEventHandlers = [];
        foreach (static::$_eventWildcards as
            $nameWildcard => $classHandlers) {
            if (!StringHelper::matchWildcard($nameWildcard, $name)) {
                continue;
            }
            $wildcardEventHandlers = array_merge(
                $wildcardEventHandlers,
                $classHandlers
            );
        }

        if (
            empty(static::$_events[$name])
            && empty($wildcardEventHandlers)
        ) {
            return;
        }

        $event === null && $event = new static;
        $event->handled = false;
        $event->name = $name;

        if (is_object($class)) {
            $event->sender === null && $event->sender = $class;
            $class = get_class($class);
        } else {
            $class = ltrim($class, '\\');
        }

        $classes = array_merge(
            [$class],
            class_parents($class, true),
            class_implements($class, true)
        );

        foreach ($classes as $class) {
            $eventHandlers = [];
            foreach ($wildcardEventHandlers as $classWildcard => $handlers) {
                if (StringHelper::matchWildcard($classWildcard, $class)) {
                    $eventHandlers = array_merge($eventHandlers, $handlers);
                    unset($wildcardEventHandlers[$classWildcard]);
                }
            }

            if (!empty(static::$_events[$name][$class])) {
                $eventHandlers = array_merge(
                    $eventHandlers,
                    static::$_events[$name][$class]
                );
            }

            foreach ($eventHandlers as $handler) {
                $event->data = $handler[1];
                call_user_func($handler[0], $event);
                if ($event->handled) {
                    return;
                }
            }
        }
    }
331547
protected function normalizeDescription(DocBlock $phpdoc)
    {
        //Get the short + long description from the DocBlock
        $description = $phpdoc->getText();

        //Loop through parents/interfaces, to fill in {@inheritdoc}
        if (strpos($description, '{@inheritdoc}') !== false) {
            $inheritdoc = $this->getInheritDoc($this->method);
            $inheritDescription = $inheritdoc->getText();

            $description = str_replace('{@inheritdoc}', $inheritDescription, $description);
            $phpdoc->setText($description);

            $this->normalizeParams($inheritdoc);
            $this->normalizeReturn($inheritdoc);

            //Add the tags that are inherited
            $inheritTags = $inheritdoc->getTags();
            if ($inheritTags) {
                /** @var Tag $tag */
                foreach ($inheritTags as $tag) {
                    $tag->setDocBlock();
                    $phpdoc->appendTag($tag);
                }
            }
        }
    }
424653
public static function register($name, $class)
    {
        if (isset(self::$converterMap[$name])) {
            throw new InvalidArgumentException(
                sprintf('The attribute converter name "%s" is already registered.', $name)
            );
        }

        self::$converterMap[$name] = $class;
    }