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
03:18
created

AddDefaultFormats::getPrerequisites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
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
 * Upgrade wizard to add default metadata formats.
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 ConnectionPool
43
     */
44
    protected $connectionPool;
45
46
    /**
47
     * @var array[]
48
     */
49
    protected $defaultFormats;
50
51
    public function __construct()
52
    {
53
        $this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
54
        $this->defaultFormats = require ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php';
55
    }
56
57
    /**
58
     * @param OutputInterface $output
59
     */
60
    public function setOutput(OutputInterface $output): void
61
    {
62
        $this->output = $output;
63
    }
64
65
    /**
66
     * @return string Unique identifier of this updater
67
     */
68
    public function getIdentifier(): string
69
    {
70
        return self::class;
71
    }
72
73
    /**
74
     * Return the speaking name of this wizard
75
     *
76
     * @return string
77
     */
78
    public function getTitle(): string
79
    {
80
        return 'Create default metadata formats.';
81
    }
82
83
    /**
84
     * Get description
85
     *
86
     * @return string Longer description of this updater
87
     */
88
    public function getDescription(): string
89
    {
90
        return 'Declare namespaces of default metadata formats such as MODS and ALTO.';
91
    }
92
93
    /**
94
     * Is an update necessary?
95
     *
96
     * Is used to determine whether a wizard needs to be run.
97
     * Check if data for migration exists.
98
     *
99
     * @return bool
100
     */
101
    public function updateNecessary(): bool
102
    {
103
        return $this->countMissingFormats() !== 0;
104
    }
105
106
    /**
107
     * Execute the update
108
     *
109
     * Called when a wizard reports that an update is necessary
110
     *
111
     * @return bool
112
     */
113
    public function executeUpdate(): bool
114
    {
115
        $insertRows = [];
116
117
        foreach ($this->getMissingFormats() as $type => $data) {
118
            $insertRows[] = [
119
                'type' => $type,
120
                'root' => $data['root'],
121
                'namespace' => $data['namespace'],
122
                'class' => $data['class'],
123
            ];
124
        }
125
126
        try {
127
            $this->connectionPool
128
                ->getConnectionForTable('tx_dlf_formats')
129
                ->bulkInsert('tx_dlf_formats', $insertRows, ['type', 'root', 'namespace', 'class']);
130
131
            return true;
132
        } catch (\Exception $e) {
133
            $this->output->writeln($e->getMessage());
134
135
            if ($this->logger !== null) {
136
                $this->logger->error($e->getMessage());
137
            }
138
139
            return false;
140
        }
141
    }
142
143
    /**
144
     * @return string[] All new fields and tables must exist
145
     */
146
    public function getPrerequisites(): array
147
    {
148
        return [
149
            DatabaseUpdatedPrerequisite::class,
150
        ];
151
    }
152
153
    /**
154
     * @return array
155
     */
156
    protected function getMissingFormats(): array
157
    {
158
        $missingFormats = $this->defaultFormats;
159
160
        $availableFormats = $this->queryAvailableFormats()
161
            ->select('type')
162
            ->execute();
163
164
        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

164
        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...
165
            unset($missingFormats[$resArray['type']]);
166
        }
167
168
        return $missingFormats;
169
    }
170
171
    /**
172
     * @return int
173
     */
174
    protected function countMissingFormats(): int
175
    {
176
        $numTotalDefaultFormats = count($this->defaultFormats);
177
178
        $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

178
        $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...
179
            ->count('uid')
180
            ->execute()
181
            ->fetchColumn(0);
182
183
        return $numTotalDefaultFormats - $numExistingDefaultFormats;
184
    }
185
186
    /**
187
     * @return QueryBuilder
188
     */
189
    protected function queryAvailableFormats(bool $count = false): QueryBuilder
190
    {
191
        $defaultFormatTypes = array_keys($this->defaultFormats);
192
193
        $queryBuilder = $this->connectionPool
194
            ->getQueryBuilderForTable('tx_dlf_formats');
195
196
        return $queryBuilder
197
            ->from('tx_dlf_formats')
198
            ->where(
199
                $queryBuilder->expr()->in('type', $queryBuilder->createNamedParameter($defaultFormatTypes, Connection::PARAM_STR_ARRAY)),
200
                // Apparently, TCA is not loaded in this context, so we need to manually check if the field is marked as deleted
201
                $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
202
            );
203
    }
204
}
205