<commit_before><?php

/*
 * This file is part of the SHQFeaturesBundle.
 *
 * Copyright <NAME> 2016-2017.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2016 - 2017 Aerendir. All rights reserved.
 * @license   MIT License.
 */

namespace SerendipityHQ\Bundle\FeaturesBundle\Model;

use SerendipityHQ\Bundle\FeaturesBundle\Property\CanHaveFreePackProperty;
use SerendipityHQ\Bundle\FeaturesBundle\Property\HasConfiguredPacksInterface;
use SerendipityHQ\Bundle\FeaturesBundle\Property\HasConfiguredPacksProperty;

/**
 * {@inheritdoc}
 */
class ConfiguredCountableFeature extends AbstractFeature implements ConfiguredCountableFeatureInterface
{
    use HasConfiguredPacksProperty {
        HasConfiguredPacksProperty::setPacks as setPacksProperty;
    }
    use CanHaveFreePackProperty;

    /** @var array $packs */
    private $packs;

    /** @var string $refreshPeriod */
    private $refreshPeriod;

    /**
     * {@inheritdoc}
     */
    public function __construct(string $name, array $details = [])
    {
        // Set the type
        $details['type'] = self::COUNTABLE;

        if (isset($details['packs'])) {
            $this->setPacks($details['packs']);
        }

        $this->refreshPeriod = $details['refresh_period'];

        parent::__construct($name, $details);
    }

    /**
     * {@inheritdoc}
     */
    public function getRefreshPeriod(): string
    {
        return $this->refreshPeriod;
    }

    /**
     * {@inheritdoc}
     */
    public function setPacks(array $packs, string $class = null): HasConfiguredPacksInterface
    {
        return $this->setPacksProperty($packs, ConfiguredCountableFeaturePack::class);
    }

    /**
     * {@inheritdoc}
     */
    public function setSubscription(SubscriptionInterface $subscription): ConfiguredCountableFeatureInterface
    {
        // If there are packs, set subscription in them, too
        if (false === empty($this->packs)) {
            /** @var ConfiguredCountableFeaturePack $pack */
            foreach ($this->packs as $pack) {
                $pack->setSubscription($subscription);
            }
        }

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setTax(float $rate, string $name): ConfiguredCountableFeatureInterface
    {
        /** @var ConfiguredCountableFeaturePack $pack Set tax rate in the packs too */
        foreach ($this->getPacks() as $pack) {
            $pack->setTax($rate, $name);
        }

        return $this;
    }
}<commit_msg>Fix tax handling of `ConfiguredCountableFeature`.<commit_after><?php

/*
 * This file is part of the SHQFeaturesBundle.
 *
 * Copyright <NAME> 2016-2017.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2016 - 2017 Aerendir. All rights reserved.
 * @license   MIT License.
 */

namespace SerendipityHQ\Bundle\FeaturesBundle\Model;

use SerendipityHQ\Bundle\FeaturesBundle\Property\CanHaveFreePackProperty;
use SerendipityHQ\Bundle\FeaturesBundle\Property\HasConfiguredPacksInterface;
use SerendipityHQ\Bundle\FeaturesBundle\Property\HasConfiguredPacksProperty;

/**
 * {@inheritdoc}
 */
class ConfiguredCountableFeature extends AbstractFeature implements ConfiguredCountableFeatureInterface
{
    use HasConfiguredPacksProperty {
        HasConfiguredPacksProperty::setPacks as setPacksProperty;
    }
    use CanHaveFreePackProperty;

    /** @var array $packs */
    private $packs;

    /** @var string $refreshPeriod */
    private $refreshPeriod;

    /** @var string $taxName */
    private $taxName;

    /** @var float $taxRate */
    private $taxRate;

    /**
     * {@inheritdoc}
     */
    public function __construct(string $name, array $details = [])
    {
        // Set the type
        $details['type'] = self::COUNTABLE;

        if (isset($details['packs'])) {
            $this->setPacks($details['packs']);
        }

        $this->refreshPeriod = $details['refresh_period'];

        parent::__construct($name, $details);
    }

    /**
     * {@inheritdoc}
     */
    public function getRefreshPeriod(): string
    {
        return $this->refreshPeriod;
    }

    /**
     * {@inheritdoc}
     */
    public function setPacks(array $packs, string $class = null): HasConfiguredPacksInterface
    {
        return $this->setPacksProperty($packs, ConfiguredCountableFeaturePack::class);
    }

    /**
     * {@inheritdoc}
     */
    public function setSubscription(SubscriptionInterface $subscription): ConfiguredCountableFeatureInterface
    {
        // If there are packs, set subscription in them, too
        if (false === empty($this->packs)) {
            /** @var ConfiguredCountableFeaturePack $pack */
            foreach ($this->packs as $pack) {
                $pack->setSubscription($subscription);
            }
        }

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setTax(float $rate, string $name): ConfiguredCountableFeatureInterface
    {
        $this->taxRate = $rate;
        $this->taxName = $name;

        /** @var ConfiguredCountableFeaturePack $pack Set tax rate in the packs too */
        foreach ($this->getPacks() as $pack) {
            $pack->setTax($rate, $name);
        }

        return $this;
    }

    /**
     * @return string
     */
    public function getTaxName(): string
    {
        return $this->taxName;
    }

    /**
     * @return float
     */
    public function getTaxRate(): float
    {
        return $this->taxRate;
    }
}
{'fraction_non_alphanumeric': 0.11981164980816184, 'fraction_numerical': 0.0055807464248343215, 'mean_word_length': 2.6598596043395024, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, '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': '2126348', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1595, 'n_words': 372}