<commit_before><?php

namespace OpenOrchestra\FrontBundle\Manager;

use OpenOrchestra\ModelInterface\Model\ReadNodeInterface;
use OpenOrchestra\ModelInterface\Repository\ReadNodeRepositoryInterface;
use OpenOrchestra\ModelInterface\Model\ReadSiteInterface;
use OpenOrchestra\BaseBundle\Manager\EncryptionManager;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Class ErrorPagesManager
 */
class ErrorPagesManager
{
    protected $nodeRepository;
    protected $filesystem;
    protected $client;
    protected $router;
    protected $encrypter;

    /**
     * @param ReadNodeRepositoryInterface $nodeRepository
     * @param Filesystem                  $filesystem
     * @param Client                      $client
     * @param UrlGeneratorInterface       $router
     * @param EncryptionManager           $encrypter
     */
    public function __construct(
        ReadNodeRepositoryInterface $nodeRepository,
        Filesystem $filesystem,
        Client $client,
        UrlGeneratorInterface $router,
        EncryptionManager $encrypter
    ) {
        $this->nodeRepository = $nodeRepository;
        $this->filesystem = $filesystem;
        $this->client = $client;
        $this->router = $router;
        $this->encrypter = $encrypter;
    }

    /**
     * Dump published error pages for $site
     *
     * @param ReadSiteInterface $site
     *
     * @return string
     */
    public function generateErrorPages(ReadSiteInterface $site)
    {
        $filenames = array();
        $errorNodes = array();

        $nodeCollection = $this->nodeRepository->findAllNodesOfTypeInLastPublishedVersionForSite(ReadNodeInterface::TYPE_ERROR, $site->getSiteId());
        foreach ($nodeCollection as $translatedError) {
            $errorNodes[$translatedError->getLanguage()][$translatedError->getNodeId()] = $translatedError;
        }

        foreach ($site->getAliases() as $aliasId => $alias) {
            if (isset($errorNodes[$alias->getLanguage()])) {
                foreach ($errorNodes[$alias->getLanguage()] as $errorNode) {
                    $filenames[] = $this->dumpErrorPageForSiteAlias($errorNode, $aliasId, $site->getSiteId());
                }
            }
        }

        return $filenames;
    }

    /**
     * Dump the single error pages for a siteAlias given by $errorNode
     * 
     * @param ReadNodeInterface $errorNode
     * @param int               $aliasId
     * @param string            $siteId
     */
    protected function dumpErrorPageForSiteAlias(ReadNodeInterface $errorNode, $aliasId, $siteId)
    {
        $url = $this->router->generate(
            'open_orchestra_base_node_preview',
            array(
                'token' => $this->encrypter->encrypt($errorNode->getId()),
                'nodeId' => $errorNode->getNodeId(),
                'aliasId' => $aliasId
            )
        );

        $filepath = $siteId . '/alias-' . $aliasId . '/' . $errorNode->getName() . '.html';
        $crawler = $this->client->request('GET', $url);

        $this->filesystem->dumpFile('web/' . $filepath, $crawler->html());

        return $filepath;
    }
}
<commit_msg>remove empty lines<commit_after><?php

namespace OpenOrchestra\FrontBundle\Manager;

use OpenOrchestra\ModelInterface\Model\ReadNodeInterface;
use OpenOrchestra\ModelInterface\Repository\ReadNodeRepositoryInterface;
use OpenOrchestra\ModelInterface\Model\ReadSiteInterface;
use OpenOrchestra\BaseBundle\Manager\EncryptionManager;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Class ErrorPagesManager
 */
class ErrorPagesManager
{
    protected $nodeRepository;
    protected $filesystem;
    protected $client;
    protected $router;
    protected $encrypter;

    /**
     * @param ReadNodeRepositoryInterface $nodeRepository
     * @param Filesystem                  $filesystem
     * @param Client                      $client
     * @param UrlGeneratorInterface       $router
     * @param EncryptionManager           $encrypter
     */
    public function __construct(
        ReadNodeRepositoryInterface $nodeRepository,
        Filesystem $filesystem,
        Client $client,
        UrlGeneratorInterface $router,
        EncryptionManager $encrypter
    ) {
        $this->nodeRepository = $nodeRepository;
        $this->filesystem = $filesystem;
        $this->client = $client;
        $this->router = $router;
        $this->encrypter = $encrypter;
    }

    /**
     * Dump published error pages for $site
     *
     * @param ReadSiteInterface $site
     *
     * @return string
     */
    public function generateErrorPages(ReadSiteInterface $site)
    {
        $filenames = array();
        $errorNodes = array();

        $nodeCollection = $this->nodeRepository->findAllNodesOfTypeInLastPublishedVersionForSite(ReadNodeInterface::TYPE_ERROR, $site->getSiteId());
        foreach ($nodeCollection as $translatedError) {
            $errorNodes[$translatedError->getLanguage()][$translatedError->getNodeId()] = $translatedError;
        }

        foreach ($site->getAliases() as $aliasId => $alias) {
            if (isset($errorNodes[$alias->getLanguage()])) {
                foreach ($errorNodes[$alias->getLanguage()] as $errorNode) {
                    $filenames[] = $this->dumpErrorPageForSiteAlias($errorNode, $aliasId, $site->getSiteId());
                }
            }
        }

        return $filenames;
    }

    /**
     * Dump the single error pages for a siteAlias given by $errorNode
     * 
     * @param ReadNodeInterface $errorNode
     * @param int               $aliasId
     * @param string            $siteId
     */
    protected function dumpErrorPageForSiteAlias(ReadNodeInterface $errorNode, $aliasId, $siteId)
    {
        $url = $this->router->generate(
            'open_orchestra_base_node_preview',
            array(
                'token' => $this->encrypter->encrypt($errorNode->getId()),
                'nodeId' => $errorNode->getNodeId(),
                'aliasId' => $aliasId
            )
        );

        $filepath = $siteId . '/alias-' . $aliasId . '/' . $errorNode->getName() . '.html';
        $crawler = $this->client->request('GET', $url);
        $this->filesystem->dumpFile('web/' . $filepath, $crawler->html());

        return $filepath;
    }
}

{'fraction_non_alphanumeric': 0.11831943157244362, 'fraction_numerical': 0.0, 'mean_word_length': 2.5266884531590414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '1873746', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1768, 'n_words': 330}