‪TYPO3CMS  10.4
checkIntegrityComposer.php
Go to the documentation of this file.
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 
31 {
35  private ‪$rootComposerJson = [];
36 
37  private ‪$testResults = [];
38 
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;
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 
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 
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 
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 
150 exit(‪$composerIntegrityChecker->execute());
‪checkIntegrityComposer\findExtensionComposerJson
‪Symfony Component Finder Finder findExtensionComposerJson()
Definition: checkIntegrityComposer.php:88
‪$finder
‪if(PHP_SAPI !=='cli') $finder
Definition: header-comment.php:22
‪checkIntegrityComposer\execute
‪int execute()
Definition: checkIntegrityComposer.php:44
‪checkIntegrityComposer\$testResults
‪$testResults
Definition: checkIntegrityComposer.php:36
‪checkIntegrityComposer\extractExtensionKey
‪string extractExtensionKey(string $filename)
Definition: checkIntegrityComposer.php:140
‪checkIntegrityComposer\$rootComposerJson
‪array $rootComposerJson
Definition: checkIntegrityComposer.php:34
‪$output
‪$output
Definition: annotationChecker.php:119
‪$composerIntegrityChecker
‪$composerIntegrityChecker
Definition: checkIntegrityComposer.php:148
‪checkIntegrityComposer
Definition: checkIntegrityComposer.php:31
‪checkIntegrityComposer\validateComposerJson
‪validateComposerJson(string $composerJsonFile)
Definition: checkIntegrityComposer.php:104