Esempio n. 1
0
 /**
  * Validate changes to this gauge
  * Attempts to generate an imperial width if a metric width is present
  *
  * @since Version 3.9.1
  * @throws \Exception if $this->name is empty
  * @throws \Exception if $this->width_metric is empty
  * @throws \Exception if $this->width_imperial is empty
  */
 private function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Name cannot be empty");
     }
     if (empty($this->width_metric)) {
         throw new Exception("Metric gauge width cannot be empty");
     }
     if (substr($this->width_metric, -2) != "mm") {
         $this->width_metric .= "mm";
     }
     if (empty($this->width_imperial) && !empty($this->width_metric)) {
         $width = Locos::convert_to_inches($this->width_metric);
         if (isset($width['ft']) && filter_var($width['ft'], FILTER_VALIDATE_INT) && $width['ft'] != 0) {
             $this->width_imperial = sprintf("%d' ", $width['ft']);
         }
         if (isset($width['in']) && filter_var($width['in'], FILTER_VALIDATE_INT) && $width['in'] != 0) {
             $this->width_imperial = sprintf("%s%d\"", $this->width_imperial, $width['in']);
         }
         $this->width_imperial = trim($this->width_imperial);
     }
     if (empty($this->width_imperial)) {
         throw new Exception("Could not create an imperial width for this gauge");
     }
     if (empty($this->slug)) {
         $this->createSlug();
     }
     return true;
 }
Esempio n. 2
0
 public function test_measurements()
 {
     $Locos = new Locos();
     $cm = 160;
     $imp = $Locos->convert_to_inches($cm);
     $this->assertEquals("5 foot 3 inches", sprintf("%d foot %d inches", $imp['ft'], $imp['in']));
     $this->assertEquals($cm, $Locos->convert_to_cm(5, 3));
 }