Skip to content

Commit 7511f22

Browse files
committed
Fix PHPCS violations in phpcs-check-sniff-doc-code-examples
1 parent cae0df1 commit 7511f22

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSDevTools
6+
* @copyright 2019 PHPCSDevTools Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSDevTools
9+
*/
10+
11+
/**
12+
* Helper function to require the correct autoload file given a list of possible file locations.
13+
*
14+
* @param array<int, string> $files An array of possible file paths.
15+
*
16+
* @return void
17+
*/
18+
function requireCorrectAutoloadFile(array $files)
19+
{
20+
foreach ($files as $file) {
21+
$file = realpath($file);
22+
if ($file !== false && is_file($file) === true) {
23+
require_once $file;
24+
return;
25+
}
26+
}
27+
}

bin/phpcs-check-sniff-doc-code-examples

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,12 @@
1919
*/
2020

2121
if (PHP_VERSION_ID < 70000) {
22-
$error = 'ERROR: This script requires PHP version 7.0.0 or greater.'.PHP_EOL;
22+
$error = 'ERROR: This script requires PHP version 7.0.0 or greater.' . PHP_EOL;
2323
fwrite(STDERR, $error);
2424
exit(1);
2525
}
2626

27-
/**
28-
* Helper function to require the correct autoload file given a list of possible file locations.
29-
*
30-
* @param array $files An array of possible file paths.
31-
*
32-
* @return void
33-
*/
34-
function requireCorrectAutoloadFile(array $files) {
35-
foreach ($files as $file) {
36-
$file = realpath($file);
37-
if ($file !== false && is_file($file) === true) {
38-
require_once($file);
39-
return;
40-
}
41-
}
42-
}
27+
require_once __DIR__ . '/../Scripts/DocCodeExamples/Functions.php';
4328

4429
$devToolsAutoloadLocations = [
4530
__DIR__ . '/../devtools-autoload.php', // Git clone or direct run from within vendor package directory.
@@ -51,8 +36,8 @@ $devToolsAutoloadLocations = [
5136
$phpcsAutoloadLocations = [
5237
__DIR__ . '/../vendor/squizlabs/php_codesniffer/autoload.php', // Git clone.
5338
__DIR__ . '/../squizlabs/php_codesniffer/autoload.php', // Composer bin dir install.
54-
__DIR__ . '/../../autoload.php', // Installed as a Composer dependency for PHPCS itself. Running from vendor/bin/.
55-
__DIR__ . '/../../../../autoload.php', // Installed as a Composer dependency for PHPCS itself. Running from vendor/phpcsstandards/phpcsdevtools/bin/.
39+
__DIR__ . '/../../autoload.php', // Composer dependency for PHPCS itself. Running from vendor/bin/.
40+
__DIR__ . '/../../../../autoload.php', // Composer dependency running from vendor/phpcsstandards/phpcsdevtools/bin/.
5641
];
5742

5843
// Try to find a usable PHPCSDevTools autoload file.
@@ -72,13 +57,13 @@ try {
7257
$extractor = new PHPCSDevTools\Scripts\DocCodeExamples\CodeBlocksExtractor();
7358

7459
// It is necessary to reset argv to avoid issues with the PHPCS Config,
75-
// as it also checks for command line arguments.
60+
// as it also checks for command line arguments.
7661
$_SERVER['argv'] = [];
77-
$phpcsConfig = new PHP_CodeSniffer\Config();
62+
$phpcsConfig = new PHP_CodeSniffer\Config();
7863

7964
$check = new PHPCSDevTools\Scripts\DocCodeExamples\Check($config, $extractor, $phpcsConfig, $writer);
80-
exit($check->run());
65+
exit($check->run());
8166
} catch (RuntimeException $e) {
82-
echo $e->getMessage() . PHP_EOL;
83-
exit(1);
67+
echo $e->getMessage() . PHP_EOL;
68+
exit(1);
8469
}

0 commit comments

Comments
 (0)