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

ImageDownloadTool::main()   B

Complexity

Conditions 9
Paths 17

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 22
nc 17
nop 2
dl 0
loc 35
rs 8.0555
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
 * Image Download tool for the plugin 'Toolbox' of the 'dlf' extension
16
 *
17
 * @author Alexander Bigga <[email protected]>
18
 * @package TYPO3
19
 * @subpackage dlf
20
 * @access public
21
 */
22
class ImageDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin {
23
    public $scriptRelPath = 'Classes/Plugin/Tools/ImageDownloadTool.php';
24
25
    /**
26
     * The main method of the PlugIn
27
     *
28
     * @access public
29
     *
30
     * @param string $content: The PlugIn content
31
     * @param array $conf: The PlugIn configuration
32
     *
33
     * @return string The content that is displayed on the website
34
     */
35
    public function main($content, $conf) {
36
        $this->init($conf);
37
        // Merge configuration with conf array of toolbox.
38
        $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

38
        $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...
39
        // Load current document.
40
        $this->loadDocument();
41
        if ($this->doc === NULL
42
            || $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...
43
            || empty($this->conf['fileGrpsImageDownload'])) {
44
            // Quit without doing anything if required variables are not set.
45
            return $content;
46
        } else {
47
            if (!empty($this->piVars['logicalPage'])) {
48
                $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
49
                // The logical page parameter should not appear again
50
                unset($this->piVars['logicalPage']);
51
            }
52
            // Set default values if not set.
53
            // $this->piVars['page'] may be integer or string (physical structure @ID)
54
            if ((int) $this->piVars['page'] > 0
55
                || empty($this->piVars['page'])) {
56
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
57
            } else {
58
                $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...
59
            }
60
            $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
61
        }
62
        // Load template file.
63
        $this->getTemplate();
64
        // Get left or single page download.
65
        $markerArray['###IMAGE_LEFT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'], $this->pi_getLL('leftPage', '')) : $this->getImage($this->piVars['page'], $this->pi_getLL('singlePage', ''));
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...
66
        // Get right page download.
67
        $markerArray['###IMAGE_RIGHT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'] + 1, $this->pi_getLL('rightPage', '')) : '';
68
        $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

68
        $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...
69
        return $this->pi_wrapInBaseClass($content);
70
    }
71
72
    /**
73
     * Get image's URL and MIME type
74
     *
75
     * @access protected
76
     *
77
     * @param integer $page: Page number
78
     * @param string $label: Link title and label
79
     *
80
     * @return string Link to image file with given label
81
     */
82
    protected function getImage($page, $label) {
83
        $image = [];
84
        // Get @USE value of METS fileGrp.
85
        $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrpsImageDownload']);
86
        while ($fileGrp = @array_pop($fileGrps)) {
87
            // Get image link.
88
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) {
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...
89
                $image['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
90
                $image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
91
                switch ($image['mimetype']) {
92
                    case 'image/jpeg':
93
                        $mimetypeLabel = '(JPG)';
94
                        break;
95
                    case 'image/tiff':
96
                        $mimetypeLabel = '(TIFF)';
97
                        break;
98
                    default:
99
                        $mimetypeLabel = '';
100
                }
101
                $linkConf = [
102
                    'parameter' => $image['url'],
103
                    'title' => $label.' '.$mimetypeLabel,
104
                    'additionalParams' => '',
105
                ];
106
                $imageLink = $this->cObj->typoLink($label.' '.$mimetypeLabel, $linkConf);
107
                break;
108
            } else {
109
                Helper::devLog('File not found in fileGrp "'.$fileGrp.'"', 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...
110
            }
111
        }
112
        return $imageLink;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $imageLink does not seem to be defined for all execution paths leading up to this point.
Loading history...
113
    }
114
}
115