Passed
Push — master ( 96ad23...e674df )
by Timo
12:01
created

Typo3ManagedSite::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 9.9666
cc 1
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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