<commit_before><?php

/*
 * This file is part of sonata-project.
 *
 * (c) 2010 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\BlockBundle\Templating\Helper;

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Cache\HttpCacheHandlerInterface;
use Sonata\BlockBundle\Event\BlockEvent;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BlockRendererInterface;
use Sonata\BlockBundle\Util\RecursiveBlockIterator;
use Sonata\Cache\CacheManagerInterface;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\HttpFoundation\Response;

use Doctrine\Common\Util\ClassUtils;

class BlockHelper extends Helper
{
    private $blockServiceManager;

    private $cacheManager;

    private $cacheBlocks;

    private $blockRenderer;

    private $blockContextManager;

    private $cacheHandler;

    private $eventDispatcher;

    /**
     * This property is a state variable holdings all assets used by the block for the current PHP request
     * It is used to correctly render the javascripts and stylesheets tags on the main layout
     *
     * @var array
     */
    private $assets;

    private $traces;

    private $stopwatch;

    /**
     * @param BlockServiceManagerInterface $blockServiceManager
     * @param array                        $cacheBlocks
     * @param BlockRendererInterface       $blockRenderer
     * @param BlockContextManagerInterface $blockContextManager
     * @param EventDispatcherInterface     $eventDispatcher
     * @param CacheManagerInterface        $cacheManager
     * @param HttpCacheHandlerInterface    $cacheHandler
     * @param Stopwatch                    $stopwatch
     */
    public function __construct(BlockServiceManagerInterface $blockServiceManager, array $cacheBlocks, BlockRendererInterface $blockRenderer,
                                BlockContextManagerInterface $blockContextManager, EventDispatcherInterface $eventDispatcher,
                                CacheManagerInterface $cacheManager = null, HttpCacheHandlerInterface $cacheHandler = null, Stopwatch $stopwatch = null)
    {
        $this->blockServiceManager = $blockServiceManager;
        $this->cacheBlocks         = $cacheBlocks;
        $this->blockRenderer       = $blockRenderer;
        $this->eventDispatcher     = $eventDispatcher;
        $this->cacheManager        = $cacheManager;
        $this->blockContextManager = $blockContextManager;
        $this->cacheHandler        = $cacheHandler;
        $this->stopwatch           = $stopwatch;

        $this->assets = array(
            'js'  => array(),
            'css' => array()
        );

        $this->traces = array(
            '_events' => array()
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'sonata_block';
    }

    /**
     * @param string $media
     * @param string $basePath
     *
     * @return array|string
     */
    public function includeJavascripts($media, $basePath = '')
    {
        $html = "";
        foreach ($this->assets['js'] as $javascript) {
            $html .= "\n" . sprintf('<script src="%s%s" type="text/javascript"></script>', $basePath, $javascript);
        }

        return $html;
    }

    /**
     * @param string $media
     * @param string $basePath
     *
     * @return array|string
     */
    public function includeStylesheets($media, $basePath = '')
    {

        $html = sprintf("<style type='text/css' media='%s'>", $media);

        foreach ($this->assets['css'] as $stylesheet) {
            $html .= "\n" . sprintf('@import url(%s%s);', $basePath, $stylesheet);
        }

        $html .= "\n</style>";

        return $html;
    }

    /**
     * Traverse the parent block and its children to retrieve the correct list css and javascript only for main block
     *
     * @param BlockContextInterface $blockContext
     * @param array                 $stats
     */
    protected function computeAssets(BlockContextInterface $blockContext, array &$stats = null)
    {
        if ($blockContext->getBlock()->hasParent()) {
            return;
        }

        $service = $this->blockServiceManager->get($blockContext->getBlock());
<commit_msg>update phpdoc, fix #130, fix #131<commit_after><?php

/*
 * This file is part of sonata-project.
 *
 * (c) 2010 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\BlockBundle\Templating\Helper;

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Cache\HttpCacheHandlerInterface;
use Sonata\BlockBundle\Event\BlockEvent;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BlockRendererInterface;
use Sonata\BlockBundle\Util\RecursiveBlockIterator;
use Sonata\Cache\CacheManagerInterface;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\HttpFoundation\Response;

use Doctrine\Common\Util\ClassUtils;

class BlockHelper extends Helper
{
    private $blockServiceManager;

    private $cacheManager;

    private $cacheBlocks;

    private $blockRenderer;

    private $blockContextManager;

    private $cacheHandler;

    private $eventDispatcher;

    /**
     * This property is a state variable holdings all assets used by the block for the current PHP request
     * It is used to correctly render the javascripts and stylesheets tags on the main layout
     *
     * @var array
     */
    private $assets;

    private $traces;

    private $stopwatch;

    /**
     * @param BlockServiceManagerInterface $blockServiceManager
     * @param array                        $cacheBlocks
     * @param BlockRendererInterface       $blockRenderer
     * @param BlockContextManagerInterface $blockContextManager
     * @param EventDispatcherInterface     $eventDispatcher
     * @param CacheManagerInterface        $cacheManager
     * @param HttpCacheHandlerInterface    $cacheHandler
     * @param Stopwatch                    $stopwatch
     */
    public function __construct(BlockServiceManagerInterface $blockServiceManager, array $cacheBlocks, BlockRendererInterface $blockRenderer,
                                BlockContextManagerInterface $blockContextManager, EventDispatcherInterface $eventDispatcher,
                                CacheManagerInterface $cacheManager = null, HttpCacheHandlerInterface $cacheHandler = null, Stopwatch $stopwatch = null)
    {
        $this->blockServiceManager = $blockServiceManager;
        $this->cacheBlocks         = $cacheBlocks;
        $this->blockRenderer       = $blockRenderer;
        $this->eventDispatcher     = $eventDispatcher;
        $this->cacheManager        = $cacheManager;
        $this->blockContextManager = $blockContextManager;
        $this->cacheHandler        = $cacheHandler;
        $this->stopwatch           = $stopwatch;

        $this->assets = array(
            'js'  => array(),
            'css' => array()
        );

        $this->traces = array(
            '_events' => array()
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'sonata_block';
    }

    /**
     * @param string $media    Unused, only kept to not break existing code
     * @param string $basePath Base path to prepend to the stylesheet urls.
     *
     * @return array|string
     */
    public function includeJavascripts($media, $basePath = '')
    {
        $html = "";
        foreach ($this->assets['js'] as $javascript) {
            $html .= "\n" . sprintf('<script src="%s%s" type="text/javascript"></script>', $basePath, $javascript);
        }

        return $html;
    }

    /**
     * @param string $media    The css media type to use: all|screen|...
     * @param string $basePath Base path to prepend to the stylesheet urls.
     *
     * @return array|string
     */
    public function includeStylesheets($media, $basePath = '')
    {

        $html = sprintf("<style type='text/css' media='%s'>", $media);

        foreach ($this->assets['css'] as $stylesheet) {
            $html .= "\n" . sprintf('@import url(%s%s);', $basePath, $stylesheet);
        }

        $html .= "\n</style>";

        return $html;
    }

    /**
     * Traverse the parent block and its children to retrieve the correct list css and javascript only for main block
     *
     * @param BlockContextInterface $blockContext
     * @param array                 $stats
     */
    protected function computeAssets(BlockContextInterface $blockContext, array &$stats = null)
    {
        if ($blockContext->getBlock()->hasParent()) {
            return;
        }

        $service = $this->blockServiceManager->get($blockContext->getBlock());

{'fraction_non_alphanumeric': 0.10366312171017295, 'fraction_numerical': 0.0015039209367278977, 'mean_word_length': 2.6827531645569622, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1986941', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2398, 'n_words': 614}