protected function blockYamlFrontmatter($line)
    {
        if ($this->config["frontmatter_yaml"]
            && strlen($line) === 3
            && $line[2] === "-"
            && $line[1] === "-"
        ) {
            $startLineNumber = $this->lineNumber;

            // Detect end of block and move it to frontmatter
            while (($line = $this->nextLine()) !== false) {
                $line = rtrim($line);

                // Block ends with --- or ...
                if (strlen($line) === 3
                    && (
                    ($line[2] === "-" && $line[1] === "-" && $line[0] === "-") ||
                    ($line[2] === "." && $line[1] === "." && $line[0] === ".")
                    )
                ) {
                    $linesRemoved = $this->lineNumber + 1 - $startLineNumber;
                    $this->linesRemoved += $linesRemoved;
                    $frontmatter = array_splice(
                        $this->lines,
                        $startLineNumber - 1,
                        $linesRemoved
                    );

                    unset($frontmatter[$linesRemoved - 1]);
                    unset($frontmatter[0]);
                    $this->addYamlFrontmatter($frontmatter);
                    $this->lineNumber = $startLineNumber - 1;

                    return true;
                }
            }

            if ($this->currentLine() === false) {
                throw new Exception("Start of YAML detected at line: $startLineNumber but no end of block detected.");
            }
        }
    }
protected function blockYamlFrontmatter($line)
    {
        if ($this->config["frontmatter_yaml"]
            && strlen($line) === 3
            && $line[2] === "-"
            && $line[1] === "-"
        ) {
            $startLineNumber = $this->lineNumber;

            // Detect end of block and move it to frontmatter
            while (($line = $this->nextLine()) !== false) {
                $line = rtrim($line);

                // Block ends with --- or ...
                if (strlen($line) === 3
                    && (
                    ($line[2] === "-" && $line[1] === "-" && $line[0] === "-") ||
                    ($line[2] === "." && $line[1] === "." && $line[0] === ".")
                    )
                ) {
                    $linesRemoved = $this->lineNumber + 1 - $startLineNumber;
                    $this->linesRemoved += $linesRemoved;
                    $frontmatter = array_splice(
                        $this->lines,
                        $startLineNumber - 1,
                        $linesRemoved
                    );

                    unset($frontmatter[$linesRemoved - 1]);
                    unset($frontmatter[0]);
                    $this->addYamlFrontmatter($frontmatter);
                    $this->lineNumber = $startLineNumber - 1;

                    return true;
                }
            }

            if ($this->currentLine() === false) {
                throw new Exception("Start of YAML detected at line: $startLineNumber but no end of block detected.");
            }
        }
    }
protected function blockYamlFrontmatter ( $ line ) { if ( $ this -> config [ "frontmatter_yaml" ] && strlen ( $ line ) === 3 && $ line [ 2 ] === "-" && $ line [ 1 ] === "-" ) { $ startLineNumber = $ this -> lineNumber ; // Detect end of block and move it to frontmatter while ( ( $ line = $ this -> nextLine ( ) ) !== false ) { $ line = rtrim ( $ line ) ; // Block ends with --- or ... if ( strlen ( $ line ) === 3 && ( ( $ line [ 2 ] === "-" && $ line [ 1 ] === "-" && $ line [ 0 ] === "-" ) || ( $ line [ 2 ] === "." && $ line [ 1 ] === "." && $ line [ 0 ] === "." ) ) ) { $ linesRemoved = $ this -> lineNumber + 1 - $ startLineNumber ; $ this -> linesRemoved += $ linesRemoved ; $ frontmatter = array_splice ( $ this -> lines , $ startLineNumber - 1 , $ linesRemoved ) ; unset ( $ frontmatter [ $ linesRemoved - 1 ] ) ; unset ( $ frontmatter [ 0 ] ) ; $ this -> addYamlFrontmatter ( $ frontmatter ) ; $ this -> lineNumber = $ startLineNumber - 1 ; return true ; } } if ( $ this -> currentLine ( ) === false ) { throw new Exception ( "Start of YAML detected at line: $startLineNumber but no end of block detected." ) ; } } }
Detect and extract block with YAML frontmatter from the lines array.

@param string $line to begin parsing.

@return boolean|void true when block is found and parsed, else void.

@SuppressWarnings(PHPMD.CyclomaticComplexity)
Detect and extract block with YAML frontmatter from the lines array .