<commit_before><?php
/**
 * UMI.Framework (http://umi-framework.ru/)
 *
 * @link      http://github.com/Umisoft/framework for the canonical source repository
 * @copyright Copyright (c) 2007-2013 Umisoft ltd. (http://umisoft.ru/)
 * @license   http://umi-framework.ru/license/bsd-3 BSD-3 License
 */
namespace umi\rss\toolbox\factory;

use DateTime;
use Exception;
use SimpleXMLElement;
use umi\rss\exception\RuntimeException;
use umi\rss\IRssFeed;
use umi\toolkit\factory\IFactory;
use umi\toolkit\factory\TFactory;
use umi\rss\IRssEntityFactory;

/**
 * Фабрика для создания RSS сущностей.
 */
class RssEntityFactory implements IRssEntityFactory, IFactory
{

    use TFactory;

    /**
     * @var string $rssFeedClass класс для создания RSS ленты
     */
    public $rssFeedClass = 'umi\rss\RssFeed';
    /**
     * @var string $rssItemClass класс для создания RSS-элемента
     */
    public $rssItemClass = 'umi\rss\RssItem';

    /**
     * {@inheritdoc}
     */
    public function createFeed($url, $title, $description)
    {
        return $this->getPrototype(
            $this->rssFeedClass,
            ['umi\rss\IRssFeed']
        )
            ->createInstance([$url, $title, $description]);
    }

    /**
     * {@inheritdoc}
     */
    public function createFeedFromXml($xml)
    {
        try {
            $rssElement = new SimpleXMLElement($xml);
        } catch (Exception $e) {
            throw new RuntimeException('Invalid XML');
        }

        if (!isset($rssElement->channel)) {
            throw new RuntimeException('Channel section is not specified');
        }

        if (!isset($rssElement->channel->link)) {
            throw new RuntimeException('Channel link is not specified');
        }
        if (!isset($rssElement->channel->title)) {
            throw new RuntimeException('Channel title is not specified');
        }
        if (!isset($rssElement->channel->description)) {
            throw new RuntimeException('Channel description is not specified');
        }

        $rssFeed = $this->createFeed(
            (string)$rssElement->channel->link,
            (string)$rssElement->channel->title,
            (string)$rssElement->channel->description
        );

        $items = $rssElement->channel->item;

        foreach ($items as $item) {<commit_msg>[rss] Exception messages fixed.<commit_after><?php
/**
 * UMI.Framework (http://umi-framework.ru/)
 *
 * @link      http://github.com/Umisoft/framework for the canonical source repository
 * @copyright Copyright (c) 2007-2013 Umisoft ltd. (http://umisoft.ru/)
 * @license   http://umi-framework.ru/license/bsd-3 BSD-3 License
 */
namespace umi\rss\toolbox\factory;

use DateTime;
use Exception;
use SimpleXMLElement;
use umi\rss\exception\RuntimeException;
use umi\rss\IRssFeed;
use umi\toolkit\factory\IFactory;
use umi\toolkit\factory\TFactory;
use umi\rss\IRssEntityFactory;

/**
 * Фабрика для создания RSS сущностей.
 */
class RssEntityFactory implements IRssEntityFactory, IFactory
{

    use TFactory;

    /**
     * @var string $rssFeedClass класс для создания RSS ленты
     */
    public $rssFeedClass = 'umi\rss\RssFeed';
    /**
     * @var string $rssItemClass класс для создания RSS-элемента
     */
    public $rssItemClass = 'umi\rss\RssItem';

    /**
     * {@inheritdoc}
     */
    public function createFeed($url, $title, $description)
    {
        return $this->getPrototype(
            $this->rssFeedClass,
            ['umi\rss\IRssFeed']
        )
            ->createInstance([$url, $title, $description]);
    }

    /**
     * {@inheritdoc}
     */
    public function createFeedFromXml($xml)
    {
        try {
            $rssElement = new SimpleXMLElement($xml);
        } catch (Exception $e) {
            throw new RuntimeException('Cannot create feed from xml. XML is not wellformed.');
        }

        if (!isset($rssElement->channel)) {
            throw new RuntimeException('Cannot create feed. Channel section is not specified');
        }

        if (!isset($rssElement->channel->link)) {
            throw new RuntimeException('Cannot create feed. Channel link is not specified');
        }
        if (!isset($rssElement->channel->title)) {
            throw new RuntimeException('Cannot create feed. Channel title is not specified');
        }
        if (!isset($rssElement->channel->description)) {
            throw new RuntimeException('Cannot create feed. Channel description is not specified');
        }

        $rssFeed = $this->createFeed(
            (string) $rssElement->channel->link,
            (string) $rssElement->channel->title,
            (string) $rssElement->channel->description
        );

        $items = $rssElement->channel->item;

        foreach ($items as $item) {
{'fraction_non_alphanumeric': 0.13012402774858103, 'fraction_numerical': 0.004204330460374185, 'mean_word_length': 2.4857142857142858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '407742', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1377, 'n_words': 319}