Exemple #1
0
 /**
  * @param array              $numbers
  * @param OperationInterface $strategy
  *
  * @return array
  */
 public function calculate(array $numbers, OperationInterface $strategy)
 {
     $formatedNumbers = [];
     foreach ($numbers as $number) {
         $formatedNumbers[] = $strategy->apply($number);
     }
     return $formatedNumbers;
 }
Exemple #2
0
 /**
  * Adds a single operation.
  * Note that only operations with the same operation name can be added.
  * First operation which is added will be the reference and the instance will let you only add
  * other operations with the same operation name.
  *
  * @param OperationInterface $operation
  *
  * @return void
  */
 public function addOperation(OperationInterface $operation)
 {
     if (null === $this->operationName) {
         $this->operationName = $operation->getName();
     }
     if ($this->operationName !== $operation->getName()) {
         return;
     }
     $this->operations[] = $operation;
 }
 public function calculate(OperationInterface $operazione, $num1, $num2)
 {
     $result = $operazione->apply($num1, $num2);
     return $result;
 }
 /** {@inheritdoc} */
 public function getType()
 {
     return $this->origin->getType();
 }
Exemple #5
0
 /**
  * Add a operation to the service description
  *
  * @param OperationInterface $operation Operation to add
  *
  * @return self
  */
 public function addOperation(OperationInterface $operation)
 {
     $this->operations[$operation->getName()] = $operation->setServiceDescription($this);
     return $this;
 }