-
Notifications
You must be signed in to change notification settings - Fork 0
/
Facade.php
47 lines (41 loc) · 1.36 KB
/
Facade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\DesignPatterns\Controller\Test;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use ArtemiiKarkusha\DesignPatterns\Api\Facade\CalculatorFacadeInterface;
use Magento\Framework\Controller\ResultInterface;
class Facade implements HttpGetActionInterface
{
/**
* @param ResultFactory $resultFactory
* @param CalculatorFacadeInterface $calculatorFacade
*/
public function __construct(
private ResultFactory $resultFactory,
private CalculatorFacadeInterface $calculatorFacade
) {}
/**
* @inheritDoc
*/
public function execute(): ResultInterface
{
return $this->resultFactory->create(ResultFactory::TYPE_RAW)
->setContents($this->getContents());
}
/**
* @return string
*/
public function getContents(): string
{
$firstNumber = 10;
$secondNumber = 5;
$subtractedNumber = $this->calculatorFacade->subtract($firstNumber, $secondNumber);
$dividedNumber = $this->calculatorFacade->divide($firstNumber, $secondNumber);
return sprintf('Devided number: %s. Subtracted number: %s', $dividedNumber, $subtractedNumber);
}
}