Passed
Push — master ( 14a771...9e67b2 )
by Timo
05:24
created

Typo3ManagedSite   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 24
c 2
b 1
f 0
dl 0
loc 70
rs 10
ccs 24
cts 33
cp 0.7272

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFallbackOrder() 0 4 1
A getSolrConnectionConfiguration() 0 16 2
A __construct() 0 13 1
A getTypo3SiteObject() 0 3 1
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Site;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2019 Frans Saris <[email protected]> & Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
29
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
30
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository;
31
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site;
34
35
36
/**
37
 * Class Typo3ManagedSite
38
 * @package ApacheSolrForTypo3\Solr\Domain\Site
39
 */
40
class Typo3ManagedSite extends Site
41
{
42
43
    /**
44
     * @var Typo3Site
45
     */
46
    protected $typo3SiteObject;
47
48
    /**
49
     * @var array
50
     */
51
    protected $solrConnectionConfigurations;
52
53
54 156
    public function __construct(
55
        TypoScriptConfiguration $configuration,
56
        array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = [], array $solrConnectionConfigurations = [], Typo3Site $typo3SiteObject = null)
57
    {
58 156
        $this->configuration = $configuration;
59 156
        $this->rootPage = $page;
60 156
        $this->domain = $domain;
61 156
        $this->siteHash = $siteHash;
62 156
        $this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class);
63 156
        $this->defaultLanguageId = $defaultLanguageId;
64 156
        $this->availableLanguageIds = $availableLanguageIds;
65 156
        $this->solrConnectionConfigurations = $solrConnectionConfigurations;
66 156
        $this->typo3SiteObject = $typo3SiteObject;
67 156
    }
68
69
    /**
70
     * @param int $languageUid
71
     * @return array
72
     */
73 19
    public function getFallbackOrder(int $languageUid): array
74
    {
75 19
        $languageAspect = LanguageAspectFactory::createFromSiteLanguage($this->typo3SiteObject->getLanguageById($languageUid));
76 19
        return $languageAspect->getFallbackChain();
77
    }
78
79
    /**
80
     * @param int $language
81
     * @return array
82
     * @throws NoSolrConnectionFoundException
83
     */
84 105
    public function getSolrConnectionConfiguration(int $language = 0): array
85
    {
86 105
        if (!is_array($this->solrConnectionConfigurations[$language])) {
87
            /* @var $noSolrConnectionException NoSolrConnectionFoundException */
88 1
            $noSolrConnectionException = GeneralUtility::makeInstance(
89 1
                NoSolrConnectionFoundException::class,
90 1
                /** @scrutinizer ignore-type */  'Could not find a Solr connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].',
91 1
                /** @scrutinizer ignore-type */ 1552491117
92
            );
93 1
            $noSolrConnectionException->setRootPageId($this->getRootPageId());
94 1
            $noSolrConnectionException->setLanguageId($language);
95
96 1
            throw $noSolrConnectionException;
97
        }
98
99 105
        return $this->solrConnectionConfigurations[$language];
100
    }
101
102
    /**
103
     * Returns \TYPO3\CMS\Core\Site\Entity\Site
104
     *
105
     * @return Typo3Site
106
     */
107
    public function getTypo3SiteObject(): Typo3Site
108
    {
109
        return $this->typo3SiteObject;
110
    }
111
}
112