for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Jne;
use Jne\Contracts\Foundation\WeightInterface;
class Weight implements WeightInterface
{
/**
* Grams per kilogram.
*/
const GRAMS_PER_KILOGRAM = 1000;
* Grams per pound.
const GRAMS_PER_POUND = 453.592;
* Weight in grams.
*
* @var float
protected $grams;
* Create a new instance of Weight.
* @param float $grams
protected function __construct($grams)
$this->grams = $grams;
}
* Create weight from grams.
* @return \Jne\Contracts\Foudation\WeightInterface
public static function fromGrams($grams)
return new static($grams);
* Create weight from kilograms.
* @param float $kilograms
public static function fromKilograms($kilograms)
return new static($kilograms * self::GRAMS_PER_KILOGRAM);
* Create weight from pounds.
* @param float $pounds
public static function fromPounds($pounds)
return new static($pounds * self::GRAMS_PER_POUND);
* Get weight in grams.
* @return float
public function grams()
return $this->grams;
* Get weight in kilograms.
public function kilograms()
return $this->grams() / self::GRAMS_PER_KILOGRAM;
* Get weight in pounds.
public function pounds()
return $this->grams() / self::GRAMS_PER_POUND;