<?php

/*
 * This file is part of the league/commonmark package.
 *
 * (c) Colin O'Dell <colinodell@gmail.com>
 *
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
 *  - (c) John MacFarlane
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace League\CommonMark;

/**
 * Converts CommonMark-compatible Markdown to HTML
 */
class CommonMarkConverter
{
    /**
     * Converts CommonMark to HTML
     * @param string $commonMark
     *
     * @return string
     *
     * @api
     */
    public function convertToHtml($commonMark)
    {
        $environment = Environment::createCommonMarkEnvironment();
        $docParser = new DocParser($environment);
        $renderer = new HtmlRenderer($environment);

        $documentAST = $docParser->parse($commonMark);
        $html = $renderer->renderBlock($documentAST);

        return $html;
    }
}

<?php

/*
 * This file is part of the league/commonmark package.
 *
 * (c) Colin O'Dell <colinodell@gmail.com>
 *
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
 *  - (c) John MacFarlane
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace League\CommonMark;

/**
 * Converts CommonMark-compatible Markdown to HTML.
 */
class CommonMarkConverter
{
    /**
     * The document parser instance.
     * 
     * @var \League\CommonMark\DocParser
     */
    protected $docParser;

    /**
     * The html renderer instance.
     * 
     * @var \League\CommonMark\HtmlRenderer
     */
    protected $htmlRenderer;

    /**
     * Create a new commonmark converter instance.
     */
    public function __construct()
    {
        $environment = Environment::createCommonMarkEnvironment();
        $this->docParser = new DocParser($environment);
        $this->renderer = new HtmlRenderer($environment);
    }

    /**
     * Converts CommonMark to HTML.
     *
     * @param string $commonMark
     *
     * @return string
     *
     * @api
     */
    public function convertToHtml($commonMark)
    {
        $documentAST = $this->docParser->parse($commonMark);
        
        return $this->renderer->renderBlock($documentAST);
    }
}

Refactor the commonmark converter class
Refactor the commonmark converter class