Skip to content

Instantly share code, notes, and snippets.

@Adamwaheed
Created October 4, 2016 17:24
Show Gist options
  • Save Adamwaheed/0395a20815835ad49d0b08e2650f6ebe to your computer and use it in GitHub Desktop.
Save Adamwaheed/0395a20815835ad49d0b08e2650f6ebe to your computer and use it in GitHub Desktop.
<?php
interface CalculateInterface{
public function canculate();
}
class PilotageCharges implements CalculateInterface{
public $model;
public $profile_id;
public function __construct($model,$profile_id){
$this->model = $model;
$this->profile_id = $profile_id;
}
public function canculate(){
$invoice['customer_id'] = $this->profile_id;
$invoice['total'] = $this->model->rate * $this->model->duration;
$invoice['details'] = "PilotageCharges Calculations";
return $invoice;
}
}
class TugCharges implements CalculateInterface{
public $model;
public $profile_id;
public function __construct($model,$profile_id){
$this->model = $model;
$this->profile_id = $profile_id;
}
public function canculate(){
$invoice['customer_id'] = $this->profile_id;
$invoice['total'] = $this->model->rate + $this->model->duration;
$invoice['details'] = "TugCharges Calculations";
return $invoice;
}
}
class Tarrif{
public function canculate(CalculateInterface $loger){
return $loger->canculate();
}
}
Route::get('/', function(){
$tarrif= new Tarrif();
$model = new StdClass();
$model->rate = 52;
$model->duration = 2;
$result1 = $tarrif->canculate(new PilotageCharges($model,25));
$result2 = $tarrif->canculate(new TugCharges($model,30));;
dd($result1,$result2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment