Passed
Pull Request — release-11.2.x (#3594)
by Markus
14:43 queued 10:47
created

Typo3ManagedSite   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 68.75%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
eloc 22
dl 0
loc 68
ccs 22
cts 32
cp 0.6875
rs 10
c 2
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolrConnectionConfiguration() 0 18 2
A getTypo3SiteObject() 0 3 1
A __construct() 0 20 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\Site\Entity\Site as Typo3Site;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34
/**
35
 * Class Typo3ManagedSite
36
 */
37
class Typo3ManagedSite extends Site
38
{
39
40
    /**
41
     * @var Typo3Site
42
     */
43
    protected $typo3SiteObject;
44
45
    /**
46
     * @var array
47
     */
48
    protected $solrConnectionConfigurations;
49
50
    public function __construct(
51
        TypoScriptConfiguration $configuration,
52 151
        array $page,
53
        $domain,
54
        $siteHash,
55
        PagesRepository $pagesRepository = null,
56 151
        $defaultLanguageId = 0,
57 151
        $availableLanguageIds = [],
58 151
        array $solrConnectionConfigurations = [],
59 151
        Typo3Site $typo3SiteObject = null
60 151
    ) {
61 151
        $this->configuration = $configuration;
62 151
        $this->rootPage = $page;
63 151
        $this->domain = $domain;
64 151
        $this->siteHash = $siteHash;
65 151
        $this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class);
66
        $this->defaultLanguageId = $defaultLanguageId;
67
        $this->availableLanguageIds = $availableLanguageIds;
68
        $this->solrConnectionConfigurations = $solrConnectionConfigurations;
69
        $this->typo3SiteObject = $typo3SiteObject;
70
    }
71
72 140
    /**
73
     * @param int $language
74 140
     * @return array
75
     * @throws NoSolrConnectionFoundException
76 2
     */
77
    public function getSolrConnectionConfiguration(int $language = 0): array
78 2
    {
79 2
        if (!is_array($this->solrConnectionConfigurations[$language])) {
80
            /* @var $noSolrConnectionException NoSolrConnectionFoundException */
81 2
            $noSolrConnectionException = GeneralUtility::makeInstance(
82 2
                NoSolrConnectionFoundException::class,
83
                /** @scrutinizer ignore-type */
84 2
                'Could not find a Solr connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].',
85
                /** @scrutinizer ignore-type */
86
                1552491117
87 140
            );
88
            $noSolrConnectionException->setRootPageId($this->getRootPageId());
89
            $noSolrConnectionException->setLanguageId($language);
90
91
            throw $noSolrConnectionException;
92
        }
93
94
        return $this->solrConnectionConfigurations[$language];
95 4
    }
96
97 4
    /**
98
     * Returns \TYPO3\CMS\Core\Site\Entity\Site
99
     *
100
     * @return Typo3Site
101
     */
102
    public function getTypo3SiteObject(): Typo3Site
103
    {
104
        return $this->typo3SiteObject;
105
    }
106
}
107