ErrorCodes   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 30
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 10 2
1
<?php
2
3
namespace Phrest\API\Action;
4
5
class ErrorCodes implements \Interop\Http\ServerMiddleware\MiddlewareInterface
6
{
7
    /**
8
     * @var \Phrest\API\ErrorCodes
9
     */
10
    private $errorCodes;
11
12
    /**
13
     * @var \Zend\Cache\Storage\StorageInterface
14
     */
15
    private $cache;
16
17
    private const CACHE_ERROR_CODES = 'Phrest_API_Action_ErrorCodes';
18
19
    public function __construct(\Zend\Cache\Storage\StorageInterface $cache, \Phrest\API\ErrorCodes $errorCodes)
20
    {
21
        $this->errorCodes = $errorCodes;
22
        $this->cache = $cache;
23
    }
24
25
    public function process(\Psr\Http\Message\ServerRequestInterface $request, \Interop\Http\ServerMiddleware\DelegateInterface $delegate)
26
    {
27
        if(!$this->cache->hasItem(self::CACHE_ERROR_CODES)) {
28
            $errorCodes = $this->errorCodes->getErrorCodes();
29
            $this->cache->setItem(self::CACHE_ERROR_CODES, serialize($errorCodes));
30
        } else {
31
            $errorCodes = unserialize($this->cache->getItem(self::CACHE_ERROR_CODES));
32
        }
33
34
        return new \Zend\Diactoros\Response\JsonResponse($errorCodes);
35
    }
36
}