<commit_before><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Billapi services model for services entity
 *
 * @package  Billapi
 * @since    5.3
 */
class Models_Services extends Models_Entity {
	
	protected $errorCode = 999999;

	protected function init($params) {
		parent::init($params);
		$actionsExcludeValidation = array('move', 'close');
		if (!in_array($this->action, $actionsExcludeValidation)) {
			$this->validatePrice();
		}
	}
	
	/**
	 * Verfiy services has all price parameters required.
	 */
	protected function validatePrice() {
		$priceIntervals = $this->update['price'];
		if (empty($priceIntervals)) {
			throw new Billrun_Exceptions_Api($this->errorCode, array(), 'Service must have price value');
		}
		
		foreach ($priceIntervals as $price) {
			if (!isset($price['from']) || $price['from'] === '' || 
				!isset($price['to']) || $price['to'] === '') {
				throw new Billrun_Exceptions_Api($this->errorCode, array(), 'Service missing cycles parameters');
			}
			if (!isset($price['price']) || $price['price'] === '') {
				throw new Billrun_Exceptions_Api($this->errorCode, array(), 'Service missing price parameter');
			}
		}
		
		return true;
	}

}<commit_msg>BRCD-1045: fix(Service) - validate price only if price exist, requried validate done by parent class<commit_after><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Billapi services model for services entity
 *
 * @package  Billapi
 * @since    5.3
 */
class Models_Services extends Models_Entity {
	
	protected $errorCode = 999999;

	protected function init($params) {
		parent::init($params);
		$this->validatePrice();
	}
	
	/**
	 * Verfiy services has all price parameters required.
	 */
	protected function validatePrice() {
		$priceIntervals = Billrun_Util::getIn($this->update, 'price', []);
		foreach ($priceIntervals as $price) {
			if (!isset($price['from']) || $price['from'] === '' || 
				!isset($price['to']) || $price['to'] === '') {
				throw new Billrun_Exceptions_Api($this->errorCode, array(), 'Service missing cycles parameters');
			}
			if (!isset($price['price']) || $price['price'] === '') {
				throw new Billrun_Exceptions_Api($this->errorCode, array(), 'Service missing price parameter');
			}
		}
		
		return true;
	}

}
{'fraction_non_alphanumeric': 0.15917893106119288, 'fraction_numerical': 0.01471727343144849, 'mean_word_length': 3.9106463878326996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3130266', 'n_tokens_mistral': 858, 'n_tokens_neox': 749, 'n_words': 205}