TcaLanguageSelection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A get() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Service;
6
7
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
8
use TYPO3\CMS\Core\Site\SiteFinder;
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
11
class TcaLanguageSelection
12
{
13
    public function __construct(protected ?SiteFinder $siteFinder = null)
14
    {
15
        if ($siteFinder === null) {
16
            /** @var SiteFinder $siteFinder */
17
            $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
18
            $this->siteFinder = $siteFinder;
19
        }
20
    }
21
22
    /**
23
     * @param mixed[] $configuration
24
     */
25
    public function get(array &$configuration): void
26
    {
27
        if (!isset($configuration['row']['identifier'])) {
28
            return;
29
        }
30
31
        try {
32
            $site = $this->siteFinder->getSiteByIdentifier($configuration['row']['identifier']);
0 ignored issues
show
Bug introduced by
The method getSiteByIdentifier() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            /** @scrutinizer ignore-call */ 
33
            $site = $this->siteFinder->getSiteByIdentifier($configuration['row']['identifier']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        } catch (SiteNotFoundException $exception) {
34
            return;
35
        }
36
37
        $configuration['items'][] = ['', ''];
38
        foreach ($site->getAllLanguages() as $language) {
39
            $configuration['items'][] = [$language->getTitle(), $language->getLanguageId()];
40
        }
41
    }
42
}
43