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
Push — master ( 14584b...f60880 )
by Sebastian
02:42
created

PdfDownloadTool::getWorkLink()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 6
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
namespace Kitodo\Dlf\Plugin\Tools;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
/**
15
 * PDF Download tool for the plugin 'Toolbox' of the 'dlf' extension
16
 *
17
 * @author Sebastian Meyer <[email protected]>
18
 * @author Alexander Bigga <[email protected]>
19
 * @package TYPO3
20
 * @subpackage dlf
21
 * @access public
22
 */
23
class PdfDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin {
24
    public $scriptRelPath = 'Classes/Plugin/Tools/PdfDownloadTool.php';
25
26
    /**
27
     * The main method of the PlugIn
28
     *
29
     * @access public
30
     *
31
     * @param string $content: The PlugIn content
32
     * @param array $conf: The PlugIn configuration
33
     *
34
     * @return string The content that is displayed on the website
35
     */
36
    public function main($content, $conf) {
37
        $this->init($conf);
38
        // Merge configuration with conf array of toolbox.
39
        $this->conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
0 ignored issues
show
Bug introduced by
It seems like $this->conf can also be of type null; however, parameter $overrule of TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

39
        $this->conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->cObj->data['conf'], /** @scrutinizer ignore-type */ $this->conf);
Loading history...
Bug introduced by
Are you sure the assignment to $this->conf is correct as TYPO3\CMS\Core\Utility\A...a['conf'], $this->conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
        // Load current document.
41
        $this->loadDocument();
42
        if ($this->doc === NULL
43
            || $this->doc->numPages < 1
0 ignored issues
show
Bug Best Practice introduced by
The property $numPages is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
44
            || empty($this->conf['fileGrpDownload'])) {
45
            // Quit without doing anything if required variables are not set.
46
            return $content;
47
        } else {
48
            if (!empty($this->piVars['logicalPage'])) {
49
                $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
50
                // The logical page parameter should not appear again
51
                unset($this->piVars['logicalPage']);
52
            }
53
            // Set default values if not set.
54
            // $this->piVars['page'] may be integer or string (physical structure @ID)
55
            if ((int) $this->piVars['page'] > 0
56
                || empty($this->piVars['page'])) {
57
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
58
            } else {
59
                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
0 ignored issues
show
Bug Best Practice introduced by
The property $physicalStructure is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
60
            }
61
            $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
62
        }
63
        // Load template file.
64
        $this->getTemplate();
65
        // Get single page downloads.
66
        $markerArray['###PAGE###'] = $this->getPageLink();
1 ignored issue
show
Comprehensibility Best Practice introduced by
$markerArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $markerArray = array(); before regardless.
Loading history...
67
        // Get work download.
68
        $markerArray['###WORK###'] = $this->getWorkLink();
69
        $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Frontend\Conte...substituteMarkerArray() has been deprecated: since TYPO3 v8, will be removed in TYPO3 v9, please use the MarkerBasedTemplateService instead. ( Ignorable by Annotation )

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

69
        $content .= /** @scrutinizer ignore-deprecated */ $this->cObj->substituteMarkerArray($this->template, $markerArray);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
70
        return $this->pi_wrapInBaseClass($content);
71
    }
72
73
    /**
74
     * Get page's download link
75
     *
76
     * @access protected
77
     *
78
     * @return string Link to downloadable page
79
     */
80
    protected function getPageLink() {
81
        $page1Link = '';
82
        $page2Link = '';
83
        $pageNumber = $this->piVars['page'];
84
        // Get image link.
85
        $details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]];
0 ignored issues
show
Bug Best Practice introduced by
The property $physicalStructure is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $physicalStructureInfo is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
86
        $file = $details['files'][$this->conf['fileGrpDownload']];
87
        if (!empty($file)) {
88
            $page1Link = $this->doc->getFileLocation($file);
89
        }
90
        // Get second page, too, if double page view is activated.
91
        if ($this->piVars['double']
92
            && $pageNumber < $this->doc->numPages) {
0 ignored issues
show
Bug Best Practice introduced by
The property $numPages is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
93
            $details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]];
94
            $file = $details['files'][$this->conf['fileGrpDownload']];
95
            if (!empty($file)) {
96
                $page2Link = $this->doc->getFileLocation($file);
97
            }
98
        }
99
        if (empty($page1Link)
100
            && empty($page2Link)) {
101
            Helper::devLog('File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', DEVLOG_SEVERITY_WARNING);
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Plugin\Tools\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
102
        }
103
        // Wrap URLs with HTML.
104
        if (!empty($page1Link)) {
105
            if ($this->piVars['double']) {
106
                $page1Link = $this->cObj->typoLink($this->pi_getLL('leftPage', ''), ['parameter' => $page1Link, 'title' => $this->pi_getLL('leftPage', '')]);
107
            } else {
108
                $page1Link = $this->cObj->typoLink($this->pi_getLL('singlePage', ''), ['parameter' => $page1Link, 'title' => $this->pi_getLL('singlePage', '')]);
109
            }
110
        }
111
        if (!empty($page2Link)) {
112
            $page2Link = $this->cObj->typoLink($this->pi_getLL('rightPage', ''), ['parameter' => $page2Link, 'title' => $this->pi_getLL('rightPage', '')]);
113
        }
114
        return $page1Link.$page2Link;
115
    }
116
117
    /**
118
     * Get work's download link
119
     *
120
     * @access protected
121
     *
122
     * @return string Link to downloadable work
123
     */
124
    protected function getWorkLink() {
125
        $workLink = '';
126
        // Get work link.
127
        if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']])) {
0 ignored issues
show
Bug Best Practice introduced by
The property $physicalStructure is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $physicalStructureInfo is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
128
            $workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']]);
129
        } else {
130
            $details = $this->doc->getLogicalStructure($this->doc->toplevelId);
0 ignored issues
show
Bug Best Practice introduced by
The property $toplevelId is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
131
            if (!empty($details['files'][$this->conf['fileGrpDownload']])) {
132
                $workLink = $this->doc->getFileLocation($details['files'][$this->conf['fileGrpDownload']]);
133
            }
134
        }
135
        // Wrap URLs with HTML.
136
        if (!empty($workLink)) {
137
            $workLink = $this->cObj->typoLink($this->pi_getLL('work', ''), ['parameter' => $workLink, 'title' => $this->pi_getLL('work', '')]);
138
        } else {
139
            Helper::devLog('File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', DEVLOG_SEVERITY_WARNING);
140
        }
141
        return $workLink;
142
    }
143
}
144