# Skyeng Backend Developer #L1
## Требования к решению
Решение необходимо оформить в виде ссылки на Google Doc.
Предоставление решения в правильном виде — один из критериев оценки.
## Условие
Разработчика попросили получить данные из REST-API стороннего сервиса.
Данные необходимо было кешировать, ошибки логировать.
Разработчик с задачей справился, ниже предоставлен его код.
**Задание**:
1. Проведите максимально подробный Code Review. Необходимо написать,
с чем вы не согласны и почему.
2. Исправьте обозначенные ошибки, предоставив свой вариант кода.
```php
<?php
namespace src\Integration;
class DataProvider
{
private $host;
private $user;
private $password;
/**
* @param $host
* @param $user
* @param $password
*/
public function __construct($host, $user, $password)
{
$this->host = $host;
$this->user = $user;
$this->password = $password;
}
/**
* @param array $request
*
* @return array
*/
public function get(array $request)
{
// returns a response from external service
}
}
```
```php
<?php
namespace src\Decorator;
use DateTime;
use Exception;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use src\Integration\DataProvider;
class DecoratorManager extends DataProvider
{
public $cache;
public $logger;
/**
* @param string $host
* @param string $user
* @param string $password
* @param CacheItemPoolInterface $cache
*/
public function __construct($host, $user, $password, CacheItemPoolInterface $cache)
{
parent::__construct($host, $user, $password);
$this->cache = $cache;
}
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function getResponse(array $input)
{
try {
$cacheKey = $this->getCacheKey($input);
$cacheItem = $this->cache->getItem($cacheKey);
if ($cacheItem->isHit()) {
return $cacheItem->get();
}
$result = parent::get($input);
$cacheItem
->set($result)
->expiresAt(
(new DateTime())->modify('+1 day')
);
return $result;
} catch (Exception $e) {
$this->logger->critical('Error');
}
return [];
}
public function getCacheKey(array $input)
{
return json_encode($input);
}
}
```