public function getCodeFromDocComment(string $docComment): string
    {
        $startExampleKeyword = strpos($docComment, Constants::EXAMPLE_KEYWORD);
        $startCodeKeyword = strpos($docComment, Constants::CODE_KEYWORD);

        if ($startExampleKeyword !== false) {
            $matches = $this->getCodeWithExampleKeyword($docComment, $startExampleKeyword);
        } elseif ($startCodeKeyword !== false) {
            $matches = $this->getCodeWithCodeKeyword($docComment, $startCodeKeyword);
        } else {
            // None of the keywords was found
            return '';
        }

        if (!$matches) {
            return '';
        }

        $codeLines = array_filter(
            array_map(
                function ($line) {
                    return ltrim(trim($line, " \t\n\r\0\x0B"), '*');
                },
                // TODO: Check what type $matches has
                is_array($matches) ? $matches : explode("\n", (string)$matches)
            )
        );

        return rtrim(implode("\n", $codeLines) . ';');
    }
public function getCodeFromDocComment(string $docComment): string
    {
        $startExampleKeyword = strpos($docComment, Constants::EXAMPLE_KEYWORD);
        $startCodeKeyword = strpos($docComment, Constants::CODE_KEYWORD);

        if ($startExampleKeyword !== false) {
            $matches = $this->getCodeWithExampleKeyword($docComment, $startExampleKeyword);
        } elseif ($startCodeKeyword !== false) {
            $matches = $this->getCodeWithCodeKeyword($docComment, $startCodeKeyword);
        } else {
            // None of the keywords was found
            return '';
        }

        if (!$matches) {
            return '';
        }

        $codeLines = array_filter(
            array_map(
                function ($line) {
                    return ltrim(trim($line, " \t\n\r\0\x0B"), '*');
                },
                // TODO: Check what type $matches has
                is_array($matches) ? $matches : explode("\n", (string)$matches)
            )
        );

        return rtrim(implode("\n", $codeLines) . ';');
    }
public function getCodeFromDocComment ( string $ docComment ) : string { $ startExampleKeyword = strpos ( $ docComment , Constants :: EXAMPLE_KEYWORD ) ; $ startCodeKeyword = strpos ( $ docComment , Constants :: CODE_KEYWORD ) ; if ( $ startExampleKeyword !== false ) { $ matches = $ this -> getCodeWithExampleKeyword ( $ docComment , $ startExampleKeyword ) ; } elseif ( $ startCodeKeyword !== false ) { $ matches = $ this -> getCodeWithCodeKeyword ( $ docComment , $ startCodeKeyword ) ; } else { // None of the keywords was found return '' ; } if ( ! $ matches ) { return '' ; } $ codeLines = array_filter ( array_map ( function ( $ line ) { return ltrim ( trim ( $ line , " \t\n\r\0\x0B" ) , '*' ) ; } , // TODO: Check what type $matches has is_array ( $ matches ) ? $ matches : explode ( "\n" , ( string ) $ matches ) ) ) ; return rtrim ( implode ( "\n" , $ codeLines ) . ';' ) ; }
Extract the example code from the doc comment

@param string $docComment
@return string
Extract the example code from the doc comment