<commit_before><?php

namespace Oro\Bundle\AsseticBundle\Factory;

use Assetic\Factory\Resource\IteratorResourceInterface;
use Assetic\Asset\AssetInterface;
use Assetic\Factory\LazyAssetManager;
use Assetic\Asset\AssetCollectionInterface;
use Assetic\Filter\DependencyExtractorInterface;

use Oro\Bundle\AsseticBundle\Node\OroAsseticNode;

class OroAssetManager
{
    /**
     * @var LazyAssetManager
     */
    public $am;

    /**
     * @var \Twig_Environment
     */
    protected $twig;

    protected $assetGroups;
    protected $compiledGroups;

    protected $assets;
    protected $loaded;
    protected $loading;


    public function __construct(LazyAssetManager $am, \Twig_Environment $twig, $assetGroups, $compiledGroups)
    {
        $this->loaded = false;
        $this->loading = false;
        $this->am = $am;
        $this->assets = array();
        $this->twig = $twig;
        $this->assetGroups = $assetGroups;
        $this->compiledGroups = $compiledGroups;
    }

    /**
     * @return array
     */
    public function getAssetGroups()
    {
        return $this->assetGroups;
    }

    /**
     * @return array
     */
    public function getCompiledGroups()
    {
        return $this->compiledGroups;
    }

    /**
     * @return array
     */
    public function getAssets()
    {
        $this->checkLoad();

        return $this->assets;
    }

    /**
     * @param $name
     * @return mixed
     */
    public function get($name)
    {
        $this->checkLoad();

        return $this->assets[$name]->getUnCompressAsset();
    }

    /**
     * @param $name
     * @return bool
     */
    public function has($name)
    {
        $this->checkLoad();

        return isset($this->assets[$name]);
    }

    /**
     * @return array
     */
    public function load()
    {
        if ($this->loading) {
            return;
        }
        $this->loading = true;

        $assets = array();
        foreach ($this->am->getResources() as $resources) {

            if (!$resources instanceof IteratorResourceInterface) {
                $resources = array($resources);
            }

            foreach ($resources as $resource) {
                /**@var $resource \Symfony\Bundle\AsseticBundle\Factory\Resource\FileResource */
                $tokens = $this->twig->tokenize($resource->getContent(), (string)$resource);
                $nodes = $this->twig->parse($tokens);
                $assets += $this->loadNode($nodes);
            }
        }

        $this->assets = $assets;
        $this->loaded = true;
        $this->loading = false;

        return $this->assets;
    }

    /**
     * @param AssetInterface $asset
     * @return int|mixed
     */
    public function getLastModified(AssetInterface $asset)
    {
        return $this->am->getLastModified($asset);
    }

    /**
     * @param $name
     * @return bool
     */
    public function hasFormula($name)
    {
        $this->checkLoad();

        return true;
    }

    /**
     * @param $name
     * @return array
     */
    public function getFormula($name)
    {
        $this->checkLoad();

        return array($this->assets[$name]->getAttribute('inputs'));
    }

    /**
     * Check if assets was loaded
     */
    private function checkLoad()
    {
        if (!$this->loaded) {
            $this->load();
        }
    }

    /**
     * Loads assets from the supplied node.
     *
     * @param \Twig_Node $node
     *
     * @return array An array of asset formulae indexed by name
     */
    private function loadNode(\Twig_Node $node)
    {
        $assets = array();
        if ($node instanceof OroAsseticNode) {
            $assets[$node->getNameUnCompress()] = $node;
        }

        foreach ($node as $child) {
            if ($child instanceof \Twig_Node) {
                $assets += $this->loadNode($child);
            }
        }

        return $assets;
    }
}
<commit_msg>BAP-1305: Fix assetic manager  - clear uses<commit_after><?php

namespace Oro\Bundle\AsseticBundle\Factory;

use Assetic\Factory\Resource\IteratorResourceInterface;
use Assetic\Asset\AssetInterface;
use Assetic\Factory\LazyAssetManager;

use Oro\Bundle\AsseticBundle\Node\OroAsseticNode;

class OroAssetManager
{
    /**
     * @var LazyAssetManager
     */
    public $am;

    /**
     * @var \Twig_Environment
     */
    protected $twig;

    protected $assetGroups;
    protected $compiledGroups;

    protected $assets;
    protected $loaded;
    protected $loading;


    public function __construct(LazyAssetManager $am, \Twig_Environment $twig, $assetGroups, $compiledGroups)
    {
        $this->loaded = false;
        $this->loading = false;
        $this->am = $am;
        $this->assets = array();
        $this->twig = $twig;
        $this->assetGroups = $assetGroups;
        $this->compiledGroups = $compiledGroups;
    }

    /**
     * @return array
     */
    public function getAssetGroups()
    {
        return $this->assetGroups;
    }

    /**
     * @return array
     */
    public function getCompiledGroups()
    {
        return $this->compiledGroups;
    }

    /**
     * @return array
     */
    public function getAssets()
    {
        $this->checkLoad();

        return $this->assets;
    }

    /**
     * @param $name
     * @return mixed
     */
    public function get($name)
    {
        $this->checkLoad();

        return $this->assets[$name]->getUnCompressAsset();
    }

    /**
     * @param $name
     * @return bool
     */
    public function has($name)
    {
        $this->checkLoad();

        return isset($this->assets[$name]);
    }

    /**
     * @return array
     */
    public function load()
    {
        if ($this->loading) {
            return;
        }
        $this->loading = true;

        $assets = array();
        foreach ($this->am->getResources() as $resources) {

            if (!$resources instanceof IteratorResourceInterface) {
                $resources = array($resources);
            }

            foreach ($resources as $resource) {
                /**@var $resource \Symfony\Bundle\AsseticBundle\Factory\Resource\FileResource */
                $tokens = $this->twig->tokenize($resource->getContent(), (string)$resource);
                $nodes = $this->twig->parse($tokens);
                $assets += $this->loadNode($nodes);
            }
        }

        $this->assets = $assets;
        $this->loaded = true;
        $this->loading = false;

        return $this->assets;
    }

    /**
     * @param AssetInterface $asset
     * @return int|mixed
     */
    public function getLastModified(AssetInterface $asset)
    {
        return $this->am->getLastModified($asset);
    }

    /**
     * @param $name
     * @return bool
     */
    public function hasFormula($name)
    {
        $this->checkLoad();

        return true;
    }

    /**
     * @param $name
     * @return array
     */
    public function getFormula($name)
    {
        $this->checkLoad();

        return array($this->assets[$name]->getAttribute('inputs'));
    }

    /**
     * Check if assets was loaded
     */
    private function checkLoad()
    {
        if (!$this->loaded) {
            $this->load();
        }
    }

    /**
     * Loads assets from the supplied node.
     *
     * @param \Twig_Node $node
     *
     * @return array An array of asset formulae indexed by name
     */
    private function loadNode(\Twig_Node $node)
    {
        $assets = array();
        if ($node instanceof OroAsseticNode) {
            $assets[$node->getNameUnCompress()] = $node;
        }

        foreach ($node as $child) {
            if ($child instanceof \Twig_Node) {
                $assets += $this->loadNode($child);
            }
        }

        return $assets;
    }
}

{'fraction_non_alphanumeric': 0.13635779462793984, 'fraction_numerical': 0.0005140727412928929, 'mean_word_length': 1.8277616279069768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '4820468', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2222, 'n_words': 457}