Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — dev-extbase-fluid (#754)
by Alexander
02:55
created

ListViewController::getEntry()   F

Complexity

Conditions 20
Paths 184

Size

Total Lines 73
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 20
eloc 44
c 2
b 0
f 0
nc 184
nop 1
dl 0
loc 73
rs 3.4666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
4
 *
5
 * This file is part of the Kitodo and TYPO3 projects.
6
 *
7
 * @license GNU General Public License version 3 or later.
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace Kitodo\Dlf\Controller;
13
14
use Kitodo\Dlf\Domain\Model\Collection;
15
use Kitodo\Dlf\Domain\Model\Metadata;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Core\Utility\MathUtility;
18
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
19
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
20
21
/**
22
 * Plugin 'List View' for the 'dlf' extension
23
 *
24
 * @author Sebastian Meyer <[email protected]>
25
 * @author Henrik Lochmann <[email protected]>
26
 * @author Frank Ulrich Weber <[email protected]>
27
 * @package TYPO3
28
 * @subpackage dlf
29
 * @access public
30
 */
31
class ListViewController extends AbstractController
32
{
33
    /**
34
     * @var CollectionRepository
35
     */
36
    protected $collectionRepository;
37
38
    /**
39
     * @param CollectionRepository $collectionRepository
40
     */
41
    public function injectCollectionRepository(CollectionRepository $collectionRepository)
42
    {
43
        $this->collectionRepository = $collectionRepository;
44
    }
45
46
    /**
47
     * @var MetadataRepository
48
     */
49
    protected $metadataRepository;
50
51
    /**
52
     * @param MetadataRepository $metadataRepository
53
     */
54
    public function injectMetadataRepository(MetadataRepository $metadataRepository)
55
    {
56
        $this->metadataRepository = $metadataRepository;
57
    }
58
59
    /**
60
     * @var array $this->searchParams: The current search parameter
61
     * @access protected
62
     */
63
    protected $searchParams;
64
65
    /**
66
     * The main method of the plugin
67
     *
68
     * @return void
69
     */
70
    public function mainAction()
71
    {
72
        $this->searchParams = $this->getParametersSafely('searchParameter');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getParametersSafely('searchParameter') can also be of type string. However, the property $searchParams is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
73
74
        if ($this->searchParams['collection'] && MathUtility::canBeInterpretedAsInteger($this->searchParams['collection'])) {
75
            $collection = $this->collectionRepository->findByUid($this->searchParams['collection']);
76
        }
77
78
        $widgetPage = $this->getParametersSafely('@widget_0');
79
        if (empty($widgetPage)) {
80
            $widgetPage = ['currentPage' => 1];
81
        }
82
83
        // get all sortable metadata records
84
        $sortableMetadata = $this->metadataRepository->findByIsSortable(true);
0 ignored issues
show
Bug introduced by
The method findByIsSortable() does not exist on Kitodo\Dlf\Domain\Repository\MetadataRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

84
        /** @scrutinizer ignore-call */ 
85
        $sortableMetadata = $this->metadataRepository->findByIsSortable(true);
Loading history...
85
86
        // get all metadata records to be shown in results
87
        $listedMetadata = $this->metadataRepository->findByIsListed(true);
0 ignored issues
show
Bug introduced by
The method findByIsListed() does not exist on Kitodo\Dlf\Domain\Repository\MetadataRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

87
        /** @scrutinizer ignore-call */ 
88
        $listedMetadata = $this->metadataRepository->findByIsListed(true);
Loading history...
88
89
        $solrResults = [];
90
        if (is_array($this->searchParams) && !empty($this->searchParams)) {
91
            $solrResults = $this->documentRepository->findSolrByCollection($collection ? : null, $this->settings, $this->searchParams, $listedMetadata);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $collection does not seem to be defined for all execution paths leading up to this point.
Loading history...
92
        }
93
94
        $documents = $solrResults['documents'] ? : [];
95
        $this->view->assign('documents', $documents);
96
        $rawResults = $solrResults['solrResults']['documents'] ? : [];
97
        $this->view->assign('numResults', count($rawResults));
98
        $this->view->assign('widgetPage', $widgetPage);
99
        $this->view->assign('lastSearch', $this->searchParams);
100
101
        $this->view->assign('sortableMetadata', $sortableMetadata);
102
        $this->view->assign('listedMetadata', $listedMetadata);
103
    }
104
}
105