src/bekanntmacher/boxmaker-bundle/src/Calculation/Surface.php line 50

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: yanickwitschi
  5.  * Date: 15/12/14
  6.  * Time: 11:52
  7.  */
  8. namespace Bekanntmacher\BoxmakerBundle\Calculation;
  9. class Surface
  10. {
  11.     /**
  12.      * Formula width
  13.      * @var string
  14.      */
  15.     protected $strFormulaWidth;
  16.     /**
  17.      * Formula length
  18.      * @var string
  19.      */
  20.     protected $strFormulaLength;
  21.     /**
  22.      * Formula tokens
  23.      * @var array
  24.      */
  25.     protected $arrData;
  26.     /**
  27.      * @param $strFormulaLength
  28.      * @param $strFormulaLength
  29.      * @param $strFormulaWidth
  30.      */
  31.     function __construct($strFormulaLength$strFormulaWidth, array $arrData)
  32.     {
  33.         $this->strFormulaLength $strFormulaLength;
  34.         $this->strFormulaWidth  $strFormulaWidth;
  35.         $this->arrData $arrData;
  36.     }
  37.     /**
  38.      * Get the "m2 per piece" (based on length and width)
  39.      *
  40.      * @return  Number
  41.      * @throws  \RuntimeException
  42.      */
  43.     public function getM2PerPiece()
  44.     {
  45.         $width $this->getFormulaResult(
  46.             $this->strFormulaWidth,
  47.             $this->arrData
  48.         );
  49.         $length $this->getFormulaResult(
  50.             $this->strFormulaLength,
  51.             $this->arrData
  52.         );
  53.         return (float) ( $width $length );
  54.     }
  55.     /**
  56.      * Get the "Nutzen" (based on length and width)
  57.      *
  58.      * @return  Number
  59.      * @throws  \RuntimeException
  60.      */
  61.     public function getNutzen()
  62.     {
  63.         $width $this->getFormulaResult(
  64.             $this->strFormulaWidth,
  65.             $this->arrData
  66.         );
  67.         $length $this->getFormulaResult(
  68.             $this->strFormulaLength,
  69.             $this->arrData
  70.         );
  71.         return floor($width) * floor($length);
  72.     }
  73.     /**
  74.      * Execute formula code with tokens and return the result
  75.      *
  76.      * @param   string $code
  77.      * @param   array $tokens
  78.      * @return  float
  79.      */
  80.     private function getFormulaResult($code$arrData)
  81.     {
  82.         $code 'return ' . \StringUtil::parseSimpleTokens($code$arrData) . ';';
  83.         return (float) eval($code);
  84.     }