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

Typo3ManagedSite::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1.0098

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 20
ccs 11
cts 14
cp 0.7856
rs 9.9666
c 1
b 0
f 0
cc 1
nc 1
nop 9
crap 1.0098

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\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