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 (#761)
by
unknown
08:47
created

AddDefaultFormats::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Updates;
14
15
use Psr\Log\LoggerAwareInterface;
16
use Psr\Log\LoggerAwareTrait;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use TYPO3\CMS\Core\Database\Connection;
19
use TYPO3\CMS\Core\Database\ConnectionPool;
20
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
21
use TYPO3\CMS\Core\Resource\File;
22
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Install\Updates\ChattyInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Install\Updates\ChattyInterface 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...
25
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Install\Update...baseUpdatedPrerequisite 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...
26
use TYPO3\CMS\Install\Updates\RepeatableInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Install\Updates\RepeatableInterface 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...
27
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Install\Updates\UpgradeWizardInterface 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...
28
29
/**
30
 * Migrate reference of thumbnail image in collections record.
31
 */
32
class AddDefaultFormats implements UpgradeWizardInterface, ChattyInterface, LoggerAwareInterface, RepeatableInterface
33
{
34
    use LoggerAwareTrait;
35
36
    /**
37
     * @var OutputInterface
38
     */
39
    protected $output;
40
41
    /**
42
     * @var Logger
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Updates\Logger 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...
43
     */
44
    protected $logger;
45
46
    /**
47
     * @var Connectionpool
48
     */
49
    protected $connectionPool;
50
51
    /**
52
     * @var array[]
53
     */
54
    protected $defaultFormats;
55
56
    public function __construct()
57
    {
58
        $this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
59
        $this->defaultFormats = require ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php';
60
    }
61
62
    /**
63
     * @param OutputInterface $output
64
     */
65
    public function setOutput(OutputInterface $output): void
66
    {
67
        $this->output = $output;
68
    }
69
70
    /**
71
     * @return string Unique identifier of this updater
72
     */
73
    public function getIdentifier(): string
74
    {
75
        return self::class;
76
    }
77
78
    /**
79
     * Return the speaking name of this wizard
80
     *
81
     * @return string
82
     */
83
    public function getTitle(): string
84
    {
85
        return 'Create default metadata formats.';
86
    }
87
88
    /**
89
     * Get description
90
     *
91
     * @return string Longer description of this updater
92
     */
93
    public function getDescription(): string
94
    {
95
        return 'Declare namespaces of default metadata formats such as MODS and ALTO.';
96
    }
97
98
    /**
99
     * Is an update necessary?
100
     *
101
     * Is used to determine whether a wizard needs to be run.
102
     * Check if data for migration exists.
103
     *
104
     * @return bool
105
     */
106
    public function updateNecessary(): bool
107
    {
108
        return $this->countMissingFormats() !== 0;
109
    }
110
111
    /**
112
     * Execute the update
113
     *
114
     * Called when a wizard reports that an update is necessary
115
     *
116
     * @return bool
117
     */
118
    public function executeUpdate(): bool
119
    {
120
        $insertRows = [];
121
122
        foreach ($this->getMissingFormats() as $type => $data) {
123
            $insertRows[] = [
124
                'type' => $type,
125
                'root' => $data['root'],
126
                'namespace' => $data['namespace'],
127
                'class' => $data['class'],
128
            ];
129
        }
130
131
        try {
132
            $this->connectionPool
133
                ->getConnectionForTable('tx_dlf_formats')
134
                ->bulkInsert('tx_dlf_formats', $insertRows, ['type', 'root', 'namespace', 'class']);
135
136
            return true;
137
        } catch (\Exception $e) {
138
            $this->output->writeln($e->getMessage());
139
            $this->logger->error($e->getMessage());
140
            return false;
141
        }
142
    }
143
144
    /**
145
     * @return string[] All new fields and tables must exist
146
     */
147
    public function getPrerequisites(): array
148
    {
149
        return [
150
            DatabaseUpdatedPrerequisite::class,
151
        ];
152
    }
153
154
    /**
155
     * @return array
156
     */
157
    protected function getMissingFormats(): array
158
    {
159
        $missingFormats = $this->defaultFormats;
160
161
        $availableFormats = $this->queryAvailableFormats()
162
            ->select('type')
163
            ->execute();
164
165
        while ($resArray = $availableFormats->fetch()) {
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCompatibility\Result::fetch() has been deprecated: Use fetchNumeric(), fetchAssociative() or fetchOne() instead. ( Ignorable by Annotation )

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

165
        while ($resArray = /** @scrutinizer ignore-deprecated */ $availableFormats->fetch()) {

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...
166
            unset($missingFormats[$resArray['type']]);
167
        }
168
169
        return $missingFormats;
170
    }
171
172
    /**
173
     * @return int
174
     */
175
    protected function countMissingFormats(): int
176
    {
177
        $numTotalDefaultFormats = count($this->defaultFormats);
178
179
        $numExistingDefaultFormats = $this->queryAvailableFormats()
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...y\Result::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

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

179
        $numExistingDefaultFormats = /** @scrutinizer ignore-deprecated */ $this->queryAvailableFormats()

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...
180
            ->count('uid')
181
            ->execute()
182
            ->fetchColumn(0);
183
184
        return $numTotalDefaultFormats - $numExistingDefaultFormats;
185
    }
186
187
    /**
188
     * @return QueryBuilder
189
     */
190
    protected function queryAvailableFormats(bool $count = false): QueryBuilder
191
    {
192
        $defaultFormatTypes = array_keys($this->defaultFormats);
193
194
        $queryBuilder = $this->connectionPool
195
            ->getQueryBuilderForTable('tx_dlf_formats');
196
197
        return $queryBuilder
198
            ->from('tx_dlf_formats')
199
            ->where(
200
                $queryBuilder->expr()->in('type', $queryBuilder->createNamedParameter($defaultFormatTypes, Connection::PARAM_STR_ARRAY)),
0 ignored issues
show
Bug introduced by
$queryBuilder->expr()->i...tion::PARAM_STR_ARRAY)) of type string is incompatible with the type Doctrine\DBAL\Query\Expr...on|array<integer,mixed> expected by parameter $predicates of TYPO3\CMS\Core\Database\...y\QueryBuilder::where(). ( Ignorable by Annotation )

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

200
                /** @scrutinizer ignore-type */ $queryBuilder->expr()->in('type', $queryBuilder->createNamedParameter($defaultFormatTypes, Connection::PARAM_STR_ARRAY)),
Loading history...
201
                // Apparently, TCA is not loaded in this context, so we need to manually check if the field is marked as deleted
202
                $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
203
            );
204
    }
205
}
206