Completed
Push — master ( 11f33f...14005b )
by Tim
10:31 queued 07:40
created

ApiResultLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 15 2
1
<?php
2
/**
3
 * Class ApiResultLoader
4
 */
5
namespace HDNET\OnpageIntegration\Loader;
6
7
use TYPO3\CMS\Core\Utility\GeneralUtility;
8
use HDNET\OnpageIntegration\Service\DataService;
9
use HDNET\OnpageIntegration\Persister\ApiResultToCachePersister;
10
use TYPO3\CMS\Core\Cache\CacheManager;
11
12
/**
13
 * Class ApiResultLoader
14
 */
15
class ApiResultLoader
16
{
17
    /**
18
     * @var DataService
19
     */
20
    protected $dataService;
21
22
    /**
23
     * @var ApiResultToCachePersister
24
     */
25
    protected $persister;
26
27
    public function __construct()
28
    {
29
        $this->dataService = GeneralUtility::makeInstance(DataService::class);
30
        $this->persister   = GeneralUtility::makeInstance(ApiResultToCachePersister::class);
31
    }
32
33
    /**
34
     * @param string $key
35
     * @return array
36
     */
37
    public function load($key)
38
    {
39
        $cacheId = $this->persister->getIdentifier($key);
40
41
        $entry = GeneralUtility::makeInstance(CacheManager::class)->getCache('onpage_extension')->get(
42
            $cacheId
43
        );
44
45
        if ($entry === false) {
46
            $entry = $this->dataService->getApiResult($key);
47
            $this->persister->persist($entry, $key);
0 ignored issues
show
Documentation introduced by
$entry is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
        }
49
50
        return json_decode($entry, true);
51
    }
52
}
53