Completed
Push — middleware-wip ( 55159c...844477 )
by Romain
02:34
created

ContentObjectService::getContentObjectSettings()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 4
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Service;
15
16
use Romm\Formz\Core\Core;
17
use Romm\Formz\Service\Traits\SelfInstantiateTrait;
18
use TYPO3\CMS\Core\SingletonInterface;
19
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
20
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
21
22
class ContentObjectService implements SingletonInterface
23
{
24
    use SelfInstantiateTrait;
25
26
    /**
27
     * @param string $table
28
     * @param int    $uid
29
     * @param string $extensionName
30
     * @param string $pluginName
31
     * @return array
32
     */
33
    public function getContentObjectSettings($table, $uid, $extensionName, $pluginName)
34
    {
35
        /** @var ConfigurationManager $configurationManager */
36
        $configurationManager = Core::instantiate(ConfigurationManager::class);
37
38
        $contentObjectBackup = $configurationManager->getContentObject();
39
40
        $content = Core::get()->getDatabase()->exec_SELECTgetSingleRow('*', $table,'uid=' . $uid);
41
42
        $contentObject = new ContentObjectRenderer;
43
        $contentObject->start($content, $table);
0 ignored issues
show
Bug introduced by
It seems like $content defined by \Romm\Formz\Core\Core::g... $table, 'uid=' . $uid) on line 40 can also be of type boolean or null; however, TYPO3\CMS\Frontend\Conte...ObjectRenderer::start() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
        $configurationManager->setContentObject($contentObject);
45
46
        $configurationManager->setConfiguration([
47
            'extensionName' => $extensionName,
48
            'pluginName'    => $pluginName
49
        ]);
50
51
        $configuration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
52
53
        $configurationManager->setContentObject($contentObjectBackup);
54
55
        return $configuration;
56
    }
57
}
58