<?php

namespace Lc\ShopBundle\Services ;

class Price
{
        protected $price ;
        protected $taxRate ;

        public function __construct($price, $taxRate)
        {
                $this->price = $price ;
                $this->taxRate = $taxRate ;
        }

        public function withTax()
        {
                return self::getPriceWithTax(
                        $this->price,
                        $this->taxRate
                ) ;
        }

        public function withoutTax()
        {
                return $this->price ;
        }

        /* Static */

        public static function priceTwoDecimals($number)
        {
                return number_format(( ($number * 100)) / 100, 2) ;
        }

        public static function getPriceWithoutTax($priceWithTax, $taxRate)
        {
                return floatval($priceWithTax) / ($taxRate + 1);
        }

        public static function getPriceWithTax($priceWithoutTax, $taxRate)
        {
                return self::priceTwoDecimals(floatval($priceWithoutTax) * ($taxRate + 1)) ;
        }
}
