[BUGFIX] Apply enableFields in JOIN's ON condition
[Packages/TYPO3.CMS.git] / Build / Scripts / checkIntegrityComposer.php
1 #!/usr/bin/env php
2 <?php
3 declare(strict_types=1);
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 require __DIR__ . '/../../vendor/autoload.php';
18
19 if (PHP_SAPI !== 'cli') {
20 die('Script must be called from command line.' . chr(10));
21 }
22
23 /**
24 * Core integrity test script:
25 *
26 * Find all composer.json files in all system extensions and compare
27 * their dependencies against the defined dependencies of our root
28 * composer.json
29 */
30 class checkIntegrityComposer
31 {
32 /**
33 * @var array
34 */
35 private $rootComposerJson = [];
36
37 private $testResults = [];
38
39 /**
40 * Executes the composer integrity check.
41 * The return value is used directly in the ext() call outside this class.
42 *
43 * @return int
44 */
45 public function execute(): int
46 {
47 $rootComposerJson = __DIR__ . '/../../composer.json';
48 $this->rootComposerJson = json_decode(file_get_contents($rootComposerJson), true);
49 $filesToProcess = $this->findExtensionComposerJson();
50 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
51
52 $resultAcrossAllFiles = 0;
53 /** @var \SplFileInfo $composerJsonFile */
54 foreach ($filesToProcess as $composerJsonFile) {
55 $fullFilePath = $composerJsonFile->getRealPath();
56 $this->validateComposerJson($fullFilePath);
57 }
58 if (!empty($this->testResults)) {
59 $table = new \Symfony\Component\Console\Helper\Table($output);
60 $table->setHeaders([
61 'EXT',
62 'type',
63 'Dependency',
64 'should be',
65 'actually is'
66 ]);
67 foreach ($this->testResults as $extKey => $results) {
68 foreach ($results as $result) {
69 $table->addRow([
70 $extKey,
71 $result['type'],
72 $result['dependency'],
73 $result['shouldBe'],
74 $result['actuallyIs']
75 ]);
76 }
77 }
78 $table->render();
79 $resultAcrossAllFiles = 1;
80 }
81 return $resultAcrossAllFiles;
82 }
83
84 /**
85 * Finds all composer.json files in TYPO3s system extensions
86 *
87 * @return \Symfony\Component\Finder\Finder
88 */
89 private function findExtensionComposerJson(): \Symfony\Component\Finder\Finder
90 {
91 $finder = new Symfony\Component\Finder\Finder();
92 $composerFiles = $finder
93 ->files()
94 ->in(__DIR__ . '/../../typo3/sysext/*')
95 ->name('composer.json');
96 return $composerFiles;
97 }
98
99 /**
100 * Checks if the dependencies defined in $composerJsonFile are the same as
101 * in TYPO3s root composer.json file.
102 *
103 * @param string $composerJsonFile
104 */
105 private function validateComposerJson(string $composerJsonFile)
106 {
107 $extensionKey = $this->extractExtensionKey($composerJsonFile);
108 $extensionComposerJson = json_decode(file_get_contents($composerJsonFile), true);
109 // Check require section
110 foreach ($this->rootComposerJson['require'] as $requireKey => $requireItem) {
111 if (isset($extensionComposerJson['require'][$requireKey]) && $extensionComposerJson['require'][$requireKey] !== $requireItem) {
112 // log inconsistency
113 $this->testResults[$extensionKey][] = [
114 'type' => 'require',
115 'dependency' => $requireKey,
116 'shouldBe' => $requireItem,
117 'actuallyIs' => $extensionComposerJson['require'][$requireKey]
118 ];
119 }
120 }
121 // Check require-dev section
122 foreach ($this->rootComposerJson['require-dev'] as $requireDevKey => $requireDevItem) {
123 if (isset($extensionComposerJson['require-dev'][$requireDevKey]) && $extensionComposerJson['require-dev'][$requireDevKey] !== $requireDevItem) {
124 // log inconsistency
125 $this->testResults[$extensionKey][] = [
126 'type' => 'require-dev',
127 'dependency' => $requireDevKey,
128 'shouldBe' => $requireDevItem,
129 'actuallyIs' => $extensionComposerJson['require-dev'][$requireDevKey]
130 ];
131 }
132 }
133 }
134
135 /**
136 * Makes the output on CLI a bit more readable
137 *
138 * @param string $filename
139 * @return string
140 */
141 private function extractExtensionKey(string $filename): string
142 {
143 $pattern = '/typo3\/sysext\/(?<extName>[a-z].+?)\//';
144 preg_match_all($pattern, $filename, $matches, PREG_SET_ORDER, 0);
145 return $matches[0]['extName'];
146 }
147 }
148
149 $composerIntegrityChecker = new checkIntegrityComposer();
150 exit($composerIntegrityChecker->execute());