Skip to content

Commit 82321be

Browse files
zero-24Phil E. Taylor
andauthored
Apply PHPCS to the build tools and remove unused md5/sha1 hashes (#34290)
* Apply PHPCS to the build tools and remove unused md5/sha1 hashes * phpcs (#49) * phpcs * revert to suitable lang level Co-authored-by: Phil E. Taylor <[email protected]>
1 parent 6a25a6a commit 82321be

File tree

3 files changed

+85
-68
lines changed

3 files changed

+85
-68
lines changed

build/build.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function usage($command)
2828
{
2929
echo PHP_EOL;
3030
echo 'Usage: php ' . $command . ' [options]' . PHP_EOL;
31-
echo PHP_TAB . '[options]:'.PHP_EOL;
31+
echo PHP_TAB . '[options]:' . PHP_EOL;
3232
echo PHP_TAB . PHP_TAB . '--remote <remote>:' . PHP_TAB . 'The git remote reference to build from (ex: `tags/3.8.6`, `4.0-dev`), defaults to the most recent tag for the repository' . PHP_EOL;
3333
echo PHP_TAB . PHP_TAB . '--exclude-zip:' . PHP_TAB . PHP_TAB . 'Exclude the generation of .zip packages' . PHP_EOL;
3434
echo PHP_TAB . PHP_TAB . '--exclude-gzip:' . PHP_TAB . PHP_TAB . 'Exclude the generation of .tar.gz packages' . PHP_EOL;
@@ -228,18 +228,21 @@ function usage($command)
228228
// Loop through and add all files except: tests, installation, build, .git, .travis, travis, phpunit, .md, or images
229229
foreach ($files as $file)
230230
{
231-
if (substr($file, 0, 1) === 'R') {
232-
$fileName = substr($file, strrpos($file, "\t") + 1);
233-
} else {
234-
$fileName = substr($file, 2);
231+
if (substr($file, 0, 1) === 'R')
232+
{
233+
$fileName = substr($file, strrpos($file, "\t") + 1);
234+
}
235+
else
236+
{
237+
$fileName = substr($file, 2);
235238
}
236-
$folderPath = explode('/', $fileName);
237-
$baseFolderName = $folderPath[0];
238239

239-
$doNotPackageFile = in_array(trim($fileName), $doNotPackage);
240-
$doNotPatchFile = in_array(trim($fileName), $doNotPatch);
240+
$folderPath = explode('/', $fileName);
241+
$baseFolderName = $folderPath[0];
242+
$doNotPackageFile = in_array(trim($fileName), $doNotPackage);
243+
$doNotPatchFile = in_array(trim($fileName), $doNotPatch);
241244
$doNotPackageBaseFolder = in_array($baseFolderName, $doNotPackage);
242-
$doNotPatchBaseFolder = in_array($baseFolderName, $doNotPatch);
245+
$doNotPatchBaseFolder = in_array($baseFolderName, $doNotPatch);
243246

244247
if ($doNotPackageFile || $doNotPatchFile || $doNotPackageBaseFolder || $doNotPatchBaseFolder)
245248
{
@@ -393,7 +396,7 @@ function usage($command)
393396
{
394397
echo "Generating checksums for $packageName\n";
395398

396-
foreach (array('md5', 'sha1', 'sha256', 'sha384', 'sha512') as $hash)
399+
foreach (array('sha256', 'sha384', 'sha512') as $hash)
397400
{
398401
if (file_exists('packages/' . $packageName))
399402
{
@@ -439,25 +442,34 @@ function usage($command)
439442
foreach ($checksums as $packageName => $packageHashes)
440443
{
441444
$type = '';
445+
442446
if (strpos($packageName, 'Full_Package') !== false)
443447
{
444448
$type = 'FULL';
445-
} elseif (strpos($packageName, 'Patch_Package') !== false) {
446-
if (strpos($packageName, '.x_to') !== false) {
449+
}
450+
elseif (strpos($packageName, 'Patch_Package') !== false)
451+
{
452+
if (strpos($packageName, '.x_to') !== false)
453+
{
447454
$type = 'MINOR';
448-
} else {
455+
}
456+
else
457+
{
449458
$type = 'POINT';
450459
}
451-
} elseif (strpos($packageName, 'Update_Package') !== false) {
460+
}
461+
elseif (strpos($packageName, 'Update_Package') !== false)
462+
{
452463
$type = 'UPGRADE';
453464
}
454465

455466
$githubContent[$type][] = '[' . substr($packageName, strpos($packageName, 'Package') + 7) . '](' . $githubLink . $packageName . ')';
456467
}
457468

458-
foreach($releaseText as $type => $text)
469+
foreach ($releaseText as $type => $text)
459470
{
460-
if (empty($githubContent[$type])) {
471+
if (empty($githubContent[$type]))
472+
{
461473
continue;
462474
}
463475

build/bump.php

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,49 @@ function usage($command)
3636
const PHP_TAB = "\t";
3737

3838
// File paths.
39-
$versionFile = '/libraries/src/Version.php';
39+
$versionFile = '/libraries/src/Version.php';
4040

41-
$coreXmlFiles = array(
42-
'/administrator/manifests/files/joomla.xml',
43-
);
41+
$coreXmlFiles = array(
42+
'/administrator/manifests/files/joomla.xml',
43+
);
4444

4545
$languageXmlFiles = array(
46-
'/language/en-GB/en-GB.xml',
47-
'/language/en-GB/install.xml',
48-
'/administrator/language/en-GB/en-GB.xml',
49-
'/administrator/language/en-GB/install.xml',
50-
'/installation/language/en-GB/en-GB.xml',
51-
);
46+
'/language/en-GB/en-GB.xml',
47+
'/language/en-GB/install.xml',
48+
'/administrator/language/en-GB/en-GB.xml',
49+
'/administrator/language/en-GB/install.xml',
50+
'/installation/language/en-GB/en-GB.xml',
51+
);
5252

5353
$languagePackXmlFile = '/administrator/manifests/packages/pkg_en-GB.xml';
5454

5555
$antJobFile = '/build.xml';
5656

5757
$readMeFiles = array(
58-
'/README.md',
59-
'/README.txt',
60-
);
58+
'/README.md',
59+
'/README.txt',
60+
);
6161

6262
/*
6363
* Change copyright date exclusions.
6464
* Some systems may try to scan the .git directory, exclude it.
65-
* Also exclude build resources such as the packaging space or the API documentation build.
65+
* Also exclude build resources such as the packaging space or the API documentation build
66+
* as well as external libraries.
6667
*/
6768
$directoryLoopExcludeDirectories = array(
68-
'/.git',
69-
'/build/api/',
70-
'/build/coverage/',
71-
'/build/tmp/',
72-
'/libraries/vendor/',
73-
'/libraries/phputf8/',
74-
'/libraries/php-encryption/',
75-
'/libraries/phpass/',
76-
'/libraries/idna_convert/',
77-
'/libraries/fof/',
78-
);
79-
80-
$directoryLoopExcludeFiles = array(
81-
);
69+
'/.git',
70+
'/build/api/',
71+
'/build/coverage/',
72+
'/build/tmp/',
73+
'/libraries/vendor/',
74+
'/libraries/phputf8/',
75+
'/libraries/php-encryption/',
76+
'/libraries/phpass/',
77+
'/libraries/idna_convert/',
78+
'/libraries/fof/',
79+
);
80+
81+
$directoryLoopExcludeFiles = array();
8282

8383
// Check arguments (exit if incorrect cli arguments).
8484
$opts = getopt("v:c:");
@@ -157,20 +157,20 @@ function usage($command)
157157
$versionSubParts = explode('.', $versionParts[0]);
158158

159159
$version = array(
160-
'main' => $versionSubParts[0] . '.' . $versionSubParts[1],
161-
'major' => $versionSubParts[0],
162-
'minor' => $versionSubParts[1],
163-
'patch' => $versionSubParts[2],
164-
'extra' => (!empty($versionParts[1]) ? $versionParts[1] : '') . (!empty($versionParts[2]) ? (!empty($versionParts[1]) ? '-' : '') . $versionParts[2] : ''),
165-
'release' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2],
166-
'dev_devel' => $versionSubParts[2] . (!empty($versionParts[1]) ? '-' . $versionParts[1] : '') . (!empty($versionParts[2]) ? '-' . $versionParts[2] : ''),
167-
'dev_status' => $dev_status,
168-
'build' => '',
169-
'reldate' => date('j-F-Y'),
170-
'reltime' => date('H:i'),
171-
'reltz' => 'GMT',
172-
'credate' => date('F Y'),
173-
);
160+
'main' => $versionSubParts[0] . '.' . $versionSubParts[1],
161+
'major' => $versionSubParts[0],
162+
'minor' => $versionSubParts[1],
163+
'patch' => $versionSubParts[2],
164+
'extra' => (!empty($versionParts[1]) ? $versionParts[1] : '') . (!empty($versionParts[2]) ? (!empty($versionParts[1]) ? '-' : '') . $versionParts[2] : ''),
165+
'release' => $versionSubParts[0] . '.' . $versionSubParts[1] . '.' . $versionSubParts[2],
166+
'dev_devel' => $versionSubParts[2] . (!empty($versionParts[1]) ? '-' . $versionParts[1] : '') . (!empty($versionParts[2]) ? '-' . $versionParts[2] : ''),
167+
'dev_status' => $dev_status,
168+
'build' => '',
169+
'reldate' => date('j-F-Y'),
170+
'reltime' => date('H:i'),
171+
'reltz' => 'GMT',
172+
'credate' => date('F Y'),
173+
);
174174

175175
// Version Codename.
176176
if (!empty($opts['c']))
@@ -180,21 +180,23 @@ function usage($command)
180180

181181
// Prints version information.
182182
echo PHP_EOL;
183-
echo 'Version data:'. PHP_EOL;
183+
echo 'Version data:' . PHP_EOL;
184184
echo '- Main:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . PHP_EOL;
185185
echo '- Release:' . PHP_TAB . PHP_TAB . $version['release'] . PHP_EOL;
186-
echo '- Full:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . '.' . $version['dev_devel'] . PHP_EOL;
186+
echo '- Full:' . PHP_TAB . PHP_TAB . PHP_TAB . $version['main'] . '.' . $version['dev_devel'] . PHP_EOL;
187187
echo '- Build:' . PHP_TAB . PHP_TAB . $version['build'] . PHP_EOL;
188188
echo '- Dev Level:' . PHP_TAB . PHP_TAB . $version['dev_devel'] . PHP_EOL;
189189
echo '- Dev Status:' . PHP_TAB . PHP_TAB . $version['dev_status'] . PHP_EOL;
190190
echo '- Release date:' . PHP_TAB . PHP_TAB . $version['reldate'] . PHP_EOL;
191191
echo '- Release time:' . PHP_TAB . PHP_TAB . $version['reltime'] . PHP_EOL;
192-
echo '- Release timezone:' . PHP_TAB . $version['reltz'] . PHP_EOL;
192+
echo '- Release timezone:' . PHP_TAB . $version['reltz'] . PHP_EOL;
193193
echo '- Creation date:' . PHP_TAB . $version['credate'] . PHP_EOL;
194+
194195
if (!empty($version['codename']))
195196
{
196197
echo '- Codename:' . PHP_TAB . PHP_TAB . $version['codename'] . PHP_EOL;
197198
}
199+
198200
echo PHP_EOL;
199201

200202
$rootPath = dirname(__DIR__);
@@ -214,10 +216,12 @@ function usage($command)
214216
$fileContents = preg_replace("#RELDATE\s*=\s*'[^\']*'#", "RELDATE = '" . $version['reldate'] . "'", $fileContents);
215217
$fileContents = preg_replace("#RELTIME\s*=\s*'[^\']*'#", "RELTIME = '" . $version['reltime'] . "'", $fileContents);
216218
$fileContents = preg_replace("#RELTZ\s*=\s*'[^\']*'#", "RELTZ = '" . $version['reltz'] . "'", $fileContents);
219+
217220
if (!empty($version['codename']))
218221
{
219222
$fileContents = preg_replace("#CODENAME\s*=\s*'[^\']*'#", "CODENAME = '" . $version['codename'] . "'", $fileContents);
220223
}
224+
221225
file_put_contents($rootPath . $versionFile, $fileContents);
222226
}
223227

@@ -278,8 +282,8 @@ function usage($command)
278282
$changedFilesCopyrightDate = 0;
279283
$changedFilesSinceVersion = 0;
280284
$year = date('Y');
281-
$directory = new \RecursiveDirectoryIterator($rootPath);
282-
$iterator = new \RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
285+
$directory = new RecursiveDirectoryIterator($rootPath);
286+
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
283287

284288
foreach ($iterator as $file)
285289
{
@@ -343,10 +347,12 @@ function usage($command)
343347
{
344348
echo '- Copyright Date changed in ' . $changedFilesCopyrightDate . ' files.' . PHP_EOL;
345349
}
350+
346351
if ($changedFilesSinceVersion > 0)
347352
{
348353
echo '- Since Version changed in ' . $changedFilesSinceVersion . ' files.' . PHP_EOL;
349354
}
355+
350356
echo PHP_EOL;
351357
}
352358

build/stubGenerator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
*
4040
* As Joomla transitions its core classes from residing in the global PHP namespace to using namespaced PHP classes, it will be a common
4141
* occurrence for developers to work in an environment where their code is still using the old class names which may not exist in newer
42-
* Joomla releases except for in PHP's autoloader as a class alias. This script therefore allows developers to generate a mapping
42+
* Joomla releases except for in PHP's autoloader as a class alias. This script therefore allows developers to generate a mapping
4343
* file they can use in their local environment which will create "real" classes for the aliased class names and allow things like
4444
* IDE auto completion to work normally.
4545
*
4646
* When this script is run, a `stubs.php` file will be generated at the root of your Joomla installation holding all of the mapping
47-
* information. Note that this file will raise some IDE errors as it will generate stub classes extending a final class (something
48-
* not allowed in PHP). Therefore it is suggested that inspections on this file are disabled.
47+
* information. Note that this file will raise some IDE errors as it will generate stub classes extending a final class (something
48+
* not allowed in PHP). Therefore it is suggested that inspections on this file are disabled.
4949
*
5050
* @since 3.0
5151
*/
@@ -84,7 +84,6 @@ public function doExecute()
8484
*/
8585
8686
PHP;
87-
8887
}
8988

9089
$file .= "$modifier$type $oldName extends $newName {}\n\n";

0 commit comments

Comments
 (0)